mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	add max pings before timing out a successor
This commit is contained in:
		
							parent
							
								
									63d6ab4251
								
							
						
					
					
						commit
						d851d9afe7
					
				
					 1 changed files with 3 additions and 1 deletions
				
			
		| 
						 | 
					@ -16,6 +16,7 @@ type dhtInfo struct {
 | 
				
			||||||
	send          time.Time // When we last sent a message
 | 
						send          time.Time // When we last sent a message
 | 
				
			||||||
	recv          time.Time // When we last received a message
 | 
						recv          time.Time // When we last received a message
 | 
				
			||||||
	throttle      time.Duration
 | 
						throttle      time.Duration
 | 
				
			||||||
 | 
						pings         int // Time out if at least 3 consecutive maintenance pings drop
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Returns the *NodeID associated with dhtInfo.key, calculating it on the fly the first time or from a cache all subsequent times.
 | 
					// Returns the *NodeID associated with dhtInfo.key, calculating it on the fly the first time or from a cache all subsequent times.
 | 
				
			||||||
| 
						 | 
					@ -314,7 +315,7 @@ func (t *dht) doMaintenance() {
 | 
				
			||||||
	var successor *dhtInfo
 | 
						var successor *dhtInfo
 | 
				
			||||||
	now := time.Now()
 | 
						now := time.Now()
 | 
				
			||||||
	for infoID, info := range t.table {
 | 
						for infoID, info := range t.table {
 | 
				
			||||||
		if now.Sub(info.recv) > time.Minute {
 | 
							if now.Sub(info.recv) > time.Minute || info.pings > 3 {
 | 
				
			||||||
			delete(t.table, infoID)
 | 
								delete(t.table, infoID)
 | 
				
			||||||
		} else if successor == nil || dht_ordered(&t.nodeID, &infoID, successor.getNodeID()) {
 | 
							} else if successor == nil || dht_ordered(&t.nodeID, &infoID, successor.getNodeID()) {
 | 
				
			||||||
			successor = info
 | 
								successor = info
 | 
				
			||||||
| 
						 | 
					@ -324,5 +325,6 @@ func (t *dht) doMaintenance() {
 | 
				
			||||||
		now.Sub(successor.recv) > successor.throttle &&
 | 
							now.Sub(successor.recv) > successor.throttle &&
 | 
				
			||||||
		now.Sub(successor.send) > 6*time.Second {
 | 
							now.Sub(successor.send) > 6*time.Second {
 | 
				
			||||||
		t.ping(successor, nil)
 | 
							t.ping(successor, nil)
 | 
				
			||||||
 | 
							successor.pings++
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue