2019-09-23 21:43:53 +00:00
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-10-07 07:24:51 +00:00
|
|
|
"github.com/libp2p/go-libp2p/core/host"
|
|
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
2019-09-23 21:43:53 +00:00
|
|
|
"go.opencensus.io/trace"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MakePeer from multiaddress string.
|
2020-07-13 02:28:40 +00:00
|
|
|
func MakePeer(addr string) (*peer.AddrInfo, error) {
|
2019-12-03 18:18:57 +00:00
|
|
|
maddr, err := multiAddrFromString(addr)
|
2019-09-23 21:43:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-13 02:28:40 +00:00
|
|
|
return peer.AddrInfoFromP2pAddr(maddr)
|
2019-09-23 21:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func dialRelayNode(ctx context.Context, h host.Host, relayAddr string) error {
|
|
|
|
ctx, span := trace.StartSpan(ctx, "p2p_dialRelayNode")
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
p, err := MakePeer(relayAddr)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-07-11 15:18:25 +00:00
|
|
|
ctx, cancel := context.WithTimeout(ctx, maxDialTimeout)
|
|
|
|
defer cancel()
|
2019-09-23 21:43:53 +00:00
|
|
|
return h.Connect(ctx, *p)
|
|
|
|
}
|