Commit eaa7a9d5 authored by Brian Tiger Chow's avatar Brian Tiger Chow Committed by Jeromy

misc(bitswap) renaming

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 0163be78
...@@ -153,14 +153,14 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e ...@@ -153,14 +153,14 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
func (bs *bitswap) run(ctx context.Context) { func (bs *bitswap) run(ctx context.Context) {
const batchDelay = time.Millisecond * 3 // Time to wait before sending out wantlists to better batch up requests
const numKeysPerBatch = 10
const maxProvidersPerRequest = 6
const rebroadcastPeriod = time.Second * 5 // Every so often, we should resend out our current want list const rebroadcastPeriod = time.Second * 5 // Every so often, we should resend out our current want list
const batchDelay = time.Millisecond * 3 // Time to wait before sending out wantlists to better batch up requests
const peersPerSend = 6
const threshold = 10
var sendlist <-chan peer.Peer // NB: must be initialized to zero value var providers <-chan peer.Peer // NB: must be initialized to zero value
broadcastSignal := time.After(rebroadcastPeriod) broadcastSignal := time.After(rebroadcastPeriod)
unsent := 0 unsentKeys := 0
for { for {
select { select {
...@@ -169,32 +169,33 @@ func (bs *bitswap) run(ctx context.Context) { ...@@ -169,32 +169,33 @@ func (bs *bitswap) run(ctx context.Context) {
if len(wantlist) == 0 { if len(wantlist) == 0 {
continue continue
} }
if sendlist == nil { if providers == nil {
// rely on semi randomness of maps // rely on semi randomness of maps
firstKey := wantlist[0] firstKey := wantlist[0]
sendlist = bs.routing.FindProvidersAsync(ctx, firstKey, 6) providers = bs.routing.FindProvidersAsync(ctx, firstKey, 6)
} }
err := bs.sendWantListTo(ctx, sendlist) err := bs.sendWantListTo(ctx, providers)
if err != nil { if err != nil {
log.Errorf("error sending wantlist: %s", err) log.Errorf("error sending wantlist: %s", err)
} }
sendlist = nil providers = nil
broadcastSignal = time.After(rebroadcastPeriod) broadcastSignal = time.After(rebroadcastPeriod)
case k := <-bs.blockRequests: case k := <-bs.blockRequests:
if unsent == 0 { if unsentKeys == 0 {
sendlist = bs.routing.FindProvidersAsync(ctx, k, peersPerSend) providers = bs.routing.FindProvidersAsync(ctx, k, maxProvidersPerRequest)
} }
unsent++ unsentKeys++
if unsent >= threshold { if unsentKeys >= numKeysPerBatch {
// send wantlist to sendlist // send wantlist to providers
err := bs.sendWantListTo(ctx, sendlist) err := bs.sendWantListTo(ctx, providers)
if err != nil { if err != nil {
log.Errorf("error sending wantlist: %s", err) log.Errorf("error sending wantlist: %s", err)
} }
unsent = 0 unsentKeys = 0
broadcastSignal = time.After(rebroadcastPeriod) broadcastSignal = time.After(rebroadcastPeriod)
sendlist = nil providers = nil
} else { } else {
// set a timeout to wait for more blocks or send current wantlist // set a timeout to wait for more blocks or send current wantlist
......
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