5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-14 04:30:32 +00:00

Implement GetDHT, GetSwitchQueues, GetSessions

This commit is contained in:
Neil Alexander 2019-05-19 16:29:04 +01:00
parent 8a6f6f3b2b
commit 7ca5a2533d
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -38,14 +38,44 @@ type SwitchPeer struct {
Protocol string Protocol string
} }
// DHTEntry represents a single DHT entry that has been learned or cached from
// DHT searches.
type DHTEntry struct { type DHTEntry struct {
PublicKey crypto.BoxPubKey PublicKey crypto.BoxPubKey
Coords []byte Coords []byte
LastSeen time.Duration LastSeen time.Duration
} }
type SwitchQueue struct{} // SwitchQueues represents information from the switch related to link
type Session struct{} // 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 // GetPeers returns one or more Peer objects containing information about active
// peerings with other Yggdrasil nodes, where one of the responses always // peerings with other Yggdrasil nodes, where one of the responses always
@ -104,88 +134,80 @@ func (c *Core) GetSwitchPeers() []SwitchPeer {
return switchpeers 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 { func (c *Core) GetDHT() []DHTEntry {
/* var dhtentries []DHTEntry
var infos []admin_nodeInfo
getDHT := func() { getDHT := func() {
now := time.Now() now := time.Now()
var dhtInfos []*dhtInfo var dhtentry []*dhtInfo
for _, v := range a.core.dht.table { for _, v := range c.dht.table {
dhtInfos = append(dhtInfos, v) dhtentry = append(dhtentry, v)
} }
sort.SliceStable(dhtInfos, func(i, j int) bool { sort.SliceStable(dhtentry, func(i, j int) bool {
return dht_ordered(&a.core.dht.nodeID, dhtInfos[i].getNodeID(), dhtInfos[j].getNodeID()) return dht_ordered(&c.dht.nodeID, dhtentry[i].getNodeID(), dhtentry[j].getNodeID())
}) })
for _, v := range dhtInfos { for _, v := range dhtentry {
addr := *address.AddrForNodeID(v.getNodeID()) info := DHTEntry{
info := admin_nodeInfo{ Coords: v.coords,
{"ip", net.IP(addr[:]).String()}, LastSeen: now.Sub(v.recv),
{"coords", fmt.Sprint(v.coords)},
{"last_seen", int(now.Sub(v.recv).Seconds())},
{"box_pub_key", hex.EncodeToString(v.key[:])},
} }
infos = append(infos, info) copy(info.PublicKey[:], v.key[:])
dhtentries = append(dhtentries, info)
} }
} }
a.core.router.doAdmin(getDHT) c.router.doAdmin(getDHT)
return infos return dhtentries
*/
return []DHTEntry{}
} }
func (c *Core) GetSwitchQueues() []SwitchQueue { // GetSwitchQueues returns information about the switch queues that are
/* // currently in effect. These values can change within an instant.
var peerInfos admin_nodeInfo func (c *Core) GetSwitchQueues() SwitchQueues {
switchTable := &a.core.switchTable var switchqueues SwitchQueues
switchTable := &c.switchTable
getSwitchQueues := func() { 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 { for k, v := range switchTable.queues.bufs {
nexthop := switchTable.bestPortForCoords([]byte(k)) nexthop := switchTable.bestPortForCoords([]byte(k))
queue := map[string]interface{}{ queue := SwitchQueue{
"queue_id": k, ID: k,
"queue_size": v.size, Size: v.size,
"queue_packets": len(v.packets), Packets: uint64(len(v.packets)),
"queue_port": nexthop, 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 { func (c *Core) GetSessions() []Session {
/* var sessions []Session
var infos []admin_nodeInfo
getSessions := func() { getSessions := func() {
for _, sinfo := range a.core.sessions.sinfos { for _, sinfo := range c.sessions.sinfos {
// TODO? skipped known but timed out sessions? // TODO? skipped known but timed out sessions?
info := admin_nodeInfo{ session := Session{
{"ip", net.IP(sinfo.theirAddr[:]).String()}, Coords: sinfo.coords,
{"coords", fmt.Sprint(sinfo.coords)}, MTU: sinfo.getMTU(),
{"mtu", sinfo.getMTU()}, BytesSent: sinfo.bytesSent,
{"was_mtu_fixed", sinfo.wasMTUFixed}, BytesRecvd: sinfo.bytesRecvd,
{"bytes_sent", sinfo.bytesSent}, WasMTUFixed: sinfo.wasMTUFixed,
{"bytes_recvd", sinfo.bytesRecvd},
{"box_pub_key", hex.EncodeToString(sinfo.theirPermPub[:])},
} }
infos = append(infos, info) copy(session.PublicKey[:], sinfo.theirPermPub[:])
sessions = append(sessions, session)
} }
} }
a.core.router.doAdmin(getSessions) c.router.doAdmin(getSessions)
return infos return sessions
*/
return []Session{}
} }
// BuildName gets the current build name. This is usually injected if built // BuildName gets the current build name. This is usually injected if built