Skip to content

Commit

Permalink
lib/connections: Fix relay connections when two devices use the same …
Browse files Browse the repository at this point in the history
…relay (fixes syncthing#4778)
  • Loading branch information
AudriusButkevicius committed Feb 25, 2018
1 parent 36251b8 commit 80b2218
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/connections/service.go
Expand Up @@ -346,14 +346,16 @@ func (s *Service) connect() {
dialTargets := make([]dialTarget, 0)

for _, addr := range addrs {
nextDialAt, ok := nextDial[addr]
// Use a special key that is more than just the address, as you might have two devices connected to the same relay
nextDialKey := deviceID.String() + "/" + addr
nextDialAt, ok := nextDial[nextDialKey]
if ok && initialRampup >= sleep && nextDialAt.After(now) {
l.Debugf("Not dialing %v as sleep is %v, next dial is at %s and current time is %s", addr, sleep, nextDialAt, now)
l.Debugf("Not dialing %s via %v as sleep is %v, next dial is at %s and current time is %s", deviceID, addr, sleep, nextDialAt, now)
continue
}
// If we fail at any step before actually getting the dialer
// retry in a minute
nextDial[addr] = now.Add(time.Minute)
nextDial[nextDialKey] = now.Add(time.Minute)

uri, err := url.Parse(addr)
if err != nil {
Expand Down Expand Up @@ -391,7 +393,7 @@ func (s *Service) connect() {
}

dialer := dialerFactory.New(s.cfg, s.tlsCfg)
nextDial[addr] = now.Add(dialer.RedialFrequency())
nextDial[nextDialKey] = now.Add(dialer.RedialFrequency())

// For LAN addresses, increase the priority so that we
// try these first.
Expand Down

0 comments on commit 80b2218

Please sign in to comment.