@cryptotaxi247 / kubo / commits / e5983cbe7

some renaming

License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>

Brian Tiger Chow committed Nov 18, 2014 at 22:58 UTC e5983cbe7dbcb38278895bb6b4a77a1786ad5f72
2 files changed +12 -14
exchange/bitswap/bitswap.go
+11 -13
@@ -155,21 +155,19 @@ func (bs *bitswap) sendWantListTo(ctx context.Context, peers <-chan peer.Peer) e
155 }
156
157 func (bs *bitswap) run(ctx context.Context) {
158 - var sendlist <-chan peer.Peer
158
160 - // Every so often, we should resend out our current want list
161 - const rebroadcastTime = time.Second * 5
162 -
163 - // Time to wait before sending out wantlists to better batch up requests
164 - const bufferTime = time.Millisecond * 3
165 - peersPerSend := 6
166 -
167 - timeout := time.After(rebroadcastTime)
159 + const rebroadcastPeriod = time.Second * 5 // Every so often, we should resend out our current want list
160 + const batchDelay = time.Millisecond * 3 // Time to wait before sending out wantlists to better batch up requests
161 + const peersPerSend = 6
162 const threshold = 10
163 +
164 + var sendlist <-chan peer.Peer // NB: must be initialized to zero value
165 + broadcastSignal := time.After(rebroadcastPeriod)
166 unsent := 0
167 +
168 for {
169 select {
172 - case <-timeout:
170 + case <-broadcastSignal:
171 wantlist := bs.wantlist.Keys()
172 if len(wantlist) == 0 {
173 continue
@@ -184,7 +182,7 @@ func (bs *bitswap) run(ctx context.Context) {
182 log.Errorf("error sending wantlist: %s", err)
183 }
184 sendlist = nil
187 - timeout = time.After(rebroadcastTime)
185 + broadcastSignal = time.After(rebroadcastPeriod)
186 case k := <-bs.blockRequests:
187 if unsent == 0 {
188 sendlist = bs.routing.FindProvidersAsync(ctx, k, peersPerSend)
@@ -198,12 +196,12 @@ func (bs *bitswap) run(ctx context.Context) {
196 log.Errorf("error sending wantlist: %s", err)
197 }
198 unsent = 0
201 - timeout = time.After(rebroadcastTime)
199 + broadcastSignal = time.After(rebroadcastPeriod)
200 sendlist = nil
201 } else {
202 // set a timeout to wait for more blocks or send current wantlist
203
206 - timeout = time.After(bufferTime)
204 + broadcastSignal = time.After(batchDelay)
205 }
206 case <-ctx.Done():
207 return
exchange/bitswap/bitswap_test.go
+1 -1
@@ -294,7 +294,7 @@ func session(net tn.Network, rs mock.RoutingServer, id peer.ID) instance {
294 routing: htc,
295 sender: adapter,
296 wantlist: util.NewKeySet(),
297 - blockReq: make(chan util.Key, 32),
297 + blockRequests: make(chan util.Key, 32),
298 }
299 adapter.SetDelegate(bs)
300 go bs.run(context.TODO())