good morning!!!!

Skip to content
Snippets Groups Projects
Commit 706da56f authored by Péter Szilágyi's avatar Péter Szilágyi
Browse files

p2p/discover: wrap the pinger to update the node db too

parent 85b4b442
No related branches found
No related tags found
No related merge requests found
......@@ -288,8 +288,7 @@ func (tab *Table) pingpong(w *bondproc, pinged bool, id NodeID, addr *net.UDPAdd
defer func() { tab.bondslots <- struct{}{} }()
// Ping the remote side and wait for a pong
tab.db.updateLastPing(id, time.Now())
if w.err = tab.net.ping(id, addr); w.err != nil {
if w.err = tab.ping(id, addr); w.err != nil {
close(w.done)
return
}
......@@ -307,14 +306,13 @@ func (tab *Table) pingpong(w *bondproc, pinged bool, id NodeID, addr *net.UDPAdd
TCPPort: int(tcpPort),
}
tab.db.updateNode(w.n)
tab.db.updateLastPong(id, time.Now())
close(w.done)
}
func (tab *Table) pingreplace(new *Node, b *bucket) {
if len(b.entries) == bucketSize {
oldest := b.entries[bucketSize-1]
if err := tab.net.ping(oldest.ID, oldest.addr()); err == nil {
if err := tab.ping(oldest.ID, oldest.addr()); err == nil {
// The node responded, we don't need to replace it.
return
}
......@@ -327,6 +325,19 @@ func (tab *Table) pingreplace(new *Node, b *bucket) {
b.entries[0] = new
}
// ping a remote endpoint and wait for a reply, also updating the node database
// accordingly.
func (tab *Table) ping(id NodeID, addr *net.UDPAddr) error {
// Update the last ping and send the message
tab.db.updateLastPing(id, time.Now())
if err := tab.net.ping(id, addr); err != nil {
return err
}
// Pong received, update the database and return
tab.db.updateLastPong(id, time.Now())
return nil
}
// add puts the entries into the table if their corresponding
// bucket is not full. The caller must hold tab.mutex.
func (tab *Table) add(entries []*Node) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment