fix dial backoff
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Nov 4, 2015 at 21:49 UTC
193d73080e4e9ec21d1f3795460e05ba330835ce
1 file changed
+8
-2
p2p/net/swarm/swarm_dial.go
+8
-2
@@ -227,14 +227,20 @@ func (s *Swarm) gatedDialAttempt(ctx context.Context, p peer.ID) (*Conn, error)
227
228
// check if there's an ongoing dial to this peer
229
if ok, wait := s.dsync.Lock(p); ok {
230
+ defer s.dsync.Unlock(p)
231
+
232
+ // if this peer has been backed off, lets get out of here
233
+ if s.backf.Backoff(p) {
234
+ log.Event(ctx, "swarmDialBackoff", logdial)
235
+ return nil, ErrDialBackoff
236
+ }
237
+
238
// ok, we have been charged to dial! let's do it.
239
// if it succeeds, dial will add the conn to the swarm itself.
232
-
240
defer log.EventBegin(ctx, "swarmDialAttemptStart", logdial).Done()
241
ctxT, cancel := context.WithTimeout(ctx, s.dialT)
242
conn, err := s.dial(ctxT, p)
243
cancel()
237
- s.dsync.Unlock(p)
244
log.Debugf("dial end %s", conn)
245
if err != nil {
246
log.Event(ctx, "swarmDialBackoffAdd", logdial)