mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-22 23:25:39 +00:00
update admin functions and fix core tests
This commit is contained in:
parent
abbe94fa80
commit
e99c870d51
@ -1,5 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
This file generates crypto keys.
|
This file generates crypto keys.
|
||||||
It prints out a new set of keys each time if finds a "better" one.
|
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).
|
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.
|
If run with the "-sig" flag, it generates signing keys instead.
|
||||||
A "better" signing key means one with a higher TreeID.
|
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.
|
This only matters if it's high enough to make you the root of the tree.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
@ -194,17 +194,21 @@ func run() int {
|
|||||||
if err := json.Unmarshal(recv.Response, &resp); err != nil {
|
if err := json.Unmarshal(recv.Response, &resp); err != nil {
|
||||||
panic(err)
|
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 {
|
for _, dht := range resp.DHT {
|
||||||
table.Append([]string{
|
table.Append([]string{
|
||||||
dht.PublicKey,
|
dht.PublicKey,
|
||||||
dht.IPAddress,
|
dht.IPAddress,
|
||||||
fmt.Sprintf("%d", dht.Port),
|
dht.Parent,
|
||||||
fmt.Sprintf("%d", dht.Rest),
|
fmt.Sprintf("%d", dht.Sequence),
|
||||||
|
//fmt.Sprintf("%d", dht.Port),
|
||||||
|
//fmt.Sprintf("%d", dht.Rest),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
table.Render()
|
table.Render()
|
||||||
|
|
||||||
|
/*
|
||||||
case "getpaths":
|
case "getpaths":
|
||||||
var resp admin.GetPathsResponse
|
var resp admin.GetPathsResponse
|
||||||
if err := json.Unmarshal(recv.Response, &resp); err != nil {
|
if err := json.Unmarshal(recv.Response, &resp); err != nil {
|
||||||
@ -219,6 +223,7 @@ func run() int {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
table.Render()
|
table.Render()
|
||||||
|
*/
|
||||||
|
|
||||||
case "getsessions":
|
case "getsessions":
|
||||||
var resp admin.GetSessionsResponse
|
var resp admin.GetSessionsResponse
|
||||||
|
2
go.mod
2
go.mod
@ -2,7 +2,7 @@ module github.com/yggdrasil-network/yggdrasil-go
|
|||||||
|
|
||||||
go 1.17
|
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 (
|
require (
|
||||||
github.com/Arceliar/ironwood v0.0.0-20230318003210-65aa386cab13
|
github.com/Arceliar/ironwood v0.0.0-20230318003210-65aa386cab13
|
||||||
|
4
go.sum
4
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-20230326213941-b977dd93b701 h1:Cce66vRcL0hjO/wVqBU22d2r/J5+61N/aMzfPizMS5E=
|
||||||
github.com/Arceliar/ironwood v0.0.0-20230326182230-e1880a231350/go.mod h1:PhT70gxs32jSoxpi5gLlvCguWTzbpaqnNRTY6GgFPBY=
|
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 h1:UK9fsWbWqwIQkMCz1CP+v5pGbsGoWAw6g4AyvMpm1EM=
|
||||||
github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d/go.mod h1:BCnxhRf47C/dy/e/D2pmB8NkB3dQVIrkD98b220rx5Q=
|
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=
|
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||||
|
@ -145,6 +145,7 @@ func (a *AdminSocket) SetupAdminHandlers() {
|
|||||||
return res, nil
|
return res, nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
/*
|
||||||
_ = a.AddHandler(
|
_ = a.AddHandler(
|
||||||
"getPaths", "Show established paths through this node", []string{},
|
"getPaths", "Show established paths through this node", []string{},
|
||||||
func(in json.RawMessage) (interface{}, error) {
|
func(in json.RawMessage) (interface{}, error) {
|
||||||
@ -159,6 +160,7 @@ func (a *AdminSocket) SetupAdminHandlers() {
|
|||||||
return res, nil
|
return res, nil
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
*/
|
||||||
_ = a.AddHandler(
|
_ = a.AddHandler(
|
||||||
"getSessions", "Show established traffic sessions with remote nodes", []string{},
|
"getSessions", "Show established traffic sessions with remote nodes", []string{},
|
||||||
func(in json.RawMessage) (interface{}, error) {
|
func(in json.RawMessage) (interface{}, error) {
|
||||||
|
@ -18,8 +18,10 @@ type GetDHTResponse struct {
|
|||||||
type DHTEntry struct {
|
type DHTEntry struct {
|
||||||
IPAddress string `json:"address"`
|
IPAddress string `json:"address"`
|
||||||
PublicKey string `json:"key"`
|
PublicKey string `json:"key"`
|
||||||
Port uint64 `json:"port"`
|
Parent string `json:"parent"`
|
||||||
Rest uint64 `json:"rest"`
|
Sequence uint64 `json:"sequence"`
|
||||||
|
//Port uint64 `json:"port"`
|
||||||
|
//Rest uint64 `json:"rest"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AdminSocket) getDHTHandler(req *GetDHTRequest, res *GetDHTResponse) error {
|
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{
|
res.DHT = append(res.DHT, DHTEntry{
|
||||||
IPAddress: net.IP(addr[:]).String(),
|
IPAddress: net.IP(addr[:]).String(),
|
||||||
PublicKey: hex.EncodeToString(d.Key[:]),
|
PublicKey: hex.EncodeToString(d.Key[:]),
|
||||||
Port: d.Port,
|
Parent: hex.EncodeToString(d.Parent[:]),
|
||||||
Rest: d.Rest,
|
Sequence: d.Sequence,
|
||||||
|
//Port: d.Port,
|
||||||
|
//Rest: d.Rest,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
sort.SliceStable(res.DHT, func(i, j int) bool {
|
sort.SliceStable(res.DHT, func(i, j int) bool {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package admin
|
package admin
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"net"
|
"net"
|
||||||
@ -38,3 +40,5 @@ func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsRespons
|
|||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
@ -32,14 +32,18 @@ type PeerInfo struct {
|
|||||||
|
|
||||||
type DHTEntryInfo struct {
|
type DHTEntryInfo struct {
|
||||||
Key ed25519.PublicKey
|
Key ed25519.PublicKey
|
||||||
Port uint64
|
Parent ed25519.PublicKey
|
||||||
Rest uint64
|
Sequence uint64
|
||||||
|
//Port uint64
|
||||||
|
//Rest uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
type PathEntryInfo struct {
|
type PathEntryInfo struct {
|
||||||
Key ed25519.PublicKey
|
Key ed25519.PublicKey
|
||||||
Sequence uint64
|
Sequence uint64
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
type SessionInfo struct {
|
type SessionInfo struct {
|
||||||
Key ed25519.PublicKey
|
Key ed25519.PublicKey
|
||||||
@ -96,13 +100,16 @@ func (c *Core) GetDHT() []DHTEntryInfo {
|
|||||||
for _, d := range ds {
|
for _, d := range ds {
|
||||||
var info DHTEntryInfo
|
var info DHTEntryInfo
|
||||||
info.Key = d.Key
|
info.Key = d.Key
|
||||||
info.Port = d.Port
|
info.Parent = d.Parent
|
||||||
|
info.Sequence = d.Sequence
|
||||||
|
//info.Port = d.Port
|
||||||
//info.Rest = d.Rest
|
//info.Rest = d.Rest
|
||||||
dhts = append(dhts, info)
|
dhts = append(dhts, info)
|
||||||
}
|
}
|
||||||
return dhts
|
return dhts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func (c *Core) GetPaths() []PathEntryInfo {
|
func (c *Core) GetPaths() []PathEntryInfo {
|
||||||
var paths []PathEntryInfo
|
var paths []PathEntryInfo
|
||||||
ps := c.PacketConn.PacketConn.Debug.GetPaths()
|
ps := c.PacketConn.PacketConn.Debug.GetPaths()
|
||||||
@ -115,6 +122,7 @@ func (c *Core) GetPaths() []PathEntryInfo {
|
|||||||
}
|
}
|
||||||
return paths
|
return paths
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func (c *Core) GetSessions() []SessionInfo {
|
func (c *Core) GetSessions() []SessionInfo {
|
||||||
var sessions []SessionInfo
|
var sessions []SessionInfo
|
||||||
|
@ -75,7 +75,7 @@ func WaitConnected(nodeA, nodeB *Core) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if len(nodeA.GetPaths()) > 1 && len(nodeB.GetPaths()) > 1 {
|
if len(nodeA.GetDHT()) > 1 && len(nodeB.GetDHT()) > 1 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user