From e99c870d51878878e1de8ed1fac65bd3fafb38d4 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sun, 26 Mar 2023 16:49:40 -0500 Subject: [PATCH] update admin functions and fix core tests --- cmd/genkeys/main.go | 2 -- cmd/yggdrasilctl/main.go | 39 ++++++++++++++++++++++----------------- go.mod | 2 +- go.sum | 4 ++-- src/admin/admin.go | 30 ++++++++++++++++-------------- src/admin/getdht.go | 12 ++++++++---- src/admin/getpaths.go | 4 ++++ src/core/api.go | 16 ++++++++++++---- src/core/core_test.go | 2 +- 9 files changed, 66 insertions(+), 45 deletions(-) diff --git a/cmd/genkeys/main.go b/cmd/genkeys/main.go index 8194244..a12d303 100644 --- a/cmd/genkeys/main.go +++ b/cmd/genkeys/main.go @@ -1,5 +1,4 @@ /* - This file generates crypto keys. It prints out a new set of keys each time if finds a "better" one. By default, "better" means a higher NodeID (-> higher IP address). @@ -8,7 +7,6 @@ This is because the IP address format can compress leading 1s in the address, to If run with the "-sig" flag, it generates signing keys instead. A "better" signing key means one with a higher TreeID. This only matters if it's high enough to make you the root of the tree. - */ package main diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go index 6aed8ac..656df8c 100644 --- a/cmd/yggdrasilctl/main.go +++ b/cmd/yggdrasilctl/main.go @@ -194,31 +194,36 @@ func run() int { if err := json.Unmarshal(recv.Response, &resp); err != nil { panic(err) } - table.SetHeader([]string{"Public Key", "IP Address", "Port", "Rest"}) + //table.SetHeader([]string{"Public Key", "IP Address", "Port", "Rest"}) + table.SetHeader([]string{"Public Key", "IP Address", "Parent", "Sequence"}) for _, dht := range resp.DHT { table.Append([]string{ dht.PublicKey, dht.IPAddress, - fmt.Sprintf("%d", dht.Port), - fmt.Sprintf("%d", dht.Rest), + dht.Parent, + fmt.Sprintf("%d", dht.Sequence), + //fmt.Sprintf("%d", dht.Port), + //fmt.Sprintf("%d", dht.Rest), }) } table.Render() - case "getpaths": - var resp admin.GetPathsResponse - if err := json.Unmarshal(recv.Response, &resp); err != nil { - panic(err) - } - table.SetHeader([]string{"Public Key", "IP Address", "Seq"}) - for _, p := range resp.Paths { - table.Append([]string{ - p.PublicKey, - p.IPAddress, - fmt.Sprintf("%d", p.Sequence), - }) - } - table.Render() + /* + case "getpaths": + var resp admin.GetPathsResponse + if err := json.Unmarshal(recv.Response, &resp); err != nil { + panic(err) + } + table.SetHeader([]string{"Public Key", "IP Address", "Seq"}) + for _, p := range resp.Paths { + table.Append([]string{ + p.PublicKey, + p.IPAddress, + fmt.Sprintf("%d", p.Sequence), + }) + } + table.Render() + */ case "getsessions": var resp admin.GetSessionsResponse diff --git a/go.mod b/go.mod index f94b521..19b7bf9 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/yggdrasil-network/yggdrasil-go go 1.17 -replace github.com/Arceliar/ironwood => github.com/Arceliar/ironwood v0.0.0-20230326182230-e1880a231350 +replace github.com/Arceliar/ironwood => github.com/Arceliar/ironwood v0.0.0-20230326213941-b977dd93b701 require ( github.com/Arceliar/ironwood v0.0.0-20230318003210-65aa386cab13 diff --git a/go.sum b/go.sum index cbe8346..e27fb20 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/Arceliar/ironwood v0.0.0-20230326182230-e1880a231350 h1:9dsw9bwJKfwC/bohTvFsob7h4YeZkBI14eDtbY4WtTg= -github.com/Arceliar/ironwood v0.0.0-20230326182230-e1880a231350/go.mod h1:PhT70gxs32jSoxpi5gLlvCguWTzbpaqnNRTY6GgFPBY= +github.com/Arceliar/ironwood v0.0.0-20230326213941-b977dd93b701 h1:Cce66vRcL0hjO/wVqBU22d2r/J5+61N/aMzfPizMS5E= +github.com/Arceliar/ironwood v0.0.0-20230326213941-b977dd93b701/go.mod h1:PhT70gxs32jSoxpi5gLlvCguWTzbpaqnNRTY6GgFPBY= github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d h1:UK9fsWbWqwIQkMCz1CP+v5pGbsGoWAw6g4AyvMpm1EM= github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d/go.mod h1:BCnxhRf47C/dy/e/D2pmB8NkB3dQVIrkD98b220rx5Q= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= diff --git a/src/admin/admin.go b/src/admin/admin.go index 9dbcfdc..be4482f 100644 --- a/src/admin/admin.go +++ b/src/admin/admin.go @@ -145,20 +145,22 @@ func (a *AdminSocket) SetupAdminHandlers() { return res, nil }, ) - _ = a.AddHandler( - "getPaths", "Show established paths through this node", []string{}, - func(in json.RawMessage) (interface{}, error) { - req := &GetPathsRequest{} - res := &GetPathsResponse{} - if err := json.Unmarshal(in, &req); err != nil { - return nil, err - } - if err := a.getPathsHandler(req, res); err != nil { - return nil, err - } - return res, nil - }, - ) + /* + _ = a.AddHandler( + "getPaths", "Show established paths through this node", []string{}, + func(in json.RawMessage) (interface{}, error) { + req := &GetPathsRequest{} + res := &GetPathsResponse{} + if err := json.Unmarshal(in, &req); err != nil { + return nil, err + } + if err := a.getPathsHandler(req, res); err != nil { + return nil, err + } + return res, nil + }, + ) + */ _ = a.AddHandler( "getSessions", "Show established traffic sessions with remote nodes", []string{}, func(in json.RawMessage) (interface{}, error) { diff --git a/src/admin/getdht.go b/src/admin/getdht.go index bfb2181..acddad7 100644 --- a/src/admin/getdht.go +++ b/src/admin/getdht.go @@ -18,8 +18,10 @@ type GetDHTResponse struct { type DHTEntry struct { IPAddress string `json:"address"` PublicKey string `json:"key"` - Port uint64 `json:"port"` - Rest uint64 `json:"rest"` + Parent string `json:"parent"` + Sequence uint64 `json:"sequence"` + //Port uint64 `json:"port"` + //Rest uint64 `json:"rest"` } func (a *AdminSocket) getDHTHandler(req *GetDHTRequest, res *GetDHTResponse) error { @@ -30,8 +32,10 @@ func (a *AdminSocket) getDHTHandler(req *GetDHTRequest, res *GetDHTResponse) err res.DHT = append(res.DHT, DHTEntry{ IPAddress: net.IP(addr[:]).String(), PublicKey: hex.EncodeToString(d.Key[:]), - Port: d.Port, - Rest: d.Rest, + Parent: hex.EncodeToString(d.Parent[:]), + Sequence: d.Sequence, + //Port: d.Port, + //Rest: d.Rest, }) } sort.SliceStable(res.DHT, func(i, j int) bool { diff --git a/src/admin/getpaths.go b/src/admin/getpaths.go index 2d5db0f..94a9945 100644 --- a/src/admin/getpaths.go +++ b/src/admin/getpaths.go @@ -1,5 +1,7 @@ package admin +/* + import ( "encoding/hex" "net" @@ -38,3 +40,5 @@ func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsRespons }) return nil } + +*/ diff --git a/src/core/api.go b/src/core/api.go index c617a20..da4ead5 100644 --- a/src/core/api.go +++ b/src/core/api.go @@ -31,15 +31,19 @@ type PeerInfo struct { } type DHTEntryInfo struct { - Key ed25519.PublicKey - Port uint64 - Rest uint64 + Key ed25519.PublicKey + Parent ed25519.PublicKey + Sequence uint64 + //Port uint64 + //Rest uint64 } +/* type PathEntryInfo struct { Key ed25519.PublicKey Sequence uint64 } +*/ type SessionInfo struct { Key ed25519.PublicKey @@ -96,13 +100,16 @@ func (c *Core) GetDHT() []DHTEntryInfo { for _, d := range ds { var info DHTEntryInfo info.Key = d.Key - info.Port = d.Port + info.Parent = d.Parent + info.Sequence = d.Sequence + //info.Port = d.Port //info.Rest = d.Rest dhts = append(dhts, info) } return dhts } +/* func (c *Core) GetPaths() []PathEntryInfo { var paths []PathEntryInfo ps := c.PacketConn.PacketConn.Debug.GetPaths() @@ -115,6 +122,7 @@ func (c *Core) GetPaths() []PathEntryInfo { } return paths } +*/ func (c *Core) GetSessions() []SessionInfo { var sessions []SessionInfo diff --git a/src/core/core_test.go b/src/core/core_test.go index 669ed17..f917030 100644 --- a/src/core/core_test.go +++ b/src/core/core_test.go @@ -75,7 +75,7 @@ func WaitConnected(nodeA, nodeB *Core) bool { return true } */ - if len(nodeA.GetPaths()) > 1 && len(nodeB.GetPaths()) > 1 { + if len(nodeA.GetDHT()) > 1 && len(nodeB.GetDHT()) > 1 { return true } }