keep routing logic out of NewStream on routedHost

This commit is contained in:
Jeromy 2015-02-15 01:28:47 +00:00
parent 584cdd3915
commit 03c0b2d3e0
2 changed files with 7 additions and 8 deletions

View File

@ -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)
}

View File

@ -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 {