mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-22 22:15:46 +00:00
Identify switchport for queue based on coords in stream ID
This commit is contained in:
parent
8113b4cc22
commit
0b1a6611fd
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)))
|
||||
|
Loading…
Reference in New Issue
Block a user