Skip to content

Commit

Permalink
Nil access fix in GetPeers
Browse files Browse the repository at this point in the history
  • Loading branch information
vikulin committed Dec 19, 2023
1 parent b03dc9b commit b9cc99b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
6 changes: 2 additions & 4 deletions src/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ type SelfInfo struct {
type PeerInfo struct {
Domain types.Domain
Root types.Domain
Remote string
URI string
Up bool
Inbound bool
LastError error
LastErrorTime time.Time
Coords []uint64
Port uint64
Priority uint8
RXBytes uint64
Expand Down Expand Up @@ -118,12 +116,12 @@ func (c *Core) GetPeers() []PeerInfo {
}
if p, ok := conns[conn]; ok {
peerinfo.Domain = p.Domain
peerinfo.Remote = p.Conn.RemoteAddr().String()
peerinfo.RemoteIp = p.Conn.RemoteAddr().String()
peerinfo.Root = p.Root
peerinfo.Port = p.Port
peerinfo.Priority = p.Priority
peers = append(peers, peerinfo)
}
peers = append(peers, peerinfo)
}
})

Expand Down
28 changes: 13 additions & 15 deletions src/restapi/rest_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,20 +559,19 @@ func (a *RestServer) getApiMulticastinterfacesHandler(w http.ResponseWriter, r *
}

type Peer struct {
Address string `json:"address"`
Key string `json:"key"`
Domain string `json:"domain"`
Port uint64 `json:"port"`
Priority uint64 `json:"priority"`
Coords []uint64 `json:"coords"`
Remote string `json:"remote"`
Remote_ip string `json:"remote_ip"`
Bytes_recvd uint64 `json:"bytes_recvd"`
Bytes_sent uint64 `json:"bytes_sent"`
Uptime float64 `json:"uptime"`
Multicast bool `json:"multicast"`
Country_short string `json:"country_short"`
Country_long string `json:"country_long"`
Address string `json:"address"`
Key string `json:"key"`
Domain string `json:"domain"`
Port uint64 `json:"port"`
Priority uint64 `json:"priority"`
Remote string `json:"remote"`
Remote_ip string `json:"remote_ip"`
Bytes_recvd uint64 `json:"bytes_recvd"`
Bytes_sent uint64 `json:"bytes_sent"`
Uptime float64 `json:"uptime"`
Multicast bool `json:"multicast"`
Country_short string `json:"country_short"`
Country_long string `json:"country_long"`
}

func (a *RestServer) prepareGetPeers() []Peer {
Expand All @@ -586,7 +585,6 @@ func (a *RestServer) prepareGetPeers() []Peer {
string(p.Domain.GetNormalizedName()),
p.Port,
uint64(p.Priority), // can't be uint8 thanks to gobind
p.Coords,
p.URI,
p.RemoteIp,
p.RXBytes,
Expand Down

0 comments on commit b9cc99b

Please sign in to comment.