mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 17:36:38 +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:
@ -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.")
|
||||
|
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user