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
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 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)
unsent := 0
unsentKeys := 0
for {
select {
......@@ -169,32 +169,33 @@ func (bs *bitswap) run(ctx context.Context) {
if len(wantlist) == 0 {
continue
}
if sendlist == nil {
if providers == nil {
// rely on semi randomness of maps
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 {
log.Errorf("error sending wantlist: %s", err)
}
sendlist = nil
providers = nil
broadcastSignal = time.After(rebroadcastPeriod)
case k := <-bs.blockRequests:
if unsent == 0 {
sendlist = bs.routing.FindProvidersAsync(ctx, k, peersPerSend)
if unsentKeys == 0 {
providers = bs.routing.FindProvidersAsync(ctx, k, maxProvidersPerRequest)
}
unsent++
unsentKeys++
if unsent >= threshold {
// send wantlist to sendlist
err := bs.sendWantListTo(ctx, sendlist)
if unsentKeys >= numKeysPerBatch {
// send wantlist to providers
err := bs.sendWantListTo(ctx, providers)
if err != nil {
log.Errorf("error sending wantlist: %s", err)
}
unsent = 0
unsentKeys = 0
broadcastSignal = time.After(rebroadcastPeriod)
sendlist = nil
providers = nil
} else {
// 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