Add RefreshSync method for Sync bookkeeping

This commit is contained in:
Milos Gajdos 2020-01-10 10:43:07 +00:00
parent 63edfaa852
commit 0a4bd02503
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F

View File

@ -36,6 +36,8 @@ type node struct {
network Network
// lastSeen keeps track of node lifetime and updates
lastSeen time.Time
// lastSync keeps track of node last sync request
lastSync time.Time
}
// Id is node ide
@ -127,7 +129,7 @@ func (n *node) UpdatePeer(peer *node) error {
return ErrPeerNotFound
}
// RefreshPeer updates node timestamp
// RefreshPeer updates node last seen timestamp
// It returns false if the peer has not been found.
func (n *node) RefreshPeer(id, link string, now time.Time) error {
n.Lock()
@ -146,6 +148,16 @@ func (n *node) RefreshPeer(id, link string, now time.Time) error {
return nil
}
// RefreshSync refreshes nodes sync time
func (n *node) RefreshSync(now time.Time) error {
n.Lock()
defer n.Unlock()
n.lastSync = now
return nil
}
// Nodes returns a slice of all nodes in the whole node topology
func (n *node) Nodes() []Node {
// we need to freeze the network graph here