neoneo-go/pkg/rpc/result/peers.go
Steven Jack 19a430b262 RCP server (#50)
* Adds basic RPC supporting files

* Adds interrupt handling and error chan

* Add getblock RPC method

* Update request structure

* Update names of nodes

* Allow bad addresses to be registered in discovery externally

* Small tidy up

* Few tweaks

* Check if error is close error in tcp transport

* Fix tests

* Fix priv port

* Small tweak to param name

* Comment fix

* Remove version from server

* Moves submitblock to TODO block

* Remove old field

* Bumps version and fix hex issues
2018-03-23 21:36:59 +01:00

58 lines
977 B
Go

package result
import (
"strings"
)
type (
// Peers payload for outputting peers in `getpeers` RPC call.
Peers struct {
Unconnected []Peer `json:"unconnected"`
Connected []Peer `json:"connected"`
Bad []Peer `json:"bad"`
}
// Peer represents the peer.
Peer struct {
Address string `json:"address"`
Port string `json:"port"`
}
)
// NewPeers creates a new Peers struct.
func NewPeers() Peers {
return Peers{
Unconnected: []Peer{},
Connected: []Peer{},
Bad: []Peer{},
}
}
// AddPeer adds a peer to the given peer type slice.
func (p *Peers) AddPeer(peerType string, addr string) {
addressParts := strings.Split(addr, ":")
peer := Peer{
Address: addressParts[0],
Port: addressParts[1],
}
switch peerType {
case "unconnected":
p.Unconnected = append(
p.Unconnected,
peer,
)
case "connected":
p.Connected = append(
p.Connected,
peer,
)
case "bad":
p.Bad = append(
p.Bad,
peer,
)
}
}