keep routing logic out of NewStream on routedHost
Jeromy committed
Feb 15, 2015 at 01:28 UTC
03c0b2d3e0cef3afcc1002a7be958b53d528e576
2 files changed
+7
-8
core/corenet/net.go
+7
@@ -1,6 +1,8 @@
1
package corenet
2
3
import (
4
+ "time"
5
+
6
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
7
core "github.com/jbenet/go-ipfs/core"
8
net "github.com/jbenet/go-ipfs/p2p/net"
@@ -52,5 +54,10 @@ func Listen(nd *core.IpfsNode, protocol string) (*ipfsListener, error) {
54
}
55
56
func Dial(nd *core.IpfsNode, p peer.ID, protocol string) (net.Stream, error) {
57
+ ctx, _ := context.WithTimeout(nd.Context(), time.Second*30)
58
+ err := nd.PeerHost.Connect(ctx, peer.PeerInfo{ID: p})
59
+ if err != nil {
60
+ return nil, err
61
+ }
62
return nd.PeerHost.NewStream(pro.ID(protocol), p)
63
}
p2p/host/routed/routed.go
-8
@@ -100,14 +100,6 @@ func (rh *RoutedHost) SetStreamHandler(pid protocol.ID, handler inet.StreamHandl
100
rh.host.SetStreamHandler(pid, handler)
101
}
102
func (rh *RoutedHost) NewStream(pid protocol.ID, p peer.ID) (inet.Stream, error) {
103
- if len(rh.Peerstore().Addrs(p)) < 1 {
104
- ctx, _ := context.WithTimeout(context.TODO(), time.Second*30)
105
- pi, err := rh.route.FindPeer(ctx, p)
106
- if err != nil {
107
- return nil, err
108
- }
109
- rh.Peerstore().AddAddrs(p, pi.Addrs, peer.TempAddrTTL)
110
- }
103
return rh.host.NewStream(pid, p)
104
}
105
func (rh *RoutedHost) Close() error {