swarm/network: introduce lastActive set when chunk received

This commit is contained in:
zelig 2016-07-17 08:07:37 +02:00
parent ce2a7e23e6
commit 05c62a9922
2 changed files with 4 additions and 4 deletions

View file

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

View file

@ -79,6 +79,7 @@ type bzz struct {
rw p2p.MsgReadWriter // messageReadWriter to send messages to rw p2p.MsgReadWriter // messageReadWriter to send messages to
errors *errs.Errors // errors table errors *errs.Errors // errors table
backend bind.Backend backend bind.Backend
lastActive time.Time
swap *swap.Swap // swap instance for the peer connection swap *swap.Swap // swap instance for the peer connection
swapParams *bzzswap.SwapParams // swap settings both local and remote swapParams *bzzswap.SwapParams // swap settings both local and remote
@ -229,6 +230,8 @@ func (self *bzz) handle() error {
if len(req.SData) < 9 { if len(req.SData) < 9 {
return self.protoError(ErrDecode, "<- %v: Data too short (%v)", msg) return self.protoError(ErrDecode, "<- %v: Data too short (%v)", msg)
} }
// last Active time is set only when receiving chunks
self.lastActive = time.Now()
glog.V(logger.Detail).Infof("[BZZ] incoming store request: %s", req.String()) glog.V(logger.Detail).Infof("[BZZ] incoming store request: %s", req.String())
// swap accounting is done within forwarding // swap accounting is done within forwarding
self.storage.HandleStoreRequestMsg(&req, &peer{bzz: self}) self.storage.HandleStoreRequestMsg(&req, &peer{bzz: self})