5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-13 01:40:27 +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 dhtentry []*dhtInfo
var dhtInfos []*dhtInfo for _, v := range c.dht.table {
for _, v := range a.core.dht.table { dhtentry = append(dhtentry, v)
dhtInfos = append(dhtInfos, v) }
} sort.SliceStable(dhtentry, func(i, j int) bool {
sort.SliceStable(dhtInfos, func(i, j int) bool { return dht_ordered(&c.dht.nodeID, dhtentry[i].getNodeID(), dhtentry[j].getNodeID())
return dht_ordered(&a.core.dht.nodeID, dhtInfos[i].getNodeID(), dhtInfos[j].getNodeID()) })
}) for _, v := range dhtentry {
for _, v := range dhtInfos { info := DHTEntry{
addr := *address.AddrForNodeID(v.getNodeID()) Coords: v.coords,
info := admin_nodeInfo{ LastSeen: now.Sub(v.recv),
{"ip", net.IP(addr[:]).String()}, }
{"coords", fmt.Sprint(v.coords)}, copy(info.PublicKey[:], v.key[:])
{"last_seen", int(now.Sub(v.recv).Seconds())}, dhtentries = append(dhtentries, info)
{"box_pub_key", hex.EncodeToString(v.key[:])}, }
} }
infos = append(infos, info) c.router.doAdmin(getDHT)
} return dhtentries
}
a.core.router.doAdmin(getDHT)
return infos
*/
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
getSwitchQueues := func() { switchTable := &c.switchTable
queues := make([]map[string]interface{}, 0) getSwitchQueues := func() {
for k, v := range switchTable.queues.bufs { switchqueues = SwitchQueues{
nexthop := switchTable.bestPortForCoords([]byte(k)) Count: uint64(len(switchTable.queues.bufs)),
queue := map[string]interface{}{ Size: switchTable.queues.size,
"queue_id": k, HighestCount: uint64(switchTable.queues.maxbufs),
"queue_size": v.size, HighestSize: switchTable.queues.maxsize,
"queue_packets": len(v.packets), MaximumSize: switchTable.queueTotalMaxSize,
"queue_port": nexthop, }
} for k, v := range switchTable.queues.bufs {
queues = append(queues, queue) nexthop := switchTable.bestPortForCoords([]byte(k))
} queue := SwitchQueue{
peerInfos = admin_nodeInfo{ ID: k,
{"queues", queues}, Size: v.size,
{"queues_count", len(switchTable.queues.bufs)}, Packets: uint64(len(v.packets)),
{"queues_size", switchTable.queues.size}, Port: uint64(nexthop),
{"highest_queues_count", switchTable.queues.maxbufs}, }
{"highest_queues_size", switchTable.queues.maxsize}, switchqueues.Queues = append(switchqueues.Queues, queue)
{"maximum_queues_size", switchTable.queueTotalMaxSize}, }
}
} }
a.core.switchTable.doAdmin(getSwitchQueues) c.switchTable.doAdmin(getSwitchQueues)
return peerInfos return switchqueues
*/
return []SwitchQueue{}
} }
// 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 c.sessions.sinfos {
for _, sinfo := range a.core.sessions.sinfos { // TODO? skipped known but timed out sessions?
// TODO? skipped known but timed out sessions? session := Session{
info := admin_nodeInfo{ Coords: sinfo.coords,
{"ip", net.IP(sinfo.theirAddr[:]).String()}, MTU: sinfo.getMTU(),
{"coords", fmt.Sprint(sinfo.coords)}, BytesSent: sinfo.bytesSent,
{"mtu", sinfo.getMTU()}, BytesRecvd: sinfo.bytesRecvd,
{"was_mtu_fixed", sinfo.wasMTUFixed}, WasMTUFixed: sinfo.wasMTUFixed,
{"bytes_sent", sinfo.bytesSent}, }
{"bytes_recvd", sinfo.bytesRecvd}, copy(session.PublicKey[:], sinfo.theirPermPub[:])
{"box_pub_key", hex.EncodeToString(sinfo.theirPermPub[:])}, sessions = append(sessions, session)
} }
infos = append(infos, info) }
} c.router.doAdmin(getSessions)
} return sessions
a.core.router.doAdmin(getSessions)
return infos
*/
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