mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-02 12:20:03 +08:00
fix(net) use Do to respect the caller's context
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
|||||||
mux "github.com/jbenet/go-ipfs/net/mux"
|
mux "github.com/jbenet/go-ipfs/net/mux"
|
||||||
swarm "github.com/jbenet/go-ipfs/net/swarm"
|
swarm "github.com/jbenet/go-ipfs/net/swarm"
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
|
util "github.com/jbenet/go-ipfs/util"
|
||||||
ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
|
ctxc "github.com/jbenet/go-ipfs/util/ctxcloser"
|
||||||
|
|
||||||
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
|
||||||
@ -56,10 +57,14 @@ func NewIpfsNetwork(ctx context.Context, listen []ma.Multiaddr, local peer.Peer,
|
|||||||
// Listen handles incoming connections on given Multiaddr.
|
// Listen handles incoming connections on given Multiaddr.
|
||||||
// func (n *IpfsNetwork) Listen(*ma.Muliaddr) error {}
|
// func (n *IpfsNetwork) Listen(*ma.Muliaddr) error {}
|
||||||
|
|
||||||
// DialPeer attempts to establish a connection to a given peer
|
// DialPeer attempts to establish a connection to a given peer.
|
||||||
|
// Respects the context.
|
||||||
func (n *IpfsNetwork) DialPeer(ctx context.Context, p peer.Peer) error {
|
func (n *IpfsNetwork) DialPeer(ctx context.Context, p peer.Peer) error {
|
||||||
|
err := util.Do(ctx, func() error {
|
||||||
_, err := n.swarm.Dial(p)
|
_, err := n.swarm.Dial(p)
|
||||||
return err
|
return err
|
||||||
|
})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClosePeer connection to peer
|
// ClosePeer connection to peer
|
||||||
|
Reference in New Issue
Block a user