make NewStream run FindPeer if no addresses found
Jeromy committed
Feb 14, 2015 at 19:10 UTC
584cdd3915219dff564b0bc23e68cad34949fe9f
1 file changed
+8
p2p/host/routed/routed.go
+8
@@ -100,6 +100,14 @@ 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
+ }
111
return rh.host.NewStream(pid, p)
112
}
113
func (rh *RoutedHost) Close() error {