From 0b1a6611fd3524591479e405ab86decec47147f9 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 27 Sep 2018 15:05:45 +0100 Subject: [PATCH] Identify switchport for queue based on coords in stream ID --- src/yggdrasil/admin.go | 2 ++ src/yggdrasil/switch.go | 16 ++++++++++++++++ yggdrasilctl.go | 3 ++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index 63db1a72..26a706b2 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -529,10 +529,12 @@ func (a *admin) getData_getSwitchQueues() admin_nodeInfo { getSwitchQueues := func() { queues := make([]map[string]interface{}, 0) 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, } queues = append(queues, queue) } diff --git a/src/yggdrasil/switch.go b/src/yggdrasil/switch.go index 8ec06ca1..9f786a61 100644 --- a/src/yggdrasil/switch.go +++ b/src/yggdrasil/switch.go @@ -541,6 +541,22 @@ func switch_getPacketStreamID(packet []byte) string { return string(switch_getPacketCoords(packet)) } +// Find the best port for a given set of coords +func (t *switchTable) bestPortForCoords(coords []byte) switchPort { + table := t.getTable() + var best switchPort + bestDist := table.self.dist(coords) + for to, elem := range table.elems { + dist := elem.locator.dist(coords) + if !(dist < bestDist) { + continue + } + best = to + bestDist = dist + } + return best +} + // Handle an incoming packet // Either send it to ourself, or to the first idle peer that's free // Returns true if the packet has been handled somehow, false if it should be queued diff --git a/yggdrasilctl.go b/yggdrasilctl.go index d04f7cd3..e0caf591 100644 --- a/yggdrasilctl.go +++ b/yggdrasilctl.go @@ -204,7 +204,8 @@ func main() { } else { fmt.Println("Active queues:") for _, v := range queues { - fmt.Printf("- Stream ID: %v, size: %d, packets: %d\n", + fmt.Printf("- Switch port %d, Stream ID: %v, size: %d, packets: %d\n", + uint(v.(map[string]interface{})["queue_port"].(float64)), []byte(v.(map[string]interface{})["queue_id"].(string)), uint(v.(map[string]interface{})["queue_size"].(float64)), uint(v.(map[string]interface{})["queue_packets"].(float64)))