diff --git a/shell.go b/shell.go index 78bbcc5dd..e2b0e503a 100644 --- a/shell.go +++ b/shell.go @@ -611,3 +611,26 @@ func (s *Shell) SwarmConnect(ctx context.Context, addr ...string) error { Exec(ctx, &conn) return err } + +type PeeringLsOutput struct { + Peers []PeerInfo +} + +// SwarmPeeringLs lists peers registered in the peering subsystem +func (s *Shell) SwarmPeeringLs(ctx context.Context) (*PeeringLsOutput, error) { + var output *PeeringLsOutput + err := s.Request("swarm/peering/ls").Arguments().Exec(ctx, &output) + return output, err +} + +type PeerStatus struct { + ID string + Status string +} + +// SwarmPeeringAdd adds a peer into the peering subsysytem. +func (s *Shell) SwarmPeeringAdd(ctx context.Context, addr string) (*PeerStatus, error) { + var output *PeerStatus + err := s.Request("swarm/peering/add").Arguments(addr).Exec(ctx, &output) + return output, err +} diff --git a/shell_test.go b/shell_test.go index f2e2ece9f..5b3f62a33 100644 --- a/shell_test.go +++ b/shell_test.go @@ -552,3 +552,18 @@ func TestRefs(t *testing.T) { sort.Strings(actual) is.Equal(expected, actual) } + +func TestSwarmPeeringLs(t *testing.T) { + is := is.New(t) + s := NewShell(shellUrl) + _, err := s.SwarmPeeringLs(context.Background()) + is.Nil(err) +} + +func TestSwarmPeeringAdd(t *testing.T) { + is := is.New(t) + s := NewShell(shellUrl) + addr := fmt.Sprintf("/ip4/10.10.10.10/tcp/4001/p2p/%s", examplesHash) + _, err := s.SwarmPeeringAdd(context.Background(), addr) + is.Nil(err) +}