From b530916044d4f94e29e44af98686ca403fef8535 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 27 Sep 2018 12:14:55 +0100 Subject: [PATCH] Show information about individual active queues --- src/yggdrasil/admin.go | 10 ++++++++++ src/yggdrasil/switch.go | 2 +- src/yggdrasil/tcp.go | 4 ++-- yggdrasilctl.go | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index d3f088f..29c5b71 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -527,7 +527,17 @@ func (a *admin) getData_getSwitchQueues() admin_nodeInfo { var peerInfos admin_nodeInfo switchTable := a.core.switchTable getSwitchQueues := func() { + queues := make([]map[string]interface{}, 0) + for k, v := range switchTable.queues.bufs { + queue := map[string]interface{}{ + "queue_id": k, + "queue_size": v.size, + "queue_packets": len(v.packets), + } + queues = append(queues, queue) + } peerInfos = admin_nodeInfo{ + {"queues", queues}, {"queues_count", len(switchTable.queues.bufs)}, {"queues_size", switchTable.queues.size}, {"max_queues_count", switchTable.queues.maxbufs}, diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index 883cfe3..9f9c265 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -699,12 +699,12 @@ func (t *switchTable) doWorker() { if t.queues.size > t.queues.maxsize { t.queues.maxsize = t.queues.size } + t.queues.bufs[streamID] = buf if !bufExists { if len(t.queues.bufs) > t.queues.maxbufs { t.queues.maxbufs = len(t.queues.bufs) } } - t.queues.bufs[streamID] = buf t.queues.cleanup(t) } case port := <-t.idleIn: diff --git a/src/yggdrasil/tcp.go b/src/yggdrasil/tcp.go index 8debba7..9e96344 100644 --- a/src/yggdrasil/tcp.go +++ b/src/yggdrasil/tcp.go @@ -162,8 +162,8 @@ func (iface *tcpInterface) call(saddr string, socksaddr *string, sintf string) { if sintf != "" { ief, err := net.InterfaceByName(sintf) if err == nil { - if ief.Flags & net.FlagUp == 0 { - return + if ief.Flags&net.FlagUp == 0 { + return } addrs, err := ief.Addrs() if err == nil { diff --git a/yggdrasilctl.go b/yggdrasilctl.go index 4887174..912f618 100644 --- a/yggdrasilctl.go +++ b/yggdrasilctl.go @@ -197,6 +197,20 @@ func main() { if maxqueuesize, ok := v["max_queues_size"].(float64); ok { fmt.Printf("Maximum queue size: %d\n", uint(maxqueuesize)) } + if queues, ok := v["queues"].([]interface{}); ok { + if len(queues) == 0 { + fmt.Println("No active queues") + return + } else { + fmt.Println("Active queues:") + for k, v := range queues { + fmt.Printf("[%d] - Queue '%v', size: %d, packets: %d\n", k+1, + v.(map[string]interface{})["queue_id"].([]byte), + uint(v.(map[string]interface{})["queue_size"].(float64)), + uint(v.(map[string]interface{})["queue_packets"].(float64))) + } + } + } case "addpeer", "removepeer", "addallowedencryptionpublickey", "removeallowedencryptionpublickey": if _, ok := res["added"]; ok { for _, v := range res["added"].([]interface{}) {