diff --git a/core/commands/swarm.go b/core/commands/swarm.go index 252c48d33..e28cff2aa 100644 --- a/core/commands/swarm.go +++ b/core/commands/swarm.go @@ -724,6 +724,10 @@ it will reconnect. return err } + if req.Arguments[0] == "blockAll" { + return api.Swarm().BlockAll(req.Context) + } + addrs, err := parseAddresses(req.Context, req.Arguments, node.DNSResolver) if err != nil { return err diff --git a/core/coreapi/swarm.go b/core/coreapi/swarm.go index e5332a217..cb7e7c22a 100644 --- a/core/coreapi/swarm.go +++ b/core/coreapi/swarm.go @@ -2,6 +2,8 @@ package coreapi import ( "context" + "fmt" + "runtime" "sort" "time" @@ -167,6 +169,13 @@ func (api *SwarmAPI) Peers(ctx context.Context) ([]coreiface.ConnectionInfo, err return out, nil } +func (api *SwarmAPI) BlockAll(ctx context.Context) error { + fmt.Println("blocking all connections") + api.peerHost.Network().(interface{ BlockAll() }).BlockAll() + runtime.GC() + return nil +} + func (ci *connInfo) ID() peer.ID { return ci.peer } diff --git a/core/coreiface/swarm.go b/core/coreiface/swarm.go index 9aa5466ba..52fafde1a 100644 --- a/core/coreiface/swarm.go +++ b/core/coreiface/swarm.go @@ -54,4 +54,6 @@ type SwarmAPI interface { // ListenAddrs returns the list of all listening addresses ListenAddrs(context.Context) ([]ma.Multiaddr, error) + + BlockAll(context.Context) error } diff --git a/go.mod b/go.mod index f9cefd504..eab7839cf 100644 --- a/go.mod +++ b/go.mod @@ -274,3 +274,5 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.3.0 // indirect ) + +replace github.com/libp2p/go-libp2p => ../go-libp2p