Commit 5f03eb12 authored by Matt Joiner's avatar Matt Joiner

Reduce contention on server lock when getting start addresses

The Server.mu was being unnecessarily held while doing DNS.
parent fd94da7a
......@@ -56,8 +56,6 @@ func newBloomFilterForTraversal() *bloom.BloomFilter {
// caller, and announcing the local node to each node if allowed and
// specified.
func (s *Server) Announce(infoHash [20]byte, port int, impliedPort bool) (*Announce, error) {
s.mu.Lock()
defer s.mu.Unlock()
startAddrs, err := s.traversalStartingAddrs()
if err != nil {
return nil, err
......
......@@ -32,7 +32,7 @@ type Server struct {
id int160
socket net.PacketConn
mu sync.Mutex
mu sync.RWMutex
transactions map[transactionKey]*Transaction
nextT uint64 // unique "t" field for outbound queries
table table
......@@ -674,9 +674,7 @@ type TraversalStats struct {
// Populates the node table.
func (s *Server) Bootstrap() (ts TraversalStats, err error) {
s.mu.Lock()
initialAddrs, err := s.traversalStartingAddrs()
s.mu.Unlock()
if err != nil {
return
}
......@@ -780,10 +778,12 @@ func (s *Server) closestNodes(k int, target int160, filter func(*node) bool) []*
}
func (s *Server) traversalStartingAddrs() (addrs []Addr, err error) {
s.mu.RLock()
s.table.forNodes(func(n *node) bool {
addrs = append(addrs, n.addr)
return true
})
s.mu.RUnlock()
if len(addrs) > 0 {
return
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment