mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-25 07:58:28 +00:00
Decouple local from global announcing (fixes #132)
This commit is contained in:
parent
f72ee7a69e
commit
31bfd8c039
@ -468,22 +468,20 @@ next:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func discovery() *discover.Discoverer {
|
func discovery() *discover.Discoverer {
|
||||||
if !cfg.Options.LocalAnnEnabled {
|
disc, err := discover.NewDiscoverer(myID, cfg.Options.ListenAddress)
|
||||||
|
if err != nil {
|
||||||
|
warnf("No discovery possible (%v)", err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
infoln("Sending local discovery announcements")
|
if cfg.Options.LocalAnnEnabled {
|
||||||
|
infoln("Sending local discovery announcements")
|
||||||
if !cfg.Options.GlobalAnnEnabled {
|
disc.StartLocal()
|
||||||
cfg.Options.GlobalAnnServer = ""
|
|
||||||
} else {
|
|
||||||
infoln("Sending external discovery announcements")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disc, err := discover.NewDiscoverer(myID, cfg.Options.ListenAddress, cfg.Options.GlobalAnnServer)
|
if cfg.Options.GlobalAnnEnabled {
|
||||||
|
infoln("Sending external discovery announcements")
|
||||||
if err != nil {
|
disc.StartGlobal(cfg.Options.GlobalAnnServer)
|
||||||
warnf("No discovery possible (%v)", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return disc
|
return disc
|
||||||
|
@ -40,7 +40,7 @@ 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 string, addresses []string, extServer string) (*Discoverer, error) {
|
func NewDiscoverer(id string, addresses []string) (*Discoverer, error) {
|
||||||
disc := &Discoverer{
|
disc := &Discoverer{
|
||||||
MyID: id,
|
MyID: id,
|
||||||
ListenAddresses: addresses,
|
ListenAddresses: addresses,
|
||||||
@ -48,32 +48,26 @@ func NewDiscoverer(id string, addresses []string, extServer string) (*Discoverer
|
|||||||
ExtBroadcastIntv: 1800 * time.Second,
|
ExtBroadcastIntv: 1800 * time.Second,
|
||||||
beacon: mc.NewBeacon("239.21.0.25", 21025),
|
beacon: mc.NewBeacon("239.21.0.25", 21025),
|
||||||
registry: make(map[string][]string),
|
registry: make(map[string][]string),
|
||||||
extServer: extServer,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Receive announcements sent to the local multicast group.
|
// Receive announcements sent to the local multicast group.
|
||||||
|
|
||||||
go disc.recvAnnouncements()
|
go disc.recvAnnouncements()
|
||||||
|
|
||||||
// If we got a list of addresses that we listen on, announce those
|
|
||||||
// locally.
|
|
||||||
|
|
||||||
if len(disc.ListenAddresses) > 0 {
|
|
||||||
disc.localBroadcastTick = time.Tick(disc.BroadcastIntv)
|
|
||||||
disc.forcedBroadcastTick = make(chan time.Time)
|
|
||||||
go disc.sendLocalAnnouncements()
|
|
||||||
|
|
||||||
// If we have an external server address, also announce to that
|
|
||||||
// server.
|
|
||||||
|
|
||||||
if len(disc.extServer) > 0 {
|
|
||||||
go disc.sendExternalAnnouncements()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return disc, nil
|
return disc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Discoverer) StartLocal() {
|
||||||
|
d.localBroadcastTick = time.Tick(d.BroadcastIntv)
|
||||||
|
d.forcedBroadcastTick = make(chan time.Time)
|
||||||
|
go d.sendLocalAnnouncements()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *Discoverer) StartGlobal(server string) {
|
||||||
|
d.extServer = server
|
||||||
|
go d.sendExternalAnnouncements()
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Discoverer) announcementPkt() []byte {
|
func (d *Discoverer) announcementPkt() []byte {
|
||||||
var addrs []Address
|
var addrs []Address
|
||||||
for _, astr := range d.ListenAddresses {
|
for _, astr := range d.ListenAddresses {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user