remove sendCancelable

This commit is contained in:
Alex Grintsvayg 2018-06-25 15:56:45 -04:00
parent e534f5b972
commit 66ca77b690
5 changed files with 6 additions and 20 deletions

View file

@ -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
}

View file

@ -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()
}
}()
}

View file

@ -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

View file

@ -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():

View file

@ -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 ""
}