mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-25 23:01:38 +00:00
add remote URI to GetPeers (fallback to net.Conn.RemoteAddr().String() if the uri is unknown)
This commit is contained in:
parent
6c63b02385
commit
c6a7a077a3
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/yggdrasil-network/yggdrasil-go
|
|||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
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/Arceliar/phony v0.0.0-20210209235338-dde1a8dca979
|
||||||
github.com/VividCortex/ewma v1.2.0 // indirect
|
github.com/VividCortex/ewma v1.2.0 // indirect
|
||||||
github.com/cheggaaa/pb/v3 v3.0.8
|
github.com/cheggaaa/pb/v3 v3.0.8
|
||||||
|
4
go.sum
4
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-20210613142316-e2332dbd4e3f h1:fnjzLzu6/0/cyeDVJb9mYS2odsw+6B88D9gO6iRSvGw=
|
||||||
github.com/Arceliar/ironwood v0.0.0-20210606094153-1bd43ce71198/go.mod h1:RP72rucOFm5udrnEzTmIWLRVGQiV/fSUAQXJ0RST/nk=
|
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 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/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
|
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
|
||||||
|
@ -18,6 +18,7 @@ type PeerEntry struct {
|
|||||||
PublicKey string `json:"key"`
|
PublicKey string `json:"key"`
|
||||||
Port uint64 `json:"port"`
|
Port uint64 `json:"port"`
|
||||||
Coords []uint64 `json:"coords"`
|
Coords []uint64 `json:"coords"`
|
||||||
|
Remote string `json:"remote"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersResponse) error {
|
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),
|
PublicKey: hex.EncodeToString(p.Key),
|
||||||
Port: p.Port,
|
Port: p.Port,
|
||||||
Coords: p.Coords,
|
Coords: p.Coords,
|
||||||
|
Remote: p.Remote,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -28,6 +28,7 @@ type Peer struct {
|
|||||||
Root ed25519.PublicKey
|
Root ed25519.PublicKey
|
||||||
Coords []uint64
|
Coords []uint64
|
||||||
Port uint64
|
Port uint64
|
||||||
|
Remote string
|
||||||
}
|
}
|
||||||
|
|
||||||
type DHTEntry struct {
|
type DHTEntry struct {
|
||||||
@ -56,6 +57,12 @@ func (c *Core) GetSelf() Self {
|
|||||||
|
|
||||||
func (c *Core) GetPeers() []Peer {
|
func (c *Core) GetPeers() []Peer {
|
||||||
var peers []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()
|
ps := c.pc.PacketConn.Debug.GetPeers()
|
||||||
for _, p := range ps {
|
for _, p := range ps {
|
||||||
var info Peer
|
var info Peer
|
||||||
@ -63,6 +70,10 @@ func (c *Core) GetPeers() []Peer {
|
|||||||
info.Root = p.Root
|
info.Root = p.Root
|
||||||
info.Coords = p.Coords
|
info.Coords = p.Coords
|
||||||
info.Port = p.Port
|
info.Port = p.Port
|
||||||
|
info.Remote = p.Conn.RemoteAddr().String()
|
||||||
|
if name := names[p.Conn]; name != "" {
|
||||||
|
info.Remote = name
|
||||||
|
}
|
||||||
peers = append(peers, info)
|
peers = append(peers, info)
|
||||||
}
|
}
|
||||||
return peers
|
return peers
|
||||||
|
Loading…
Reference in New Issue
Block a user