github.com/amazechain/amc@v0.1.3/internal/p2p/dial_relay_node.go (about)

     1  package p2p
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/libp2p/go-libp2p/core/host"
     7  	"github.com/libp2p/go-libp2p/core/peer"
     8  	"go.opencensus.io/trace"
     9  )
    10  
    11  // MakePeer from multiaddress string.
    12  func MakePeer(addr string) (*peer.AddrInfo, error) {
    13  	maddr, err := multiAddrFromString(addr)
    14  	if err != nil {
    15  		return nil, err
    16  	}
    17  	return peer.AddrInfoFromP2pAddr(maddr)
    18  }
    19  
    20  func dialRelayNode(ctx context.Context, h host.Host, relayAddr string) error {
    21  	ctx, span := trace.StartSpan(ctx, "p2p_dialRelayNode")
    22  	defer span.End()
    23  
    24  	p, err := MakePeer(relayAddr)
    25  	if err != nil {
    26  		return err
    27  	}
    28  	ctx, cancel := context.WithTimeout(ctx, maxDialTimeout)
    29  	defer cancel()
    30  	return h.Connect(ctx, *p)
    31  }