diff options
author | Ben Sidhom <bsidhom@gmail.com> | 2014-07-04 13:47:54 -0700 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-07-05 23:10:11 +0200 |
commit | 37d83a4e2ecd53d744dbf294f1d4080384655da3 (patch) | |
tree | 77946f4fb1e8cdce18ae30e0b5e004e08e7c561d | |
parent | a720f90a70f3ca21ab8eacb98788aa04e7aca704 (diff) |
Continue discovery on connect errors (fixes #324)
Continues trying to connect to the discovery server at regular intervals despite
failure. Whether or not to retry and retry interval should be specified in
configuration (not currently in this fix).
-rw-r--r-- | discover/discover.go | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/discover/discover.go b/discover/discover.go index 4eb82d388e..ba0289fe2d 100644 --- a/discover/discover.go +++ b/discover/discover.go @@ -168,16 +168,21 @@ func (d *Discoverer) sendLocalAnnouncements() { } func (d *Discoverer) sendExternalAnnouncements() { + // this should go in the Discoverer struct + errorRetryIntv := 60 * time.Second + remote, err := net.ResolveUDPAddr("udp", d.extServer) - if err != nil { - l.Warnf("Global discovery: %v; no external announcements", err) - return + for err != nil { + l.Warnf("Global discovery: %v; trying again in %v", err, errorRetryIntv) + time.Sleep(errorRetryIntv) + remote, err = net.ResolveUDPAddr("udp", d.extServer) } conn, err := net.ListenUDP("udp", nil) - if err != nil { - l.Warnf("Global discovery: %v; no external announcements", err) - return + for err != nil { + l.Warnf("Global discovery: %v; trying again in %v", err, errorRetryIntv) + time.Sleep(errorRetryIntv) + conn, err = net.ListenUDP("udp", nil) } var buf []byte @@ -198,7 +203,7 @@ func (d *Discoverer) sendExternalAnnouncements() { l.Debugf("discover: send announcement -> %v\n%s", remote, hex.Dump(buf)) } - _, err = conn.WriteTo(buf, remote) + _, err := conn.WriteTo(buf, remote) if err != nil { if debug { l.Debugln("discover: warning:", err) @@ -222,7 +227,7 @@ func (d *Discoverer) sendExternalAnnouncements() { if ok { time.Sleep(d.globalBcastIntv) } else { - time.Sleep(60 * time.Second) + time.Sleep(errorRetryIntv) } } } |