Merge branch 'master' into pr/511

* master: (21 commits)
  Mechanism to stop external announcement routine
  Update goleveldb
  Perfstats are not supported on Windows
  Build should fail if a platform does not build
  Include perfstats and heap profiles in standard build
  Actually no, lets not do uploads at all from the build script.
  ./build.sh upload build server artifacts
  Sign checksums, not files.
  Badges, add build server
  Remove Solaris build again, for now
  Travis should build with 1.3 + tip
  Translation update
  Indicate aproximativeness of repo sizes...
  Slightly more conservative guess on file size
  Fix set tests
  Small goleveldb hack to reduce allocations somewhat
  Don't load block lists from db unless necessary
  Rip out the Suppressor (maybe to be reintroduced)
  Reduce allocations while hash scanning
  Add heap profiling support
  ...

Conflicts:
	discover/discover.go
This commit is contained in:
Jakob Borg
2014-08-14 12:48:33 +02:00
43 changed files with 1416 additions and 609 deletions

View File

@@ -24,12 +24,15 @@ type Discoverer struct {
listenAddrs []string
localBcastIntv time.Duration
globalBcastIntv time.Duration
errorRetryIntv time.Duration
beacon *beacon.Beacon
registry map[protocol.NodeID][]string
registryLock sync.RWMutex
extServer string
extPort uint16
localBcastTick <-chan time.Time
stopGlobal chan struct{}
globalWG sync.WaitGroup
forcedBcastTick chan time.Time
extAnnounceOK bool
extAnnounceOKmut sync.Mutex
@@ -55,6 +58,7 @@ func NewDiscoverer(id protocol.NodeID, addresses []string, localPort int) (*Disc
listenAddrs: addresses,
localBcastIntv: 30 * time.Second,
globalBcastIntv: 1800 * time.Second,
errorRetryIntv: 60 * time.Second,
beacon: b,
registry: make(map[protocol.NodeID][]string),
}
@@ -71,16 +75,20 @@ func (d *Discoverer) StartLocal() {
}
func (d *Discoverer) StartGlobal(server string, extPort uint16) {
if d.globalBcastStop != nil {
d.globalBcastStop <- true
} else {
d.globalBcastStop = make(chan bool)
}
// Wait for any previous announcer to stop before starting a new one.
d.globalWG.Wait()
d.extServer = server
d.extPort = extPort
d.stopGlobal = make(chan struct{})
d.globalWG.Add(1)
go d.sendExternalAnnouncements()
}
func (d *Discoverer) StopGlobal() {
close(d.stopGlobal)
d.globalWG.Wait()
}
func (d *Discoverer) ExtAnnounceOK() bool {
d.extAnnounceOKmut.Lock()
defer d.extAnnounceOKmut.Unlock()
@@ -179,20 +187,19 @@ func (d *Discoverer) sendLocalAnnouncements() {
}
func (d *Discoverer) sendExternalAnnouncements() {
// this should go in the Discoverer struct
errorRetryIntv := 60 * time.Second
defer d.globalWG.Done()
remote, err := net.ResolveUDPAddr("udp", d.extServer)
for err != nil {
l.Warnf("Global discovery: %v; trying again in %v", err, errorRetryIntv)
time.Sleep(errorRetryIntv)
l.Warnf("Global discovery: %v; trying again in %v", err, d.errorRetryIntv)
time.Sleep(d.errorRetryIntv)
remote, err = net.ResolveUDPAddr("udp", d.extServer)
}
conn, err := net.ListenUDP("udp", nil)
for err != nil {
l.Warnf("Global discovery: %v; trying again in %v", err, errorRetryIntv)
time.Sleep(errorRetryIntv)
l.Warnf("Global discovery: %v; trying again in %v", err, d.errorRetryIntv)
time.Sleep(d.errorRetryIntv)
conn, err = net.ListenUDP("udp", nil)
}
@@ -207,7 +214,10 @@ func (d *Discoverer) sendExternalAnnouncements() {
buf = d.announcementPkt()
}
for {
var bcastTick = time.Tick(d.globalBcastIntv)
var errTick <-chan time.Time
sendOneAnnouncement := func() {
var ok bool
if debug {
@@ -236,21 +246,32 @@ func (d *Discoverer) sendExternalAnnouncements() {
d.extAnnounceOKmut.Unlock()
if ok {
// Don't do a long sleep, listen for a stop signal, just incase
// the UPnP mapping has changed, and a new routine should be started.
for i := time.Duration(0); i < d.globalBcastIntv; i += time.Duration(1) {
select {
case <-d.globalBcastStop:
return
default:
time.Sleep(1 * time.Second)
}
}
} else {
time.Sleep(errorRetryIntv)
errTick = nil
} else if errTick != nil {
errTick = time.Tick(d.errorRetryIntv)
}
}
// Announce once, immediately
sendOneAnnouncement()
loop:
for {
select {
case <-d.stopGlobal:
break loop
case <-errTick:
sendOneAnnouncement()
case <-bcastTick:
sendOneAnnouncement()
}
}
if debug {
l.Debugln("discover: stopping global")
}
}
func (d *Discoverer) recvAnnouncements() {
@@ -311,7 +332,7 @@ func (d *Discoverer) registerNode(addr net.Addr, node Node) bool {
}
}
if debug {
l.Debugf("discover: register: %s -> %#v", node.ID, addrs)
l.Debugf("discover: register: %v -> %#v", node.ID, addrs)
}
var id protocol.NodeID
copy(id[:], node.ID)