From c6a7a077a36a99f852342b2060862c5dae119909 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sun, 13 Jun 2021 09:25:08 -0500 Subject: [PATCH] add remote URI to GetPeers (fallback to net.Conn.RemoteAddr().String() if the uri is unknown) --- go.mod | 2 +- go.sum | 4 ++-- src/admin/getpeers.go | 2 ++ src/core/api.go | 11 +++++++++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1e27d93b..72a9abc7 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/yggdrasil-network/yggdrasil-go go 1.16 require ( - github.com/Arceliar/ironwood v0.0.0-20210606094153-1bd43ce71198 + github.com/Arceliar/ironwood v0.0.0-20210613142316-e2332dbd4e3f github.com/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979 github.com/VividCortex/ewma v1.2.0 // indirect github.com/cheggaaa/pb/v3 v3.0.8 diff --git a/go.sum b/go.sum index dab85269..e7135473 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/Arceliar/ironwood v0.0.0-20210606094153-1bd43ce71198 h1:wLF+CSqm9DrPeT2dp1E4Xe5of8SyUxfJVxw8DHeT1YM= -github.com/Arceliar/ironwood v0.0.0-20210606094153-1bd43ce71198/go.mod h1:RP72rucOFm5udrnEzTmIWLRVGQiV/fSUAQXJ0RST/nk= +github.com/Arceliar/ironwood v0.0.0-20210613142316-e2332dbd4e3f h1:fnjzLzu6/0/cyeDVJb9mYS2odsw+6B88D9gO6iRSvGw= +github.com/Arceliar/ironwood v0.0.0-20210613142316-e2332dbd4e3f/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/go.mod h1:6Lkn+/zJilRMsKmbmG1RPoamiArC6HS73xbwRyp3UyI= github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= diff --git a/src/admin/getpeers.go b/src/admin/getpeers.go index 9f53cf23..9ccf9e2f 100644 --- a/src/admin/getpeers.go +++ b/src/admin/getpeers.go @@ -18,6 +18,7 @@ type PeerEntry struct { PublicKey string `json:"key"` Port uint64 `json:"port"` Coords []uint64 `json:"coords"` + Remote string `json:"remote"` } func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersResponse) error { @@ -29,6 +30,7 @@ func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersRespons PublicKey: hex.EncodeToString(p.Key), Port: p.Port, Coords: p.Coords, + Remote: p.Remote, } } return nil diff --git a/src/core/api.go b/src/core/api.go index d1b931cf..0e9d9d7a 100644 --- a/src/core/api.go +++ b/src/core/api.go @@ -28,6 +28,7 @@ type Peer struct { Root ed25519.PublicKey Coords []uint64 Port uint64 + Remote string } type DHTEntry struct { @@ -56,6 +57,12 @@ func (c *Core) GetSelf() Self { func (c *Core) GetPeers() []Peer { var peers []Peer + names := make(map[net.Conn]string) + c.links.mutex.Lock() + for _, info := range c.links.links { + names[info.conn] = info.lname + } + c.links.mutex.Unlock() ps := c.pc.PacketConn.Debug.GetPeers() for _, p := range ps { var info Peer @@ -63,6 +70,10 @@ func (c *Core) GetPeers() []Peer { info.Root = p.Root info.Coords = p.Coords info.Port = p.Port + info.Remote = p.Conn.RemoteAddr().String() + if name := names[p.Conn]; name != "" { + info.Remote = name + } peers = append(peers, info) } return peers