p2p/net/swarm: const dial attempts
Juan Batiz-Benet committed
Jan 13, 2015 at 01:18 UTC
25c6ab8a26dd588dac065599664a1b234a907412
1 file changed
+5
-3
p2p/net/swarm/swarm_dial.go
+5
-3
@@ -14,6 +14,9 @@ import (
14
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
15
)
16
17
+// dialAttempts governs how many times a goroutine will try to dial a given peer.
18
+const dialAttempts = 3
19
+
20
// dialsync is a small object that helps manage ongoing dials.
21
// this way, if we receive many simultaneous dial requests, one
22
// can do its thing, while the rest wait.
@@ -101,11 +104,10 @@ func (s *Swarm) Dial(ctx context.Context, p peer.ID) (*Conn, error) {
104
// to check s.ConnectionsToPeer(p) _first_, and _between_ attempts because we
105
// may have received an incoming connection! if so, we no longer must dial.
106
//
104
- // dial attempts. we may be doing the dialing. if not, we wait.
105
- attempts := 3
107
+ // During the dial attempts, we may be doing the dialing. if not, we wait.
108
var err error
109
var conn *Conn
108
- for i := 0; i < attempts; i++ {
110
+ for i := 0; i < dialAttempts; i++ {
111
// check if we already have an open connection first
112
cs := s.ConnectionsToPeer(p)
113
for _, conn = range cs {