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 }