Merge pull request #2576 from AudriusButkevicius/reconn

More debug to reconnect loop
This commit is contained in:
Jakob Borg 2015-12-15 10:18:47 +01:00
commit 81e71d7275
1 changed files with 9 additions and 0 deletions

View File

@ -260,12 +260,15 @@ next:
func (s *connectionSvc) connect() { func (s *connectionSvc) connect() {
delay := time.Second delay := time.Second
for { for {
l.Debugln("Reconnect loop")
nextDevice: nextDevice:
for deviceID, deviceCfg := range s.cfg.Devices() { for deviceID, deviceCfg := range s.cfg.Devices() {
if deviceID == s.myID { if deviceID == s.myID {
continue continue
} }
l.Debugln("Reconnect loop for", deviceID)
if s.model.IsPaused(deviceID) { if s.model.IsPaused(deviceID) {
continue continue
} }
@ -277,6 +280,7 @@ func (s *connectionSvc) connect() {
relaysEnabled := s.relaysEnabled relaysEnabled := s.relaysEnabled
s.mut.RUnlock() s.mut.RUnlock()
if connected && ok && ct.IsDirect() { if connected && ok && ct.IsDirect() {
l.Debugln("Already connected to", deviceID, "via", ct.String())
continue continue
} }
@ -284,6 +288,7 @@ func (s *connectionSvc) connect() {
for _, addr := range addrs { for _, addr := range addrs {
if conn := s.connectDirect(deviceID, addr); conn != nil { if conn := s.connectDirect(deviceID, addr); conn != nil {
l.Debugln("Connectin to", deviceID, "via", addr, "succeeded")
if connected { if connected {
s.model.Close(deviceID, fmt.Errorf("switching connections")) s.model.Close(deviceID, fmt.Errorf("switching connections"))
} }
@ -292,6 +297,7 @@ func (s *connectionSvc) connect() {
} }
continue nextDevice continue nextDevice
} }
l.Debugln("Connectin to", deviceID, "via", addr, "failed")
} }
// Only connect via relays if not already connected // Only connect via relays if not already connected
@ -300,6 +306,7 @@ func (s *connectionSvc) connect() {
// wait up to RelayReconnectIntervalM to connect again. // wait up to RelayReconnectIntervalM to connect again.
// Also, do not try relays if we are explicitly told not to. // Also, do not try relays if we are explicitly told not to.
if connected || len(relays) == 0 || !relaysEnabled { if connected || len(relays) == 0 || !relaysEnabled {
l.Debugln("Not connecting via relay", connected, len(relays) == 0, !relaysEnabled)
continue nextDevice continue nextDevice
} }
@ -315,11 +322,13 @@ func (s *connectionSvc) connect() {
for _, addr := range relays { for _, addr := range relays {
if conn := s.connectViaRelay(deviceID, addr); conn != nil { if conn := s.connectViaRelay(deviceID, addr); conn != nil {
l.Debugln("Connectin to", deviceID, "via", addr, "succeeded")
s.conns <- model.IntermediateConnection{ s.conns <- model.IntermediateConnection{
conn, model.ConnectionTypeRelayDial, conn, model.ConnectionTypeRelayDial,
} }
continue nextDevice continue nextDevice
} }
l.Debugln("Connectin to", deviceID, "via", addr, "failed")
} }
} }