Skip to content

Commit 05c62a9

Browse files
committed
swarm/network: introduce lastActive set when chunk received
1 parent ce2a7e2 commit 05c62a9

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

swarm/network/hive.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func (self *peer) Url() string {
294294

295295
// TODO take into account traffic
296296
func (self *peer) LastActive() time.Time {
297-
return time.Now()
297+
return self.lastActive
298298
}
299299

300300
// reads the serialised form of sync state persisted as the 'Meta' attribute
@@ -335,9 +335,6 @@ func saveSync(record *kademlia.NodeRecord, node kademlia.Node) {
335335
// sends relevant peer data given by the kademlia hive to the requester
336336
// TODO: remember peers sent for duration of the session, only new peers sent
337337
func (self *Hive) peers(req *retrieveRequestMsgData) {
338-
// FIXME: should check req.MaxPeers but then should not default to zero or make sure we set it when sending retrieveRequests
339-
// we might need chunk.req to cache relevant peers response,
340-
// hive change would expire it
341338
if req != nil && req.MaxPeers >= 0 {
342339
var addrs []*peerAddr
343340
if req.timeout == nil || time.Now().Before(*(req.timeout)) {

swarm/network/protocol.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type bzz struct {
7979
rw p2p.MsgReadWriter // messageReadWriter to send messages to
8080
errors *errs.Errors // errors table
8181
backend bind.Backend
82+
lastActive time.Time
8283

8384
swap *swap.Swap // swap instance for the peer connection
8485
swapParams *bzzswap.SwapParams // swap settings both local and remote
@@ -229,6 +230,8 @@ func (self *bzz) handle() error {
229230
if len(req.SData) < 9 {
230231
return self.protoError(ErrDecode, "<- %v: Data too short (%v)", msg)
231232
}
233+
// last Active time is set only when receiving chunks
234+
self.lastActive = time.Now()
232235
glog.V(logger.Detail).Infof("[BZZ] incoming store request: %s", req.String())
233236
// swap accounting is done within forwarding
234237
self.storage.HandleStoreRequestMsg(&req, &peer{bzz: self})

0 commit comments

Comments
 (0)