Merge pull request #548 from AudriusButkevicius/warning

Do not warn about failed IPv6 discovery, warn about no discovery
This commit is contained in:
Jakob Borg 2014-08-21 18:54:33 +02:00
commit 63203aa14c
2 changed files with 23 additions and 23 deletions

View File

@ -989,19 +989,15 @@ func setTCPOptions(conn *net.TCPConn) {
} }
func discovery(extPort int) *discover.Discoverer { func discovery(extPort int) *discover.Discoverer {
disc, err := discover.NewDiscoverer(myID, cfg.Options.ListenAddress, cfg.Options.LocalAnnPort, cfg.Options.LocalAnnMCAddr) disc := discover.NewDiscoverer(myID, cfg.Options.ListenAddress)
if err != nil {
l.Warnf("No discovery possible (%v)", err)
return nil
}
if cfg.Options.LocalAnnEnabled { if cfg.Options.LocalAnnEnabled {
l.Infoln("Sending local discovery announcements") l.Infoln("Starting local discovery announcements")
disc.StartLocal() disc.StartLocal(cfg.Options.LocalAnnPort, cfg.Options.LocalAnnMCAddr)
} }
if cfg.Options.GlobalAnnEnabled { if cfg.Options.GlobalAnnEnabled {
l.Infoln("Sending global discovery announcements") l.Infoln("Starting global discovery announcements")
disc.StartGlobal(cfg.Options.GlobalAnnServer, uint16(extPort)) disc.StartGlobal(cfg.Options.GlobalAnnServer, uint16(extPort))
} }

View File

@ -55,8 +55,8 @@ var (
// When we hit this many errors in succession, we stop. // When we hit this many errors in succession, we stop.
const maxErrors = 30 const maxErrors = 30
func NewDiscoverer(id protocol.NodeID, addresses []string, localPort int, localMCAddr string) (*Discoverer, error) { func NewDiscoverer(id protocol.NodeID, addresses []string) *Discoverer {
disc := &Discoverer{ return &Discoverer{
myID: id, myID: id,
listenAddrs: addresses, listenAddrs: addresses,
localBcastIntv: 30 * time.Second, localBcastIntv: 30 * time.Second,
@ -65,33 +65,37 @@ func NewDiscoverer(id protocol.NodeID, addresses []string, localPort int, localM
cacheLifetime: 5 * time.Minute, cacheLifetime: 5 * time.Minute,
registry: make(map[protocol.NodeID][]cacheEntry), registry: make(map[protocol.NodeID][]cacheEntry),
} }
}
func (d *Discoverer) StartLocal(localPort int, localMCAddr string) {
if localPort > 0 { if localPort > 0 {
bb, err := beacon.NewBroadcast(localPort) bb, err := beacon.NewBroadcast(localPort)
if err != nil { 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 { if len(localMCAddr) > 0 {
mb, err := beacon.NewMulticast(localMCAddr) mb, err := beacon.NewMulticast(localMCAddr)
if err != nil { 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 if d.broadcastBeacon == nil && d.multicastBeacon == nil {
} l.Warnln("No local discovery method available")
} else {
func (d *Discoverer) StartLocal() {
d.localBcastTick = time.Tick(d.localBcastIntv) d.localBcastTick = time.Tick(d.localBcastIntv)
d.forcedBcastTick = make(chan time.Time) d.forcedBcastTick = make(chan time.Time)
go d.sendLocalAnnouncements() go d.sendLocalAnnouncements()
} }
}
func (d *Discoverer) StartGlobal(server string, extPort uint16) { func (d *Discoverer) StartGlobal(server string, extPort uint16) {
// Wait for any previous announcer to stop before starting a new one. // Wait for any previous announcer to stop before starting a new one.