@cryptotaxi247 / kubo / commits / f99117bcd

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.

Juan Batiz-Benet committed Nov 20, 2014 at 09:13 UTC f99117bcd2ad383956833caf00a19d54e47172e7
2 files changed +11 -3
net/swarm/conn.go
+2 -2
@@ -126,8 +126,8 @@ func (s *Swarm) peerMultiConn(p peer.Peer) (*conn.MultiConn, error) {
126 return mc, nil
127 }
128
129 -// connSetup adds the passed in connection to its peerMap and starts
130 -// the fanInSingle routine for that connection
129 +// connSetup takes a new connection, performs the IPFS handshake (handshake3)
130 +// and then adds it to the appropriate MultiConn.
131 func (s *Swarm) connSetup(c conn.Conn) (conn.Conn, error) {
132 if c == nil {
133 return nil, errors.New("Tried to start nil connection.")
net/swarm/swarm.go
+9 -1
@@ -132,7 +132,15 @@ func (s *Swarm) Dial(peer peer.Peer) (conn.Conn, error) {
132 Peerstore: s.peers,
133 }
134
135 - c, err = d.Dial(s.Context(), "tcp", peer)
135 + // try to connect to one of the peer's known addresses.
136 + // for simplicity, we do this sequentially.
137 + // A future commit will do this asynchronously.
138 + for _, addr := range peer.Addresses() {
139 + c, err = d.DialAddr(s.Context(), addr, peer)
140 + if err == nil {
141 + break
142 + }
143 + }
144 if err != nil {
145 return nil, err
146 }