diff --git a/core/corenet/net.go b/core/corenet/net.go index 13d72fe53..b506188df 100644 --- a/core/corenet/net.go +++ b/core/corenet/net.go @@ -1,6 +1,8 @@ package corenet import ( + "time" + context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" core "github.com/jbenet/go-ipfs/core" net "github.com/jbenet/go-ipfs/p2p/net" @@ -52,5 +54,10 @@ func Listen(nd *core.IpfsNode, protocol string) (*ipfsListener, error) { } func Dial(nd *core.IpfsNode, p peer.ID, protocol string) (net.Stream, error) { + ctx, _ := context.WithTimeout(nd.Context(), time.Second*30) + err := nd.PeerHost.Connect(ctx, peer.PeerInfo{ID: p}) + if err != nil { + return nil, err + } return nd.PeerHost.NewStream(pro.ID(protocol), p) } diff --git a/p2p/host/routed/routed.go b/p2p/host/routed/routed.go index 7ce5b4403..68594f836 100644 --- a/p2p/host/routed/routed.go +++ b/p2p/host/routed/routed.go @@ -100,14 +100,6 @@ func (rh *RoutedHost) SetStreamHandler(pid protocol.ID, handler inet.StreamHandl rh.host.SetStreamHandler(pid, handler) } func (rh *RoutedHost) NewStream(pid protocol.ID, p peer.ID) (inet.Stream, error) { - if len(rh.Peerstore().Addrs(p)) < 1 { - ctx, _ := context.WithTimeout(context.TODO(), time.Second*30) - pi, err := rh.route.FindPeer(ctx, p) - if err != nil { - return nil, err - } - rh.Peerstore().AddAddrs(p, pi.Addrs, peer.TempAddrTTL) - } return rh.host.NewStream(pid, p) } func (rh *RoutedHost) Close() error {