diff --git a/dht/dht.go b/dht/dht.go index a9f98c8..2873d43 100644 --- a/dht/dht.go +++ b/dht/dht.go @@ -37,7 +37,8 @@ const ( udpRetry = 3 udpTimeout = 5 * time.Second - udpMaxMessageLength = 1024 // bytes. I think our longest message is ~676 bytes, so I rounded up + udpMaxMessageLength = 4096 // bytes. I think our longest message is ~676 bytes, so I rounded up to 1024 + // scratch that. a findValue could return more than K results if a lot of nodes are storing that value, so we need more buffer maxPeerFails = 3 // after this many failures, a peer is considered bad and will be removed from the routing table //tExpire = 60 * time.Minute // the time after which a key/value pair expires; this is a time-to-live (TTL) from the original publication date diff --git a/dht/node.go b/dht/node.go index 58dd3fd..0bb5cc6 100644 --- a/dht/node.go +++ b/dht/node.go @@ -384,13 +384,14 @@ type SendOptions struct { // SendAsync sends a transaction and returns a channel that will eventually contain the transaction response // The response channel is closed when the transaction is completed or times out. func (n *Node) SendAsync(ctx context.Context, contact Contact, req Request, options ...SendOptions) <-chan *Response { + ch := make(chan *Response, 1) + if contact.ID.Equals(n.id) { log.Error("sending query to self") - return nil + close(ch) + return ch } - ch := make(chan *Response, 1) - go func() { defer close(ch) diff --git a/dht/routing_table.go b/dht/routing_table.go index 5f30521..f4c4009 100644 --- a/dht/routing_table.go +++ b/dht/routing_table.go @@ -351,7 +351,7 @@ func appendContacts(contacts []sortedContact, b bucket, target bits.Bitmap) []so func (rt *routingTable) Count() int { count := 0 for _, bucket := range rt.buckets { - count = bucket.Len() + count += bucket.Len() } return count }