transactionIDInt uint64
nodes map[string]*node // Keyed by dHTAddr.String().
mu sync.Mutex
- closed chan struct{}
+ closed missinggo.Event
ipBlockList iplist.Ranger
badNodes *boom.BloomFilter
}
go func() {
err := s.serve()
- select {
- case <-s.closed:
+ s.mu.Lock()
+ defer s.mu.Unlock()
+ if s.closed.IsSet() {
return
- default:
}
if err != nil {
panic(err)
go func() {
err := s.bootstrap()
if err != nil {
- select {
- case <-s.closed:
- default:
+ s.mu.Lock()
+ if !s.closed.IsSet() {
log.Printf("error bootstrapping DHT: %s", err)
}
+ s.mu.Unlock()
}
}()
return
if err != nil {
return
}
- s.closed = make(chan struct{})
s.transactions = make(map[transactionKey]*Transaction)
return
}
}()
s.mu.Unlock()
select {
- case <-s.closed:
+ case <-s.closed.C():
s.mu.Lock()
return
case <-time.After(15 * time.Second):
// Stops the server network activity. This is all that's required to clean-up a Server.
func (s *Server) Close() {
s.mu.Lock()
- select {
- case <-s.closed:
- default:
- close(s.closed)
- s.socket.Close()
- }
- s.mu.Unlock()
+ defer s.mu.Unlock()
+ s.closed.Set()
+ s.socket.Close()
}
func (s *Server) setDefaults() (err error) {