mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Implement GetDHT, GetSwitchQueues, GetSessions
This commit is contained in:
		
							parent
							
								
									8a6f6f3b2b
								
							
						
					
					
						commit
						7ca5a2533d
					
				
					 1 changed files with 100 additions and 78 deletions
				
			
		| 
						 | 
				
			
			@ -38,14 +38,44 @@ type SwitchPeer struct {
 | 
			
		|||
	Protocol   string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DHTEntry represents a single DHT entry that has been learned or cached from
 | 
			
		||||
// DHT searches.
 | 
			
		||||
type DHTEntry struct {
 | 
			
		||||
	PublicKey crypto.BoxPubKey
 | 
			
		||||
	Coords    []byte
 | 
			
		||||
	LastSeen  time.Duration
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type SwitchQueue struct{}
 | 
			
		||||
type Session struct{}
 | 
			
		||||
// SwitchQueues represents information from the switch related to link
 | 
			
		||||
// congestion and a list of switch queues created in response to congestion on a
 | 
			
		||||
// given link.
 | 
			
		||||
type SwitchQueues struct {
 | 
			
		||||
	Queues       []SwitchQueue
 | 
			
		||||
	Count        uint64
 | 
			
		||||
	Size         uint64
 | 
			
		||||
	HighestCount uint64
 | 
			
		||||
	HighestSize  uint64
 | 
			
		||||
	MaximumSize  uint64
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SwitchQueue represents a single switch queue, which is created in response
 | 
			
		||||
// to congestion on a given link.
 | 
			
		||||
type SwitchQueue struct {
 | 
			
		||||
	ID      string
 | 
			
		||||
	Size    uint64
 | 
			
		||||
	Packets uint64
 | 
			
		||||
	Port    uint64
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Session represents an open session with another node.
 | 
			
		||||
type Session struct {
 | 
			
		||||
	PublicKey   crypto.BoxPubKey
 | 
			
		||||
	Coords      []byte
 | 
			
		||||
	BytesSent   uint64
 | 
			
		||||
	BytesRecvd  uint64
 | 
			
		||||
	MTU         uint16
 | 
			
		||||
	WasMTUFixed bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetPeers returns one or more Peer objects containing information about active
 | 
			
		||||
// peerings with other Yggdrasil nodes, where one of the responses always
 | 
			
		||||
| 
						 | 
				
			
			@ -104,88 +134,80 @@ func (c *Core) GetSwitchPeers() []SwitchPeer {
 | 
			
		|||
	return switchpeers
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetDHT returns zero or more entries as stored in the DHT, cached primarily
 | 
			
		||||
// from searches that have already taken place.
 | 
			
		||||
func (c *Core) GetDHT() []DHTEntry {
 | 
			
		||||
	/*
 | 
			
		||||
	  var infos []admin_nodeInfo
 | 
			
		||||
	var dhtentries []DHTEntry
 | 
			
		||||
	getDHT := func() {
 | 
			
		||||
		now := time.Now()
 | 
			
		||||
	    var dhtInfos []*dhtInfo
 | 
			
		||||
	    for _, v := range a.core.dht.table {
 | 
			
		||||
	      dhtInfos = append(dhtInfos, v)
 | 
			
		||||
		var dhtentry []*dhtInfo
 | 
			
		||||
		for _, v := range c.dht.table {
 | 
			
		||||
			dhtentry = append(dhtentry, v)
 | 
			
		||||
		}
 | 
			
		||||
	    sort.SliceStable(dhtInfos, func(i, j int) bool {
 | 
			
		||||
	      return dht_ordered(&a.core.dht.nodeID, dhtInfos[i].getNodeID(), dhtInfos[j].getNodeID())
 | 
			
		||||
		sort.SliceStable(dhtentry, func(i, j int) bool {
 | 
			
		||||
			return dht_ordered(&c.dht.nodeID, dhtentry[i].getNodeID(), dhtentry[j].getNodeID())
 | 
			
		||||
		})
 | 
			
		||||
	    for _, v := range dhtInfos {
 | 
			
		||||
	      addr := *address.AddrForNodeID(v.getNodeID())
 | 
			
		||||
	      info := admin_nodeInfo{
 | 
			
		||||
	        {"ip", net.IP(addr[:]).String()},
 | 
			
		||||
	        {"coords", fmt.Sprint(v.coords)},
 | 
			
		||||
	        {"last_seen", int(now.Sub(v.recv).Seconds())},
 | 
			
		||||
	        {"box_pub_key", hex.EncodeToString(v.key[:])},
 | 
			
		||||
		for _, v := range dhtentry {
 | 
			
		||||
			info := DHTEntry{
 | 
			
		||||
				Coords:   v.coords,
 | 
			
		||||
				LastSeen: now.Sub(v.recv),
 | 
			
		||||
			}
 | 
			
		||||
	      infos = append(infos, info)
 | 
			
		||||
			copy(info.PublicKey[:], v.key[:])
 | 
			
		||||
			dhtentries = append(dhtentries, info)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	  a.core.router.doAdmin(getDHT)
 | 
			
		||||
	  return infos
 | 
			
		||||
	*/
 | 
			
		||||
	return []DHTEntry{}
 | 
			
		||||
	c.router.doAdmin(getDHT)
 | 
			
		||||
	return dhtentries
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Core) GetSwitchQueues() []SwitchQueue {
 | 
			
		||||
	/*
 | 
			
		||||
	  var peerInfos admin_nodeInfo
 | 
			
		||||
	  switchTable := &a.core.switchTable
 | 
			
		||||
// GetSwitchQueues returns information about the switch queues that are
 | 
			
		||||
// currently in effect. These values can change within an instant.
 | 
			
		||||
func (c *Core) GetSwitchQueues() SwitchQueues {
 | 
			
		||||
	var switchqueues SwitchQueues
 | 
			
		||||
	switchTable := &c.switchTable
 | 
			
		||||
	getSwitchQueues := func() {
 | 
			
		||||
	    queues := make([]map[string]interface{}, 0)
 | 
			
		||||
		switchqueues = SwitchQueues{
 | 
			
		||||
			Count:        uint64(len(switchTable.queues.bufs)),
 | 
			
		||||
			Size:         switchTable.queues.size,
 | 
			
		||||
			HighestCount: uint64(switchTable.queues.maxbufs),
 | 
			
		||||
			HighestSize:  switchTable.queues.maxsize,
 | 
			
		||||
			MaximumSize:  switchTable.queueTotalMaxSize,
 | 
			
		||||
		}
 | 
			
		||||
		for k, v := range switchTable.queues.bufs {
 | 
			
		||||
			nexthop := switchTable.bestPortForCoords([]byte(k))
 | 
			
		||||
	      queue := map[string]interface{}{
 | 
			
		||||
	        "queue_id":      k,
 | 
			
		||||
	        "queue_size":    v.size,
 | 
			
		||||
	        "queue_packets": len(v.packets),
 | 
			
		||||
	        "queue_port":    nexthop,
 | 
			
		||||
			queue := SwitchQueue{
 | 
			
		||||
				ID:      k,
 | 
			
		||||
				Size:    v.size,
 | 
			
		||||
				Packets: uint64(len(v.packets)),
 | 
			
		||||
				Port:    uint64(nexthop),
 | 
			
		||||
			}
 | 
			
		||||
	      queues = append(queues, queue)
 | 
			
		||||
			switchqueues.Queues = append(switchqueues.Queues, queue)
 | 
			
		||||
		}
 | 
			
		||||
	    peerInfos = admin_nodeInfo{
 | 
			
		||||
	      {"queues", queues},
 | 
			
		||||
	      {"queues_count", len(switchTable.queues.bufs)},
 | 
			
		||||
	      {"queues_size", switchTable.queues.size},
 | 
			
		||||
	      {"highest_queues_count", switchTable.queues.maxbufs},
 | 
			
		||||
	      {"highest_queues_size", switchTable.queues.maxsize},
 | 
			
		||||
	      {"maximum_queues_size", switchTable.queueTotalMaxSize},
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
	  }
 | 
			
		||||
	  a.core.switchTable.doAdmin(getSwitchQueues)
 | 
			
		||||
	  return peerInfos
 | 
			
		||||
	*/
 | 
			
		||||
	return []SwitchQueue{}
 | 
			
		||||
	c.switchTable.doAdmin(getSwitchQueues)
 | 
			
		||||
	return switchqueues
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetSessions returns a list of open sessions from this node to other nodes.
 | 
			
		||||
func (c *Core) GetSessions() []Session {
 | 
			
		||||
	/*
 | 
			
		||||
	  var infos []admin_nodeInfo
 | 
			
		||||
	var sessions []Session
 | 
			
		||||
	getSessions := func() {
 | 
			
		||||
	    for _, sinfo := range a.core.sessions.sinfos {
 | 
			
		||||
		for _, sinfo := range c.sessions.sinfos {
 | 
			
		||||
			// TODO? skipped known but timed out sessions?
 | 
			
		||||
	      info := admin_nodeInfo{
 | 
			
		||||
	        {"ip", net.IP(sinfo.theirAddr[:]).String()},
 | 
			
		||||
	        {"coords", fmt.Sprint(sinfo.coords)},
 | 
			
		||||
	        {"mtu", sinfo.getMTU()},
 | 
			
		||||
	        {"was_mtu_fixed", sinfo.wasMTUFixed},
 | 
			
		||||
	        {"bytes_sent", sinfo.bytesSent},
 | 
			
		||||
	        {"bytes_recvd", sinfo.bytesRecvd},
 | 
			
		||||
	        {"box_pub_key", hex.EncodeToString(sinfo.theirPermPub[:])},
 | 
			
		||||
			session := Session{
 | 
			
		||||
				Coords:      sinfo.coords,
 | 
			
		||||
				MTU:         sinfo.getMTU(),
 | 
			
		||||
				BytesSent:   sinfo.bytesSent,
 | 
			
		||||
				BytesRecvd:  sinfo.bytesRecvd,
 | 
			
		||||
				WasMTUFixed: sinfo.wasMTUFixed,
 | 
			
		||||
			}
 | 
			
		||||
	      infos = append(infos, info)
 | 
			
		||||
			copy(session.PublicKey[:], sinfo.theirPermPub[:])
 | 
			
		||||
			sessions = append(sessions, session)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	  a.core.router.doAdmin(getSessions)
 | 
			
		||||
	  return infos
 | 
			
		||||
	*/
 | 
			
		||||
	return []Session{}
 | 
			
		||||
	c.router.doAdmin(getSessions)
 | 
			
		||||
	return sessions
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// BuildName gets the current build name. This is usually injected if built
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue