From 716a8329c2cabb2885f5619f50dce947cc00a94c Mon Sep 17 00:00:00 2001 From: Audrius Butkevicius Date: Wed, 20 Aug 2014 00:00:21 +0100 Subject: [PATCH] Do not warn about failed IPv6 discovery --- cmd/syncthing/main.go | 12 ++++-------- discover/discover.go | 34 +++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index 2d8cf60d5..85b309782 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -989,19 +989,15 @@ func setTCPOptions(conn *net.TCPConn) { } func discovery(extPort int) *discover.Discoverer { - disc, err := discover.NewDiscoverer(myID, cfg.Options.ListenAddress, cfg.Options.LocalAnnPort, cfg.Options.LocalAnnMCAddr) - if err != nil { - l.Warnf("No discovery possible (%v)", err) - return nil - } + disc := discover.NewDiscoverer(myID, cfg.Options.ListenAddress) if cfg.Options.LocalAnnEnabled { - l.Infoln("Sending local discovery announcements") - disc.StartLocal() + l.Infoln("Starting local discovery announcements") + disc.StartLocal(cfg.Options.LocalAnnPort, cfg.Options.LocalAnnMCAddr) } if cfg.Options.GlobalAnnEnabled { - l.Infoln("Sending global discovery announcements") + l.Infoln("Starting global discovery announcements") disc.StartGlobal(cfg.Options.GlobalAnnServer, uint16(extPort)) } diff --git a/discover/discover.go b/discover/discover.go index 901dc6e35..cfc20fdc0 100644 --- a/discover/discover.go +++ b/discover/discover.go @@ -55,8 +55,8 @@ var ( // When we hit this many errors in succession, we stop. const maxErrors = 30 -func NewDiscoverer(id protocol.NodeID, addresses []string, localPort int, localMCAddr string) (*Discoverer, error) { - disc := &Discoverer{ +func NewDiscoverer(id protocol.NodeID, addresses []string) *Discoverer { + return &Discoverer{ myID: id, listenAddrs: addresses, localBcastIntv: 30 * time.Second, @@ -65,32 +65,36 @@ func NewDiscoverer(id protocol.NodeID, addresses []string, localPort int, localM cacheLifetime: 5 * time.Minute, registry: make(map[protocol.NodeID][]cacheEntry), } +} +func (d *Discoverer) StartLocal(localPort int, localMCAddr string) { if localPort > 0 { bb, err := beacon.NewBroadcast(localPort) if err != nil { - return nil, err + l.Infof("No IPv4 discovery possible (%v)", err) + } else { + d.broadcastBeacon = bb + go d.recvAnnouncements(bb) } - disc.broadcastBeacon = bb - go disc.recvAnnouncements(bb) } if len(localMCAddr) > 0 { mb, err := beacon.NewMulticast(localMCAddr) if err != nil { - return nil, err + l.Infof("No IPv6 discovery possible (%v)", err) + } else { + d.multicastBeacon = mb + go d.recvAnnouncements(mb) } - disc.multicastBeacon = mb - go disc.recvAnnouncements(mb) } - return disc, nil -} - -func (d *Discoverer) StartLocal() { - d.localBcastTick = time.Tick(d.localBcastIntv) - d.forcedBcastTick = make(chan time.Time) - go d.sendLocalAnnouncements() + if d.broadcastBeacon == nil && d.multicastBeacon == nil { + l.Warnln("No local discovery method available") + } else { + d.localBcastTick = time.Tick(d.localBcastIntv) + d.forcedBcastTick = make(chan time.Time) + go d.sendLocalAnnouncements() + } } func (d *Discoverer) StartGlobal(server string, extPort uint16) {