Skip to content
Snippets Groups Projects
Commit b6beebfe authored by Jonas Theis's avatar Jonas Theis Committed by Wolfgang Welz
Browse files

Feat: Add known peers to getNeighbors request (#154)

* Add known peers to getNeighbors request #151

* Check if autopeering discovery is enabled #151
parent b5bc0d39
Branches
Tags
No related merge requests found
...@@ -23,11 +23,27 @@ func getNeighbors(c echo.Context) error { ...@@ -23,11 +23,27 @@ func getNeighbors(c echo.Context) error {
chosen := []Neighbor{} chosen := []Neighbor{}
accepted := []Neighbor{} accepted := []Neighbor{}
knownPeers := []Neighbor{}
if autopeering.Selection == nil { if autopeering.Selection == nil {
return requestFailed(c, "Neighbor Selection is not enabled") return requestFailed(c, "Neighbor Selection is not enabled")
} }
if autopeering.Discovery == nil {
return requestFailed(c, "Neighbor Discovery is not enabled")
}
if c.QueryParam("known") == "1" {
for _, peer := range autopeering.Discovery.GetVerifiedPeers() {
n := Neighbor{
ID: peer.ID().String(),
PublicKey: base64.StdEncoding.EncodeToString(peer.PublicKey()),
}
n.Services = getServices(peer)
knownPeers = append(knownPeers, n)
}
}
for _, peer := range autopeering.Selection.GetOutgoingNeighbors() { for _, peer := range autopeering.Selection.GetOutgoingNeighbors() {
n := Neighbor{ n := Neighbor{
...@@ -45,14 +61,15 @@ func getNeighbors(c echo.Context) error { ...@@ -45,14 +61,15 @@ func getNeighbors(c echo.Context) error {
n.Services = getServices(peer) n.Services = getServices(peer)
accepted = append(accepted, n) accepted = append(accepted, n)
} }
return requestSuccessful(c, chosen, accepted)
return requestSuccessful(c, knownPeers, chosen, accepted)
} }
func requestSuccessful(c echo.Context, chosen, accepted []Neighbor) error { func requestSuccessful(c echo.Context, knownPeers, chosen, accepted []Neighbor) error {
return c.JSON(http.StatusOK, Response{ return c.JSON(http.StatusOK, Response{
Chosen: chosen, KnownPeers: knownPeers,
Accepted: accepted, Chosen: chosen,
Accepted: accepted,
}) })
} }
...@@ -63,15 +80,16 @@ func requestFailed(c echo.Context, message string) error { ...@@ -63,15 +80,16 @@ func requestFailed(c echo.Context, message string) error {
} }
type Response struct { type Response struct {
Chosen []Neighbor `json:"chosen"` KnownPeers []Neighbor `json:"known,omitempty"`
Accepted []Neighbor `json:"accepted"` Chosen []Neighbor `json:"chosen"`
Error string `json:"error,omitempty"` Accepted []Neighbor `json:"accepted"`
Error string `json:"error,omitempty"`
} }
type Neighbor struct { type Neighbor struct {
ID string `json:"id"` // comparable node identifier ID string `json:"id"` // comparable node identifier
PublicKey string `json:"publicKey"` // public key used to verify signatures PublicKey string `json:"publicKey"` // public key used to verify signatures
Services []peerService Services []peerService `json:"services,omitempty"`
} }
type peerService struct { type peerService struct {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment