From 90fa92905164bd7afd27cef35c1fa214c206c083 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sat, 14 Feb 2015 19:10:15 +0000 Subject: [PATCH] make NewStream run FindPeer if no addresses found --- host/routed/routed.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/host/routed/routed.go b/host/routed/routed.go index 68594f83..7ce5b440 100644 --- a/host/routed/routed.go +++ b/host/routed/routed.go @@ -100,6 +100,14 @@ 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 {