mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	fix admin dht function, more cleanup, and slowly throttle back dht traffic when idle
This commit is contained in:
		
							parent
							
								
									5a85d3515d
								
							
						
					
					
						commit
						f3ec8c5b37
					
				
					 3 changed files with 24 additions and 24 deletions
				
			
		| 
						 | 
					@ -555,27 +555,23 @@ func (a *admin) getData_getSwitchQueues() admin_nodeInfo {
 | 
				
			||||||
func (a *admin) getData_getDHT() []admin_nodeInfo {
 | 
					func (a *admin) getData_getDHT() []admin_nodeInfo {
 | 
				
			||||||
	var infos []admin_nodeInfo
 | 
						var infos []admin_nodeInfo
 | 
				
			||||||
	getDHT := func() {
 | 
						getDHT := func() {
 | 
				
			||||||
		/* TODO fix this
 | 
							now := time.Now()
 | 
				
			||||||
		  	now := time.Now()
 | 
							var dhtInfos []*dhtInfo
 | 
				
			||||||
				for i := 0; i < a.core.dht.nBuckets(); i++ {
 | 
							for _, v := range a.core.dht.table {
 | 
				
			||||||
					b := a.core.dht.getBucket(i)
 | 
								dhtInfos = append(dhtInfos, v)
 | 
				
			||||||
					getInfo := func(vs []*dhtInfo, isPeer bool) {
 | 
							}
 | 
				
			||||||
						for _, v := range vs {
 | 
							sort.SliceStable(dhtInfos, func(i, j int) bool {
 | 
				
			||||||
							addr := *address_addrForNodeID(v.getNodeID())
 | 
								return dht_ordered(&a.core.dht.nodeID, dhtInfos[i].getNodeID(), dhtInfos[j].getNodeID())
 | 
				
			||||||
							info := admin_nodeInfo{
 | 
							})
 | 
				
			||||||
								{"ip", net.IP(addr[:]).String()},
 | 
							for _, v := range dhtInfos {
 | 
				
			||||||
								{"coords", fmt.Sprint(v.coords)},
 | 
								addr := *address_addrForNodeID(v.getNodeID())
 | 
				
			||||||
								{"bucket", i},
 | 
								info := admin_nodeInfo{
 | 
				
			||||||
								{"peer_only", isPeer},
 | 
									{"ip", net.IP(addr[:]).String()},
 | 
				
			||||||
								{"last_seen", int(now.Sub(v.recv).Seconds())},
 | 
									{"coords", fmt.Sprint(v.coords)},
 | 
				
			||||||
							}
 | 
									{"last_seen", int(now.Sub(v.recv).Seconds())},
 | 
				
			||||||
							infos = append(infos, info)
 | 
								}
 | 
				
			||||||
						}
 | 
								infos = append(infos, info)
 | 
				
			||||||
					}
 | 
							}
 | 
				
			||||||
					getInfo(b.other, false)
 | 
					 | 
				
			||||||
					getInfo(b.peers, true)
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
		*/
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	a.core.router.doAdmin(getDHT)
 | 
						a.core.router.doAdmin(getDHT)
 | 
				
			||||||
	return infos
 | 
						return infos
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,6 +15,7 @@ type dhtInfo struct {
 | 
				
			||||||
	coords        []byte
 | 
						coords        []byte
 | 
				
			||||||
	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
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 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.
 | 
				
			||||||
| 
						 | 
					@ -101,9 +102,14 @@ func (t *dht) insert(info *dhtInfo) {
 | 
				
			||||||
	info.recv = time.Now()
 | 
						info.recv = time.Now()
 | 
				
			||||||
	if oldInfo, isIn := t.table[*info.getNodeID()]; isIn {
 | 
						if oldInfo, isIn := t.table[*info.getNodeID()]; isIn {
 | 
				
			||||||
		info.send = oldInfo.send
 | 
							info.send = oldInfo.send
 | 
				
			||||||
 | 
							info.throttle = oldInfo.throttle
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		info.send = info.recv
 | 
							info.send = info.recv
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						info.throttle += time.Second
 | 
				
			||||||
 | 
						if info.throttle > 30*time.Second {
 | 
				
			||||||
 | 
							info.throttle = 30 * time.Second
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	t.table[*info.getNodeID()] = info
 | 
						t.table[*info.getNodeID()] = info
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -293,6 +299,7 @@ func (t *dht) doMaintenance() {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if successor != nil &&
 | 
						if successor != nil &&
 | 
				
			||||||
 | 
							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)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -126,10 +126,7 @@ func (s *searches) doSearchStep(sinfo *searchInfo) {
 | 
				
			||||||
		// Send to the next search target
 | 
							// Send to the next search target
 | 
				
			||||||
		var next *dhtInfo
 | 
							var next *dhtInfo
 | 
				
			||||||
		next, sinfo.toVisit = sinfo.toVisit[0], sinfo.toVisit[1:]
 | 
							next, sinfo.toVisit = sinfo.toVisit[0], sinfo.toVisit[1:]
 | 
				
			||||||
		//var oldPings int
 | 
					 | 
				
			||||||
		//oldPings, next.pings = next.pings, 0
 | 
					 | 
				
			||||||
		s.core.dht.ping(next, &sinfo.dest)
 | 
							s.core.dht.ping(next, &sinfo.dest)
 | 
				
			||||||
		//next.pings = oldPings // Don't evict a node for searching with it too much
 | 
					 | 
				
			||||||
		sinfo.visited[*next.getNodeID()] = true
 | 
							sinfo.visited[*next.getNodeID()] = true
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue