mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-27 03:55:18 +00:00
Add the ability to see switch ports and DHT
This commit is contained in:
parent
b754d68068
commit
c4ac0a90ac
@ -6,6 +6,8 @@ import "bytes"
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// TODO: Make all of this JSON
|
// TODO: Make all of this JSON
|
||||||
|
// TODO: Add authentication
|
||||||
|
// TODO: Is any of this thread safe?
|
||||||
|
|
||||||
type admin struct {
|
type admin struct {
|
||||||
core *Core
|
core *Core
|
||||||
@ -44,10 +46,34 @@ func (a *admin) handleRequest(conn net.Conn) {
|
|||||||
}
|
}
|
||||||
buf = bytes.Trim(buf, "\x00\r\n\t")
|
buf = bytes.Trim(buf, "\x00\r\n\t")
|
||||||
switch string(buf) {
|
switch string(buf) {
|
||||||
case "ports":
|
case "switch table":
|
||||||
ports := a.core.peers.getPorts()
|
table := a.core.switchTable.table.Load().(lookupTable)
|
||||||
for _, v := range ports {
|
conn.Write([]byte(fmt.Sprintf(
|
||||||
conn.Write([]byte(fmt.Sprintf("Found switch port %d\n", v.port)))
|
"port 0 -> %+v\n",
|
||||||
|
table.self.coords)))
|
||||||
|
for _, v := range table.elems {
|
||||||
|
conn.Write([]byte(fmt.Sprintf(
|
||||||
|
"port %d -> %+v\n",
|
||||||
|
v.port,
|
||||||
|
v.locator.coords)))
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case "dht":
|
||||||
|
n := a.core.dht.nBuckets()
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
b := a.core.dht.getBucket(i)
|
||||||
|
if len(b.infos) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, v := range b.infos {
|
||||||
|
addr := address_addrForNodeID(v.nodeID_hidden)
|
||||||
|
ip := net.IP(addr[:]).String()
|
||||||
|
|
||||||
|
conn.Write([]byte(fmt.Sprintf("%+v -> %+v\n",
|
||||||
|
ip,
|
||||||
|
v.coords)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ func generateConfig() *nodeConfig {
|
|||||||
spub, spriv := core.DEBUG_newSigKeys()
|
spub, spriv := core.DEBUG_newSigKeys()
|
||||||
cfg := nodeConfig{}
|
cfg := nodeConfig{}
|
||||||
cfg.Listen = "[::]:0"
|
cfg.Listen = "[::]:0"
|
||||||
cfg.AdminListen = "[::]:0"
|
cfg.AdminListen = "[::1]:9001"
|
||||||
cfg.BoxPub = hex.EncodeToString(bpub[:])
|
cfg.BoxPub = hex.EncodeToString(bpub[:])
|
||||||
cfg.BoxPriv = hex.EncodeToString(bpriv[:])
|
cfg.BoxPriv = hex.EncodeToString(bpriv[:])
|
||||||
cfg.SigPub = hex.EncodeToString(spub[:])
|
cfg.SigPub = hex.EncodeToString(spub[:])
|
||||||
|
Loading…
Reference in New Issue
Block a user