From 14f1b9e83d1fe75e45bea8cedcea8d2975d7b1d6 Mon Sep 17 00:00:00 2001 From: Vadym Vikulin Date: Sat, 16 Dec 2023 00:34:49 +0200 Subject: [PATCH] Debug info fixes --- go.mod | 2 +- go.sum | 8 ++------ src/core/api.go | 38 ++++++++++++++++++++++---------------- src/core/proto.go | 2 +- src/restapi/rest_server.go | 12 +++++++----- 5 files changed, 33 insertions(+), 29 deletions(-) diff --git a/go.mod b/go.mod index b13715ec4..319917689 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/RiV-chain/RiV-mesh go 1.21 -replace github.com/Arceliar/ironwood => github.com/RiV-chain/ironwood v0.0.0-20231214215935-1a5f91834ba7 +replace github.com/Arceliar/ironwood => github.com/RiV-chain/ironwood v0.0.0-20231215220801-c35d010e1cc0 replace github.com/mikispag/dns-over-tls-forwarder => github.com/RiV-chain/dns-over-tls-forwarder v0.0.0-20230828114909-c2cd9f8d79d3 diff --git a/go.sum b/go.sum index ff7ca22bc..58510826c 100644 --- a/go.sum +++ b/go.sum @@ -4,12 +4,8 @@ github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d h1:UK9fsWbWqwIQkMCz github.com/Arceliar/phony v0.0.0-20220903101357-530938a4b13d/go.mod h1:BCnxhRf47C/dy/e/D2pmB8NkB3dQVIrkD98b220rx5Q= github.com/RiV-chain/dns-over-tls-forwarder v0.0.0-20230828114909-c2cd9f8d79d3 h1:gz71d+oEAMXYUYw54JKT4A6CxniQx6B9J0G5CYJeLok= github.com/RiV-chain/dns-over-tls-forwarder v0.0.0-20230828114909-c2cd9f8d79d3/go.mod h1:V2Irj3BjF2tLZ3xXp6TMQCu0I+eJWQPEktbLMHQN8XA= -github.com/RiV-chain/ironwood v0.0.0-20231208144419-a961fa133a84 h1:+RgMzF9gt+2C/X8946XOHOUNXg2oyHp04Eeyup0jD/g= -github.com/RiV-chain/ironwood v0.0.0-20231208144419-a961fa133a84/go.mod h1:O9iIMM9iVSXUIKNcrjossDuuXLwoGNuLSDXqjtTBHJk= -github.com/RiV-chain/ironwood v0.0.0-20231209113647-b58bfdf04661 h1:SHIqoL+YZDhl7fk2f5J0HStbXuchgLHa8eTdLU/kYkE= -github.com/RiV-chain/ironwood v0.0.0-20231209113647-b58bfdf04661/go.mod h1:O9iIMM9iVSXUIKNcrjossDuuXLwoGNuLSDXqjtTBHJk= -github.com/RiV-chain/ironwood v0.0.0-20231214215935-1a5f91834ba7 h1:dF56xA9jGei6x93h/AAwdMKRumPBoqWI3RvYQFXgYh8= -github.com/RiV-chain/ironwood v0.0.0-20231214215935-1a5f91834ba7/go.mod h1:O9iIMM9iVSXUIKNcrjossDuuXLwoGNuLSDXqjtTBHJk= +github.com/RiV-chain/ironwood v0.0.0-20231215220801-c35d010e1cc0 h1:17qzo0LTxGO1Z841EFldw3jHudk0R6ZQj7RrBbFX6RU= +github.com/RiV-chain/ironwood v0.0.0-20231215220801-c35d010e1cc0/go.mod h1:O9iIMM9iVSXUIKNcrjossDuuXLwoGNuLSDXqjtTBHJk= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/bits-and-blooms/bitset v1.3.1/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= diff --git a/src/core/api.go b/src/core/api.go index 34f93dbe5..d881b9e4c 100644 --- a/src/core/api.go +++ b/src/core/api.go @@ -6,7 +6,6 @@ import ( "sync/atomic" "time" - "encoding/hex" "encoding/json" "net" @@ -51,23 +50,25 @@ type PeerInfo struct { } type TreeEntryInfo struct { - Key ed25519.PublicKey - Parent ed25519.PublicKey - Sequence uint64 + IPAddress string + Domain string + Parent string + Sequence uint64 } type PathEntryInfo struct { - Key ed25519.PublicKey - Path []uint64 - Sequence uint64 + IPAddress string + Domain string + Path []uint64 + Sequence uint64 } type SessionInfo struct { - Key string - Domain string - RXBytes uint64 - TXBytes uint64 - Uptime time.Duration + IPAddress string + Domain string + RXBytes uint64 + TXBytes uint64 + Uptime time.Duration } func (c *Core) GetLabel() LabelInfo { @@ -137,9 +138,11 @@ func (c *Core) GetTree() []TreeEntryInfo { var trees []TreeEntryInfo ts := c.PacketConn.PacketConn.Debug.GetTree() for _, t := range ts { + addr := c.AddrForDomain(t.Domain) var info TreeEntryInfo - info.Key = t.Key - info.Parent = t.Parent + info.IPAddress = net.IP(addr[:]).String() + info.Domain = string(t.Domain.GetNormalizedName()) + info.Parent = string(t.Parent.GetNormalizedName()) info.Sequence = t.Sequence trees = append(trees, info) } @@ -150,8 +153,10 @@ func (c *Core) GetPaths() []PathEntryInfo { var paths []PathEntryInfo ps := c.PacketConn.PacketConn.Debug.GetPaths() for _, p := range ps { + addr := c.AddrForDomain(p.Domain) var info PathEntryInfo - info.Key = p.Key + info.IPAddress = net.IP(addr[:]).String() + info.Domain = string(p.Domain.GetNormalizedName()) info.Sequence = p.Sequence info.Path = p.Path paths = append(paths, info) @@ -163,8 +168,9 @@ func (c *Core) GetSessions() []SessionInfo { var sessions []SessionInfo ss := c.PacketConn.Debug.GetSessions() for _, s := range ss { + addr := c.AddrForDomain(s.Domain) var info SessionInfo - info.Key = hex.EncodeToString(s.Domain.Key) + info.IPAddress = net.IP(addr[:]).String() info.Domain = string(s.Domain.GetNormalizedName()) info.RXBytes = s.RX info.TXBytes = s.TX diff --git a/src/core/proto.go b/src/core/proto.go index 96c57f2bf..a47dabe40 100644 --- a/src/core/proto.go +++ b/src/core/proto.go @@ -225,7 +225,7 @@ func (p *protoHandler) _handleGetTreeRequest(domain iwt.Domain) { dinfos := p.core.GetTree() var bs []byte for _, dinfo := range dinfos { - tmp := append(bs, dinfo.Key[:]...) + tmp := append(bs, dinfo.Domain[:]...) const responseOverhead = 2 // 1 debug type, 1 gettree type if uint64(len(tmp))+responseOverhead > p.core.MTU() { break diff --git a/src/restapi/rest_server.go b/src/restapi/rest_server.go index b20a72a93..dcfa46686 100644 --- a/src/restapi/rest_server.go +++ b/src/restapi/rest_server.go @@ -428,7 +428,7 @@ func (a *RestServer) putApiNodeinfoHandler(w http.ResponseWriter, r *http.Reques }, r) } -// @Summary Show known Tree entries. The output contains following fields: Address, Public Key, Port, Rest +// @Summary Show known Tree entries. The output contains following fields: Domain, Parent, Sequence // @Produce json // @Success 200 {string} string "ok" // @Failure 400 {error} error "Method not allowed" @@ -439,7 +439,7 @@ func (a *RestServer) getApiTreeHandler(w http.ResponseWriter, r *http.Request) { result := make([]map[string]any, 0, len(tree)) for _, d := range tree { entry := map[string]any{ - "key": hex.EncodeToString(d.Key), + "domain": d.Domain, "parent": d.Parent, "sequence": d.Sequence, } @@ -501,8 +501,10 @@ func (a *RestServer) getApiPathsHandler(w http.ResponseWriter, r *http.Request) result := make([]map[string]any, 0, len(paths)) for _, d := range paths { entry := map[string]any{ - "key": hex.EncodeToString(d.Key), - "path": d.Path, + "ip": d.IPAddress, + "domain": d.Domain, + "path": d.Path, + "sequence": d.Sequence, } result = append(result, entry) } @@ -523,7 +525,7 @@ func (a *RestServer) getApiSessionsHandler(w http.ResponseWriter, r *http.Reques result := make([]map[string]any, 0, len(sessions)) for _, s := range sessions { entry := map[string]any{ - "key": s.Key, + "ip": s.IPAddress, "domain": s.Domain, "bytes_recvd": s.RXBytes, "bytes_sent": s.TXBytes,