From f99117bcd2ad383956833caf00a19d54e47172e7 Mon Sep 17 00:00:00 2001 From: Juan Batiz-Benet Date: Thu, 20 Nov 2014 09:13:31 -0800 Subject: [PATCH] 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. --- net/swarm/conn.go | 4 ++-- net/swarm/swarm.go | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/net/swarm/conn.go b/net/swarm/conn.go index fb34eb619..74c3b03d4 100644 --- a/net/swarm/conn.go +++ b/net/swarm/conn.go @@ -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.") diff --git a/net/swarm/swarm.go b/net/swarm/swarm.go index d0b5c65a6..9328ed7cd 100644 --- a/net/swarm/swarm.go +++ b/net/swarm/swarm.go @@ -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 }