Skip to content

Commit

Permalink
Revert "GetPeers update"
Browse files Browse the repository at this point in the history
This reverts commit a3c9140.
  • Loading branch information
vikulin committed Dec 16, 2023
1 parent a3c9140 commit 61af1b8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 42 deletions.
73 changes: 34 additions & 39 deletions src/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"net"
"net/url"

"github.com/Arceliar/ironwood/network"
"github.com/Arceliar/ironwood/types"
"github.com/Arceliar/phony"
)
Expand All @@ -35,6 +34,7 @@ type SelfInfo struct {
type PeerInfo struct {
Domain types.Domain
Root types.Domain
Remote string
URI string
Up bool
Inbound bool
Expand Down Expand Up @@ -94,48 +94,43 @@ func (c *Core) GetSelf() SelfInfo {
}

func (c *Core) GetPeers() []PeerInfo {
peers := []PeerInfo{}
conns := map[net.Conn]network.DebugPeerInfo{}
iwpeers := c.PacketConn.PacketConn.Debug.GetPeers()
for _, p := range iwpeers {
conns[p.Conn] = p
}

var peers []PeerInfo
names := make(map[net.Conn]string)
ips := make(map[net.Conn]string)
phony.Block(&c.links, func() {
for info, state := range c.links._links {
var peerinfo PeerInfo
var conn net.Conn

//peerinfo.LastError = state._err
//#peerinfo.LastErrorTime = state._errtime
if c := state.conn; c != nil {
conn = c
peerinfo.Up = true
//peerinfo.Inbound = state.linkType == linkTypeIncoming
peerinfo.RXBytes = atomic.LoadUint64(&c.rx)
peerinfo.TXBytes = atomic.LoadUint64(&c.tx)
peerinfo.Uptime = time.Since(c.up)
for _, info := range c.links._links {
if info == nil {
continue
}
if p, ok := conns[conn]; ok {
peerinfo.Domain = p.Domain
peerinfo.Root = p.Root
peerinfo.Port = p.Port
peerinfo.Priority = p.Priority
peerinfo.URI = p.Conn.RemoteAddr().String()
if name := state.lname; name != "" {
peerinfo.URI = name
}
if peerinfo.RemoteIp = info.remote; peerinfo.RemoteIp != "" {
//Cut port
if host, _, err := net.SplitHostPort(peerinfo.RemoteIp); err == nil {
peerinfo.RemoteIp = host
}
}
}
peers = append(peers, peerinfo)
names[info.conn] = info.lname
ips[info.conn] = info.info.remote
}
})

ps := c.PacketConn.PacketConn.Debug.GetPeers()
for _, p := range ps {
var info PeerInfo
info.Domain = p.Domain
info.Root = p.Root
info.Coords = p.Coords
info.Port = p.Port
info.Priority = p.Priority
info.Remote = p.Conn.RemoteAddr().String()
if name := names[p.Conn]; name != "" {
info.Remote = name
}
if info.RemoteIp = ips[p.Conn]; info.RemoteIp != "" {
//Cut port
if host, _, err := net.SplitHostPort(info.RemoteIp); err == nil {
info.RemoteIp = host
}
}
if linkconn, ok := p.Conn.(*linkConn); ok {
info.RXBytes = atomic.LoadUint64(&linkconn.rx)
info.TXBytes = atomic.LoadUint64(&linkconn.tx)
info.Uptime = time.Since(linkconn.up)
}
peers = append(peers, info)
}
return peers
}

Expand Down
6 changes: 3 additions & 3 deletions src/restapi/rest_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ type Peer struct {
Port uint64 `json:"port"`
Priority uint64 `json:"priority"`
Coords []uint64 `json:"coords"`
URI string `json:"uri"`
Remote string `json:"remote"`
Remote_ip string `json:"remote_ip"`
Bytes_recvd uint64 `json:"bytes_recvd"`
Bytes_sent uint64 `json:"bytes_sent"`
Expand All @@ -587,12 +587,12 @@ func (a *RestServer) prepareGetPeers() []Peer {
p.Port,
uint64(p.Priority), // can't be uint8 thanks to gobind
p.Coords,
p.URI,
p.Remote,
p.RemoteIp,
p.RXBytes,
p.TXBytes,
p.Uptime.Seconds(),
strings.Contains(p.URI, "[fe80::"),
strings.Contains(p.Remote, "[fe80::"),
"",
"",
}
Expand Down

0 comments on commit 61af1b8

Please sign in to comment.