forked from iotaledger/goshimmer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manualpeering.go
46 lines (39 loc) · 1.52 KB
/
manualpeering.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package client
import (
"net/http"
"github.com/cockroachdb/errors"
"github.com/izuc/zipp.foundation/core/crypto/ed25519"
"github.com/izuc/zipp/packages/app/jsonmodels"
"github.com/izuc/zipp/packages/node/manualpeering"
)
const (
routeManualPeers = "manualpeering/peers"
)
// AddManualPeers adds the provided list of peers to the manual peering layer.
func (api *ZIPPAPI) AddManualPeers(peers []*manualpeering.KnownPeerToAdd) error {
if err := api.do(http.MethodPost, routeManualPeers, peers, nil); err != nil {
return errors.Wrap(err, "failed to add manual peers via the HTTP API")
}
return nil
}
// RemoveManualPeers remove the provided list of peers from the manual peering layer.
func (api *ZIPPAPI) RemoveManualPeers(keys []ed25519.PublicKey) error {
peersToRemove := make([]*jsonmodels.PeerToRemove, len(keys))
for i, key := range keys {
peersToRemove[i] = &jsonmodels.PeerToRemove{PublicKey: key}
}
if err := api.do(http.MethodDelete, routeManualPeers, peersToRemove, nil); err != nil {
return errors.Wrap(err, "failed to remove manual peers via the HTTP API")
}
return nil
}
// GetManualPeers gets the list of connected neighbors from the manual peering layer.
func (api *ZIPPAPI) GetManualPeers(opts ...manualpeering.GetPeersOption) (
peers []*manualpeering.KnownPeer, err error,
) {
conf := manualpeering.BuildGetPeersConfig(opts)
if err := api.do(http.MethodGet, routeManualPeers, conf, &peers); err != nil {
return nil, errors.Wrap(err, "failed to get manual connected peers from the API")
}
return peers, nil
}