Commit 0fc0ade2 authored by vyzo's avatar vyzo

kill dial jump delays

parent 7ccf58e5
...@@ -57,12 +57,6 @@ var ( ...@@ -57,12 +57,6 @@ var (
ErrGaterDisallowedConnection = errors.New("gater disallows connection to peer") ErrGaterDisallowedConnection = errors.New("gater disallows connection to peer")
) )
var (
delayDialPrivateAddr = 1 * time.Millisecond
delayDialPublicAddr = 5 * time.Millisecond
delayDialRelayAddr = 10 * time.Millisecond
)
// DialAttempts governs how many times a goroutine will try to dial a given peer. // DialAttempts governs how many times a goroutine will try to dial a given peer.
// Note: this is down to one, as we have _too many dials_ atm. To add back in, // Note: this is down to one, as we have _too many dials_ atm. To add back in,
// add loop back in Dial(.) // add loop back in Dial(.)
...@@ -360,17 +354,10 @@ func (s *Swarm) dialWorkerLoop(ctx context.Context, p peer.ID, reqch <-chan Dial ...@@ -360,17 +354,10 @@ func (s *Swarm) dialWorkerLoop(ctx context.Context, p peer.ID, reqch <-chan Dial
} }
} }
var triggerDial <-chan time.Time var triggerDial <-chan struct{}
var triggerTimer *time.Timer triggerNow := make(chan struct{})
triggerNow := make(chan time.Time)
close(triggerNow) close(triggerNow)
defer func() {
if triggerTimer != nil {
triggerTimer.Stop()
}
}()
var nextDial []ma.Multiaddr var nextDial []ma.Multiaddr
active := 0 active := 0
done := false done := false
...@@ -501,26 +488,12 @@ loop: ...@@ -501,26 +488,12 @@ loop:
active++ active++
} }
lastDial := nextDial[last]
nextDial = nextDial[next:] nextDial = nextDial[next:]
if !dialed || len(nextDial) == 0 { if !dialed || len(nextDial) == 0 {
// we didn't dial anything because of backoff or we don't have any more addresses // we didn't dial anything because of backoff or we don't have any more addresses
triggerDial = nil triggerDial = nil
continue loop
} }
// select an appropriate delay for the next dial batch
delay := s.delayForNextDial(lastDial)
if triggerTimer == nil {
triggerTimer = time.NewTimer(delay)
} else {
if !triggerTimer.Stop() && triggerDial != triggerTimer.C {
<-triggerTimer.C
}
triggerTimer.Reset(delay)
}
triggerDial = triggerTimer.C
case res := <-resch: case res := <-resch:
active-- active--
...@@ -636,18 +609,6 @@ func (s *Swarm) sameAddrBatch(a, b ma.Multiaddr) bool { ...@@ -636,18 +609,6 @@ func (s *Swarm) sameAddrBatch(a, b ma.Multiaddr) bool {
return manet.IsPrivateAddr(b) return manet.IsPrivateAddr(b)
} }
func (s *Swarm) delayForNextDial(addr ma.Multiaddr) time.Duration {
if _, err := addr.ValueForProtocol(ma.P_CIRCUIT); err == nil {
return delayDialRelayAddr
}
if manet.IsPrivateAddr(addr) {
return delayDialPrivateAddr
}
return delayDialPublicAddr
}
func (s *Swarm) canDial(addr ma.Multiaddr) bool { func (s *Swarm) canDial(addr ma.Multiaddr) bool {
t := s.TransportForDialing(addr) t := s.TransportForDialing(addr)
return t != nil && t.CanDial(addr) return t != nil && t.CanDial(addr)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment