1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 09:34:03 +08:00

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.
This commit is contained in:
Juan Batiz-Benet
2014-11-20 09:13:31 -08:00
parent 48879dd56c
commit f99117bcd2
2 changed files with 11 additions and 3 deletions

View File

@ -126,8 +126,8 @@ func (s *Swarm) peerMultiConn(p peer.Peer) (*conn.MultiConn, error) {
return mc, nil
}
// connSetup adds the passed in connection to its peerMap and starts
// the fanInSingle routine for that connection
// connSetup takes a new connection, performs the IPFS handshake (handshake3)
// and then adds it to the appropriate MultiConn.
func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
if c == nil {
return nil, errors.New("Tried to start nil connection.")

View File

@ -132,7 +132,15 @@ func (s *Swarm) Dial(peer peer.Peer) (conn.Conn, error) {
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 {
return nil, err
}