diff --git a/dht/bootstrap.go b/dht/bootstrap.go index 0ca6864..2bb9230 100644 --- a/dht/bootstrap.go +++ b/dht/bootstrap.go @@ -132,14 +132,13 @@ func (b *BootstrapNode) ping(c Contact) { b.stop.Add(1) defer b.stop.Done() - resCh, cancel := b.SendCancelable(c, Request{Method: pingMethod}) + resCh := b.SendAsync(c, Request{Method: pingMethod}) var res *Response select { case res = <-resCh: case <-b.stop.Ch(): - cancel() return } diff --git a/dht/dht.go b/dht/dht.go index a37b42f..37f16de 100644 --- a/dht/dht.go +++ b/dht/dht.go @@ -318,7 +318,7 @@ func (dht *DHT) storeOnNode(hash bits.Bitmap, c Contact) { token := dht.tokenCache.Get(c, hash, dht.stop.Ch()) - resCh, cancel := dht.node.SendCancelable(c, Request{ + resCh := dht.node.SendAsync(c, Request{ Method: storeMethod, StoreArgs: &storeArgs{ BlobHash: hash, @@ -334,7 +334,6 @@ func (dht *DHT) storeOnNode(hash bits.Bitmap, c Contact) { select { case <-resCh: case <-dht.stop.Ch(): - cancel() } }() } diff --git a/dht/node.go b/dht/node.go index e2343e5..7bc828a 100644 --- a/dht/node.go +++ b/dht/node.go @@ -1,7 +1,6 @@ package dht import ( - "context" "encoding/hex" "net" "strings" @@ -387,7 +386,7 @@ 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 { +func (n *Node) SendAsync(contact Contact, req Request, options ...SendOptions) <-chan *Response { ch := make(chan *Response, 1) if contact.ID.Equals(n.id) { @@ -429,9 +428,6 @@ func (n *Node) SendAsync(ctx context.Context, contact Contact, req Request, opti return case <-n.stop.Ch(): return - case <-ctx.Done(): - // TODO: canceling these requests doesn't do much. we can probably stop supporting this feature and just use async - return case <-time.After(udpTimeout): } } @@ -446,13 +442,7 @@ func (n *Node) SendAsync(ctx context.Context, contact Contact, req Request, opti // Send sends a transaction and blocks until the response is available. It returns a response, or nil // if the transaction timed out. func (n *Node) Send(contact Contact, req Request, options ...SendOptions) *Response { - return <-n.SendAsync(context.Background(), contact, req, options...) -} - -// SendCancelable sends the transaction asynchronously and allows the transaction to be canceled -func (n *Node) SendCancelable(contact Contact, req Request, options ...SendOptions) (<-chan *Response, context.CancelFunc) { - ctx, cancel := context.WithCancel(context.Background()) - return n.SendAsync(ctx, contact, req, options...), cancel + return <-n.SendAsync(contact, req, options...) } // CountActiveTransactions returns the number of transactions in the manager diff --git a/dht/node_finder.go b/dht/node_finder.go index 00c5c2a..a455374 100644 --- a/dht/node_finder.go +++ b/dht/node_finder.go @@ -1,7 +1,6 @@ package dht import ( - "context" "sort" "sync" "time" @@ -223,7 +222,7 @@ func (cf *contactFinder) probe(cycleID string) *Contact { } var res *Response - resCh := cf.node.SendAsync(context.Background(), c, req) + resCh := cf.node.SendAsync(c, req) select { case res = <-resCh: case <-cf.stop.Ch(): diff --git a/dht/token_cache.go b/dht/token_cache.go index e080155..b10c514 100644 --- a/dht/token_cache.go +++ b/dht/token_cache.go @@ -41,7 +41,7 @@ func (tc *tokenCache) Get(c Contact, hash bits.Bitmap, cancelCh stopOnce.Chan) s return token.token } - resCh, cancel := tc.node.SendCancelable(c, Request{ + resCh := tc.node.SendAsync(c, Request{ Method: findValueMethod, Arg: &hash, }) @@ -51,7 +51,6 @@ func (tc *tokenCache) Get(c Contact, hash bits.Bitmap, cancelCh stopOnce.Chan) s select { case res = <-resCh: case <-cancelCh: - cancel() return "" }