Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Add ls and add swarming commands #270

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
15 changes: 15 additions & 0 deletions shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}