2019-09-23 21:43:53 +00:00
|
|
|
package p2p
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-10-04 03:22:17 +00:00
|
|
|
"github.com/libp2p/go-libp2p-core/host"
|
2019-09-23 21:43:53 +00:00
|
|
|
peerstore "github.com/libp2p/go-libp2p-peerstore"
|
|
|
|
"github.com/multiformats/go-multiaddr"
|
|
|
|
"go.opencensus.io/trace"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MakePeer from multiaddress string.
|
|
|
|
func MakePeer(addr string) (*peerstore.PeerInfo, error) {
|
|
|
|
maddr, err := multiaddr.NewMultiaddr(addr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return peerstore.InfoFromP2pAddr(maddr)
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
return h.Connect(ctx, *p)
|
|
|
|
}
|