// ConnsToPeer returns the connections in this Netowrk for given peer. func (n *Network) ConnsToPeer(p peer.ID) []inet.Conn { conns1 := n.Swarm().ConnectionsToPeer(p) out := make([]inet.Conn, len(conns1)) for i, c := range conns1 { out[i] = inet.Conn(c) } return out }
// DialPeer attempts to establish a connection to a given peer. // Respects the context. func (n *Network) DialPeer(ctx context.Context, p peer.ID) (inet.Conn, error) { log.Debugf("[%s] network dialing peer [%s]", n.local, p) sc, err := n.Swarm().Dial(ctx, p) if err != nil { return nil, err } log.Debugf("network for %s finished dialing %s", n.local, p) return inet.Conn(sc), nil }
// SetConnHandler sets the conn handler on the Network. // This operation is threadsafe. func (n *Network) SetConnHandler(h inet.ConnHandler) { n.Swarm().SetConnHandler(func(c *Conn) { h(inet.Conn(c)) }) }
func (n *ps2netNotifee) Disconnected(c *ps.Conn) { n.not.Disconnected(n.net, inet.Conn((*Conn)(c))) }