mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-11-25 02:55:26 +00:00
More updates for Ygg v0.5
This commit is contained in:
parent
83c1a810b5
commit
a148f4cfec
@ -165,7 +165,7 @@ func run() int {
|
|||||||
table.Append([]string{"Build version:", resp.BuildVersion})
|
table.Append([]string{"Build version:", resp.BuildVersion})
|
||||||
table.Append([]string{"IPv6 address:", resp.IPAddress})
|
table.Append([]string{"IPv6 address:", resp.IPAddress})
|
||||||
table.Append([]string{"IPv6 subnet:", resp.Subnet})
|
table.Append([]string{"IPv6 subnet:", resp.Subnet})
|
||||||
table.Append([]string{"Coordinates:", fmt.Sprintf("%v", resp.Coords)})
|
table.Append([]string{"Routing table size:", fmt.Sprintf("%d", resp.RoutingEntries)})
|
||||||
table.Append([]string{"Public key:", resp.PublicKey})
|
table.Append([]string{"Public key:", resp.PublicKey})
|
||||||
table.Render()
|
table.Render()
|
||||||
|
|
||||||
@ -210,12 +210,12 @@ 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", "Path"})
|
table.SetHeader([]string{"Public Key", "IP Address", "Seq"})
|
||||||
for _, p := range resp.Paths {
|
for _, p := range resp.Paths {
|
||||||
table.Append([]string{
|
table.Append([]string{
|
||||||
p.PublicKey,
|
p.PublicKey,
|
||||||
p.IPAddress,
|
p.IPAddress,
|
||||||
fmt.Sprintf("%v", p.Path),
|
fmt.Sprintf("%d", p.Sequence),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
table.Render()
|
table.Render()
|
||||||
|
@ -3,7 +3,6 @@ package mobile
|
|||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
@ -193,7 +192,8 @@ func (m *Yggdrasil) GetPublicKeyString() string {
|
|||||||
|
|
||||||
// GetCoordsString gets the node's coordinates
|
// GetCoordsString gets the node's coordinates
|
||||||
func (m *Yggdrasil) GetCoordsString() string {
|
func (m *Yggdrasil) GetCoordsString() string {
|
||||||
return fmt.Sprintf("%v", m.core.GetSelf().Coords)
|
return "N/A"
|
||||||
|
// return fmt.Sprintf("%v", m.core.GetSelf().Coords)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Yggdrasil) GetPeersJSON() (result string) {
|
func (m *Yggdrasil) GetPeersJSON() (result string) {
|
||||||
|
2
go.mod
2
go.mod
@ -2,6 +2,8 @@ module github.com/yggdrasil-network/yggdrasil-go
|
|||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
|
replace github.com/Arceliar/ironwood => github.com/neilalexander/ironwood v0.0.0-20230319103146-3ffd3d07e834
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Arceliar/ironwood v0.0.0-20230318003210-65aa386cab13
|
github.com/Arceliar/ironwood v0.0.0-20230318003210-65aa386cab13
|
||||||
github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979
|
github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979
|
||||||
|
4
go.sum
4
go.sum
@ -1,5 +1,3 @@
|
|||||||
github.com/Arceliar/ironwood v0.0.0-20230318003210-65aa386cab13 h1:z0PVz7aDDW5c+JVEW7b00N2JMGAfV6BHtTcOJ8zHKcU=
|
|
||||||
github.com/Arceliar/ironwood v0.0.0-20230318003210-65aa386cab13/go.mod h1:RP72rucOFm5udrnEzTmIWLRVGQiV/fSUAQXJ0RST/nk=
|
|
||||||
github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979 h1:WndgpSW13S32VLQ3ugUxx2EnnWmgba1kCqPkd4Gk1yQ=
|
github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979 h1:WndgpSW13S32VLQ3ugUxx2EnnWmgba1kCqPkd4Gk1yQ=
|
||||||
github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979/go.mod h1:6Lkn+/zJilRMsKmbmG1RPoamiArC6HS73xbwRyp3UyI=
|
github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979/go.mod h1:6Lkn+/zJilRMsKmbmG1RPoamiArC6HS73xbwRyp3UyI=
|
||||||
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=
|
||||||
@ -32,6 +30,8 @@ github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4
|
|||||||
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
|
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
|
||||||
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||||
|
github.com/neilalexander/ironwood v0.0.0-20230319103146-3ffd3d07e834 h1:HwRcrQhhthIPKBVZVHlwkKpxZxwNv0QcwIA0Gb+5Dtk=
|
||||||
|
github.com/neilalexander/ironwood v0.0.0-20230319103146-3ffd3d07e834/go.mod h1:RP72rucOFm5udrnEzTmIWLRVGQiV/fSUAQXJ0RST/nk=
|
||||||
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
|
||||||
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
|
||||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
|
@ -17,9 +17,9 @@ type GetPathsResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PathEntry struct {
|
type PathEntry struct {
|
||||||
IPAddress string `json:"address"`
|
IPAddress string `json:"address"`
|
||||||
PublicKey string `json:"key"`
|
PublicKey string `json:"key"`
|
||||||
Path []uint64 `json:"path"`
|
Sequence uint64 `json:"sequence"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsResponse) error {
|
func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsResponse) error {
|
||||||
@ -30,7 +30,7 @@ func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsRespons
|
|||||||
res.Paths = append(res.Paths, PathEntry{
|
res.Paths = append(res.Paths, PathEntry{
|
||||||
IPAddress: net.IP(addr[:]).String(),
|
IPAddress: net.IP(addr[:]).String(),
|
||||||
PublicKey: hex.EncodeToString(p.Key),
|
PublicKey: hex.EncodeToString(p.Key),
|
||||||
Path: p.Path,
|
Sequence: p.Sequence,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
sort.SliceStable(res.Paths, func(i, j int) bool {
|
sort.SliceStable(res.Paths, func(i, j int) bool {
|
||||||
|
@ -20,7 +20,6 @@ type PeerEntry struct {
|
|||||||
PublicKey string `json:"key"`
|
PublicKey string `json:"key"`
|
||||||
Port uint64 `json:"port"`
|
Port uint64 `json:"port"`
|
||||||
Priority uint64 `json:"priority"`
|
Priority uint64 `json:"priority"`
|
||||||
Coords []uint64 `json:"coords"`
|
|
||||||
Remote string `json:"remote"`
|
Remote string `json:"remote"`
|
||||||
RXBytes DataUnit `json:"bytes_recvd"`
|
RXBytes DataUnit `json:"bytes_recvd"`
|
||||||
TXBytes DataUnit `json:"bytes_sent"`
|
TXBytes DataUnit `json:"bytes_sent"`
|
||||||
@ -37,7 +36,6 @@ func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersRespons
|
|||||||
PublicKey: hex.EncodeToString(p.Key),
|
PublicKey: hex.EncodeToString(p.Key),
|
||||||
Port: p.Port,
|
Port: p.Port,
|
||||||
Priority: uint64(p.Priority), // can't be uint8 thanks to gobind
|
Priority: uint64(p.Priority), // can't be uint8 thanks to gobind
|
||||||
Coords: p.Coords,
|
|
||||||
Remote: p.Remote,
|
Remote: p.Remote,
|
||||||
RXBytes: DataUnit(p.RXBytes),
|
RXBytes: DataUnit(p.RXBytes),
|
||||||
TXBytes: DataUnit(p.TXBytes),
|
TXBytes: DataUnit(p.TXBytes),
|
||||||
|
@ -9,12 +9,12 @@ import (
|
|||||||
type GetSelfRequest struct{}
|
type GetSelfRequest struct{}
|
||||||
|
|
||||||
type GetSelfResponse struct {
|
type GetSelfResponse struct {
|
||||||
BuildName string `json:"build_name"`
|
BuildName string `json:"build_name"`
|
||||||
BuildVersion string `json:"build_version"`
|
BuildVersion string `json:"build_version"`
|
||||||
PublicKey string `json:"key"`
|
PublicKey string `json:"key"`
|
||||||
IPAddress string `json:"address"`
|
IPAddress string `json:"address"`
|
||||||
Coords []uint64 `json:"coords"`
|
RoutingEntries uint64 `json:"routing_entries"`
|
||||||
Subnet string `json:"subnet"`
|
Subnet string `json:"subnet"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AdminSocket) getSelfHandler(req *GetSelfRequest, res *GetSelfResponse) error {
|
func (a *AdminSocket) getSelfHandler(req *GetSelfRequest, res *GetSelfResponse) error {
|
||||||
@ -25,6 +25,6 @@ func (a *AdminSocket) getSelfHandler(req *GetSelfRequest, res *GetSelfResponse)
|
|||||||
res.PublicKey = hex.EncodeToString(self.Key[:])
|
res.PublicKey = hex.EncodeToString(self.Key[:])
|
||||||
res.IPAddress = a.core.Address().String()
|
res.IPAddress = a.core.Address().String()
|
||||||
res.Subnet = snet.String()
|
res.Subnet = snet.String()
|
||||||
res.Coords = self.Coords
|
res.RoutingEntries = self.RoutingEntries
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SelfInfo struct {
|
type SelfInfo struct {
|
||||||
Key ed25519.PublicKey
|
Key ed25519.PublicKey
|
||||||
Root ed25519.PublicKey
|
RoutingEntries uint64
|
||||||
Coords []uint64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type PeerInfo struct {
|
type PeerInfo struct {
|
||||||
@ -38,8 +37,8 @@ type DHTEntryInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PathEntryInfo struct {
|
type PathEntryInfo struct {
|
||||||
Key ed25519.PublicKey
|
Key ed25519.PublicKey
|
||||||
Path []uint64
|
Sequence uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type SessionInfo struct {
|
type SessionInfo struct {
|
||||||
@ -53,13 +52,12 @@ func (c *Core) GetSelf() SelfInfo {
|
|||||||
var self SelfInfo
|
var self SelfInfo
|
||||||
s := c.PacketConn.PacketConn.Debug.GetSelf()
|
s := c.PacketConn.PacketConn.Debug.GetSelf()
|
||||||
self.Key = s.Key
|
self.Key = s.Key
|
||||||
self.Root = s.Root
|
self.RoutingEntries = s.RoutingEntries
|
||||||
self.Coords = s.Coords
|
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Core) GetPeers() []PeerInfo {
|
func (c *Core) GetPeers() []PeerInfo {
|
||||||
var peers []PeerInfo
|
peers := []PeerInfo{}
|
||||||
names := make(map[net.Conn]string)
|
names := make(map[net.Conn]string)
|
||||||
phony.Block(&c.links, func() {
|
phony.Block(&c.links, func() {
|
||||||
for _, info := range c.links._links {
|
for _, info := range c.links._links {
|
||||||
@ -74,17 +72,18 @@ func (c *Core) GetPeers() []PeerInfo {
|
|||||||
var info PeerInfo
|
var info PeerInfo
|
||||||
info.Key = p.Key
|
info.Key = p.Key
|
||||||
info.Root = p.Root
|
info.Root = p.Root
|
||||||
info.Coords = p.Coords
|
|
||||||
info.Port = p.Port
|
info.Port = p.Port
|
||||||
info.Priority = p.Priority
|
info.Priority = p.Priority
|
||||||
info.Remote = p.Conn.RemoteAddr().String()
|
if p.Conn != nil {
|
||||||
if name := names[p.Conn]; name != "" {
|
info.Remote = p.Conn.RemoteAddr().String()
|
||||||
info.Remote = name
|
if linkconn, ok := p.Conn.(*linkConn); ok {
|
||||||
}
|
info.RXBytes = atomic.LoadUint64(&linkconn.rx)
|
||||||
if linkconn, ok := p.Conn.(*linkConn); ok {
|
info.TXBytes = atomic.LoadUint64(&linkconn.tx)
|
||||||
info.RXBytes = atomic.LoadUint64(&linkconn.rx)
|
info.Uptime = time.Since(linkconn.up)
|
||||||
info.TXBytes = atomic.LoadUint64(&linkconn.tx)
|
}
|
||||||
info.Uptime = time.Since(linkconn.up)
|
if name := names[p.Conn]; name != "" {
|
||||||
|
info.Remote = name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
peers = append(peers, info)
|
peers = append(peers, info)
|
||||||
}
|
}
|
||||||
@ -110,6 +109,7 @@ func (c *Core) GetPaths() []PathEntryInfo {
|
|||||||
for _, p := range ps {
|
for _, p := range ps {
|
||||||
var info PathEntryInfo
|
var info PathEntryInfo
|
||||||
info.Key = p.Key
|
info.Key = p.Key
|
||||||
|
info.Sequence = p.Sequence
|
||||||
//info.Path = p.Path
|
//info.Path = p.Path
|
||||||
paths = append(paths, info)
|
paths = append(paths, info)
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ func (l *links) create(conn net.Conn, dial *linkDial, name string, info linkInfo
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
if err := intf.handler(dial); err != nil {
|
if err := intf.handler(dial); err != nil {
|
||||||
l.core.log.Errorf("Link handler %s error (%s): %s", name, conn.RemoteAddr(), err)
|
//l.core.log.Errorf("Link handler %s error (%s): %s", name, conn.RemoteAddr(), err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
|
@ -126,8 +126,8 @@ func (p *protoHandler) sendGetSelfRequest(key keyArray, callback func([]byte)) {
|
|||||||
func (p *protoHandler) _handleGetSelfRequest(key keyArray) {
|
func (p *protoHandler) _handleGetSelfRequest(key keyArray) {
|
||||||
self := p.core.GetSelf()
|
self := p.core.GetSelf()
|
||||||
res := map[string]string{
|
res := map[string]string{
|
||||||
"key": hex.EncodeToString(self.Key[:]),
|
"key": hex.EncodeToString(self.Key[:]),
|
||||||
"coords": fmt.Sprintf("%v", self.Coords),
|
"routing_entries": fmt.Sprintf("%v", self.RoutingEntries),
|
||||||
}
|
}
|
||||||
bs, err := json.Marshal(res) // FIXME this puts keys in base64, not hex
|
bs, err := json.Marshal(res) // FIXME this puts keys in base64, not hex
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -57,10 +57,10 @@ func (k *keyStore) init(c *core.Core) {
|
|||||||
k.core = c
|
k.core = c
|
||||||
k.address = *address.AddrForKey(k.core.PublicKey())
|
k.address = *address.AddrForKey(k.core.PublicKey())
|
||||||
k.subnet = *address.SubnetForKey(k.core.PublicKey())
|
k.subnet = *address.SubnetForKey(k.core.PublicKey())
|
||||||
if err := k.core.SetOutOfBandHandler(k.oobHandler); err != nil {
|
/*if err := k.core.SetOutOfBandHandler(k.oobHandler); err != nil {
|
||||||
err = fmt.Errorf("tun.core.SetOutOfBandHander: %w", err)
|
err = fmt.Errorf("tun.core.SetOutOfBandHander: %w", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}*/
|
||||||
k.keyToInfo = make(map[keyArray]*keyInfo)
|
k.keyToInfo = make(map[keyArray]*keyInfo)
|
||||||
k.addrToInfo = make(map[address.Address]*keyInfo)
|
k.addrToInfo = make(map[address.Address]*keyInfo)
|
||||||
k.addrBuffer = make(map[address.Address]*buffer)
|
k.addrBuffer = make(map[address.Address]*buffer)
|
||||||
@ -202,13 +202,15 @@ func (k *keyStore) oobHandler(fromKey, toKey ed25519.PublicKey, data []byte) {
|
|||||||
func (k *keyStore) sendKeyLookup(partial ed25519.PublicKey) {
|
func (k *keyStore) sendKeyLookup(partial ed25519.PublicKey) {
|
||||||
sig := ed25519.Sign(k.core.PrivateKey(), partial[:])
|
sig := ed25519.Sign(k.core.PrivateKey(), partial[:])
|
||||||
bs := append([]byte{typeKeyLookup}, sig...)
|
bs := append([]byte{typeKeyLookup}, sig...)
|
||||||
_ = k.core.SendOutOfBand(partial, bs)
|
//_ = k.core.SendOutOfBand(partial, bs)
|
||||||
|
_ = bs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *keyStore) sendKeyResponse(dest ed25519.PublicKey) {
|
func (k *keyStore) sendKeyResponse(dest ed25519.PublicKey) {
|
||||||
sig := ed25519.Sign(k.core.PrivateKey(), dest[:])
|
sig := ed25519.Sign(k.core.PrivateKey(), dest[:])
|
||||||
bs := append([]byte{typeKeyResponse}, sig...)
|
bs := append([]byte{typeKeyResponse}, sig...)
|
||||||
_ = k.core.SendOutOfBand(dest, bs)
|
//_ = k.core.SendOutOfBand(dest, bs)
|
||||||
|
_ = bs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *keyStore) readPC(p []byte) (int, error) {
|
func (k *keyStore) readPC(p []byte) (int, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user