Skip to content

Commit

Permalink
Debug info fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
vikulin committed Dec 15, 2023
1 parent bfc22f6 commit 14f1b9e
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
38 changes: 22 additions & 16 deletions src/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"sync/atomic"
"time"

"encoding/hex"
"encoding/json"

"net"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/restapi/rest_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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,
Expand Down

0 comments on commit 14f1b9e

Please sign in to comment.