mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	some nodeinfo actor fixes and adjust search timeout
This commit is contained in:
		
							parent
							
								
									8c12fc4fdb
								
							
						
					
					
						commit
						c3b1a6af65
					
				
					 4 changed files with 10 additions and 11 deletions
				
			
		| 
						 | 
					@ -398,6 +398,7 @@ func (c *Core) GetNodeInfo(key crypto.BoxPubKey, coords []uint64, nocache bool)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	c.router.nodeinfo.sendNodeInfo(key, wire_coordsUint64stoBytes(coords), false)
 | 
						c.router.nodeinfo.sendNodeInfo(key, wire_coordsUint64stoBytes(coords), false)
 | 
				
			||||||
 | 
						phony.Block(&c.router.nodeinfo, func() {}) // Wait for sendNodeInfo before starting timer
 | 
				
			||||||
	timer := time.AfterFunc(6*time.Second, func() { close(response) })
 | 
						timer := time.AfterFunc(6*time.Second, func() { close(response) })
 | 
				
			||||||
	defer timer.Stop()
 | 
						defer timer.Stop()
 | 
				
			||||||
	for res := range response {
 | 
						for res := range response {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,7 +41,7 @@ type nodeinfoReqRes struct {
 | 
				
			||||||
// Initialises the nodeinfo cache/callback maps, and starts a goroutine to keep
 | 
					// Initialises the nodeinfo cache/callback maps, and starts a goroutine to keep
 | 
				
			||||||
// the cache/callback maps clean of stale entries
 | 
					// the cache/callback maps clean of stale entries
 | 
				
			||||||
func (m *nodeinfo) init(core *Core) {
 | 
					func (m *nodeinfo) init(core *Core) {
 | 
				
			||||||
	m.Act(m, func() {
 | 
						m.Act(nil, func() {
 | 
				
			||||||
		m._init(core)
 | 
							m._init(core)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -66,13 +66,13 @@ func (m *nodeinfo) _cleanup() {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	time.AfterFunc(time.Second*30, func() {
 | 
						time.AfterFunc(time.Second*30, func() {
 | 
				
			||||||
		m.Act(m, m._cleanup)
 | 
							m.Act(nil, m._cleanup)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Add a callback for a nodeinfo lookup
 | 
					// Add a callback for a nodeinfo lookup
 | 
				
			||||||
func (m *nodeinfo) addCallback(sender crypto.BoxPubKey, call func(nodeinfo *NodeInfoPayload)) {
 | 
					func (m *nodeinfo) addCallback(sender crypto.BoxPubKey, call func(nodeinfo *NodeInfoPayload)) {
 | 
				
			||||||
	m.Act(m, func() {
 | 
						m.Act(nil, func() {
 | 
				
			||||||
		m._addCallback(sender, call)
 | 
							m._addCallback(sender, call)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -164,8 +164,8 @@ func (m *nodeinfo) _getCachedNodeInfo(key crypto.BoxPubKey) (NodeInfoPayload, er
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handles a nodeinfo request/response - called from the router
 | 
					// Handles a nodeinfo request/response - called from the router
 | 
				
			||||||
func (m *nodeinfo) handleNodeInfo(nodeinfo *nodeinfoReqRes) {
 | 
					func (m *nodeinfo) handleNodeInfo(from phony.Actor, nodeinfo *nodeinfoReqRes) {
 | 
				
			||||||
	m.Act(m, func() {
 | 
						m.Act(from, func() {
 | 
				
			||||||
		m._handleNodeInfo(nodeinfo)
 | 
							m._handleNodeInfo(nodeinfo)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -181,7 +181,7 @@ func (m *nodeinfo) _handleNodeInfo(nodeinfo *nodeinfoReqRes) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Send nodeinfo request or response - called from the router
 | 
					// Send nodeinfo request or response - called from the router
 | 
				
			||||||
func (m *nodeinfo) sendNodeInfo(key crypto.BoxPubKey, coords []byte, isResponse bool) {
 | 
					func (m *nodeinfo) sendNodeInfo(key crypto.BoxPubKey, coords []byte, isResponse bool) {
 | 
				
			||||||
	m.Act(m, func() {
 | 
						m.Act(nil, func() {
 | 
				
			||||||
		m._sendNodeInfo(key, coords, isResponse)
 | 
							m._sendNodeInfo(key, coords, isResponse)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -250,5 +250,5 @@ func (r *router) _handleNodeInfo(bs []byte, fromKey *crypto.BoxPubKey) {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	req.SendPermPub = *fromKey
 | 
						req.SendPermPub = *fromKey
 | 
				
			||||||
	r.nodeinfo.handleNodeInfo(&req)
 | 
						r.nodeinfo.handleNodeInfo(r, &req)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,10 +24,8 @@ import (
 | 
				
			||||||
// This defines the maximum number of dhtInfo that we keep track of for nodes to query in an ongoing search.
 | 
					// This defines the maximum number of dhtInfo that we keep track of for nodes to query in an ongoing search.
 | 
				
			||||||
const search_MAX_SEARCH_SIZE = 16
 | 
					const search_MAX_SEARCH_SIZE = 16
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This defines the time after which we send a new search packet.
 | 
					// This defines the time after which we time out a search (so it can restart).
 | 
				
			||||||
// Search packets are sent automatically immediately after a response is received.
 | 
					const search_RETRY_TIME = 3 * time.Second
 | 
				
			||||||
// So this allows for timeouts and for long searches to become increasingly parallel.
 | 
					 | 
				
			||||||
const search_RETRY_TIME = time.Second
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Information about an ongoing search.
 | 
					// Information about an ongoing search.
 | 
				
			||||||
// Includes the target NodeID, the bitmask to match it to an IP, and the list of nodes to visit / already visited.
 | 
					// Includes the target NodeID, the bitmask to match it to an IP, and the list of nodes to visit / already visited.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue