update admin functions and fix core tests

This commit is contained in:
Arceliar 2023-03-26 16:49:40 -05:00
parent abbe94fa80
commit e99c870d51
9 changed files with 66 additions and 45 deletions

View file

@ -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) {

View file

@ -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 {

View file

@ -1,5 +1,7 @@
package admin
/*
import (
"encoding/hex"
"net"
@ -38,3 +40,5 @@ func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsRespons
})
return nil
}
*/

View file

@ -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

View file

@ -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
}
}