block swarm

This commit is contained in:
sukun 2024-12-10 18:00:05 +05:30
parent 19dc712498
commit 08ff5f4872
No known key found for this signature in database
4 changed files with 17 additions and 0 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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
}

2
go.mod
View File

@ -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