mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-07 09:17:49 +08:00
keep routing logic out of NewStream on routedHost
This commit is contained in:
parent
584cdd3915
commit
03c0b2d3e0
@ -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)
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user