提交 f99117bc 作者: Juan Batiz-Benet

swarm: try all peer's addresses

For simplicity this is sequential. This will be bad latency given
RTTs for all the handshakes, etc. Later on can make async or
at least open based on some priority of the channel.
上级 48879dd5
...@@ -126,8 +126,8 @@ func (s *Swarm) peerMultiConn(p peer.Peer) (*conn.MultiConn, error) { ...@@ -126,8 +126,8 @@ func (s *Swarm) peerMultiConn(p peer.Peer) (*conn.MultiConn, error) {
return mc, nil return mc, nil
} }
// connSetup adds the passed in connection to its peerMap and starts // connSetup takes a new connection, performs the IPFS handshake (handshake3)
// the fanInSingle routine for that connection // and then adds it to the appropriate MultiConn.
func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) { func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
if c == nil { if c == nil {
return nil, errors.New("Tried to start nil connection.") return nil, errors.New("Tried to start nil connection.")
......
...@@ -132,7 +132,15 @@ func (s *Swarm) Dial(peer peer.Peer) (conn.Conn, error) { ...@@ -132,7 +132,15 @@ func (s *Swarm) Dial(peer peer.Peer) (conn.Conn, error) {
Peerstore: s.peers, Peerstore: s.peers,
} }
c, err = d.Dial(s.Context(), "tcp", peer) // try to connect to one of the peer's known addresses.
// for simplicity, we do this sequentially.
// A future commit will do this asynchronously.
for _, addr := range peer.Addresses() {
c, err = d.DialAddr(s.Context(), addr, peer)
if err == nil {
break
}
}
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论