Commit 4ff4d356 authored by Andreas Bigger's avatar Andreas Bigger

fix formatting and lints

parent 9cbd2055
...@@ -30,17 +30,17 @@ var ( ...@@ -30,17 +30,17 @@ var (
Usage: "Sets the peer scoring strategy for the P2P stack. " + Usage: "Sets the peer scoring strategy for the P2P stack. " +
"Can be one of: none, light, full." + "Can be one of: none, light, full." +
"Custom scoring strategies can be defined in the config file.", "Custom scoring strategies can be defined in the config file.",
Required: false, Required: false,
Value: "none", Value: "none",
EnvVar: p2pEnv("PEER_SCORING"), EnvVar: p2pEnv("PEER_SCORING"),
} }
// Banning Flag - whether or not we want to act on the scoring // Banning Flag - whether or not we want to act on the scoring
Banning = cli.BoolFlag{ Banning = cli.BoolFlag{
Name: "p2p.ban.peers", Name: "p2p.ban.peers",
Usage: "Enables peer banning. This should ONLY be enabled once certain peer scoring is working correctly.", Usage: "Enables peer banning. This should ONLY be enabled once certain peer scoring is working correctly.",
Required: false, Required: false,
EnvVar: p2pEnv("PEER_BANNING"), EnvVar: p2pEnv("PEER_BANNING"),
} }
TopicScoring = cli.StringFlag{ TopicScoring = cli.StringFlag{
...@@ -48,9 +48,9 @@ var ( ...@@ -48,9 +48,9 @@ var (
Usage: "Sets the topic scoring strategy. " + Usage: "Sets the topic scoring strategy. " +
"Can be one of: none, light, full." + "Can be one of: none, light, full." +
"Custom scoring strategies can be defined in the config file.", "Custom scoring strategies can be defined in the config file.",
Required: false, Required: false,
Value: "none", Value: "none",
EnvVar: p2pEnv("TOPIC_SCORING"), EnvVar: p2pEnv("TOPIC_SCORING"),
} }
P2PPrivPath = cli.StringFlag{ P2PPrivPath = cli.StringFlag{
Name: "p2p.priv.path", Name: "p2p.priv.path",
......
...@@ -336,8 +336,6 @@ func parsePriv(data string) (*crypto.Secp256k1PrivateKey, error) { ...@@ -336,8 +336,6 @@ func parsePriv(data string) (*crypto.Secp256k1PrivateKey, error) {
return (p).(*crypto.Secp256k1PrivateKey), nil return (p).(*crypto.Secp256k1PrivateKey), nil
} }
func loadGossipOptions(conf *p2p.Config, ctx *cli.Context) error { func loadGossipOptions(conf *p2p.Config, ctx *cli.Context) error {
conf.MeshD = ctx.GlobalInt(flags.GossipMeshDFlag.Name) conf.MeshD = ctx.GlobalInt(flags.GossipMeshDFlag.Name)
conf.MeshDLo = ctx.GlobalInt(flags.GossipMeshDloFlag.Name) conf.MeshDLo = ctx.GlobalInt(flags.GossipMeshDloFlag.Name)
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enode"
ds "github.com/ipfs/go-datastore" ds "github.com/ipfs/go-datastore"
"github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core" "github.com/libp2p/go-libp2p/core"
"github.com/libp2p/go-libp2p/core/connmgr" "github.com/libp2p/go-libp2p/core/connmgr"
"github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/crypto"
...@@ -19,7 +20,6 @@ import ( ...@@ -19,7 +20,6 @@ import (
"github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/p2p/net/conngater" "github.com/libp2p/go-libp2p/p2p/net/conngater"
cmgr "github.com/libp2p/go-libp2p/p2p/net/connmgr" cmgr "github.com/libp2p/go-libp2p/p2p/net/connmgr"
pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/ethereum-optimism/optimism/op-node/rollup" "github.com/ethereum-optimism/optimism/op-node/rollup"
) )
...@@ -51,7 +51,7 @@ type Config struct { ...@@ -51,7 +51,7 @@ type Config struct {
NoDiscovery bool NoDiscovery bool
// Pubsub Scoring Parameters // Pubsub Scoring Parameters
PeerScoring pubsub.PeerScoreParams PeerScoring pubsub.PeerScoreParams
TopicScoring pubsub.TopicScoreParams TopicScoring pubsub.TopicScoreParams
// Whether to ban peers based on their [PeerScoring] score. // Whether to ban peers based on their [PeerScoring] score.
......
...@@ -168,7 +168,7 @@ func TestP2PFull(t *testing.T) { ...@@ -168,7 +168,7 @@ func TestP2PFull(t *testing.T) {
_, err = p2pClientA.DiscoveryTable(ctx) _, err = p2pClientA.DiscoveryTable(ctx)
// rpc does not preserve error type // rpc does not preserve error type
require.Equal(t, err.Error(), DisabledDiscovery.Error(), "expecting discv5 to be disabled") require.Equal(t, err.Error(), ErrDisabledDiscovery.Error(), "expecting discv5 to be disabled")
require.NoError(t, p2pClientA.BlockPeer(ctx, hostB.ID())) require.NoError(t, p2pClientA.BlockPeer(ctx, hostB.ID()))
blockedPeers, err := p2pClientA.ListBlockedPeers(ctx) blockedPeers, err := p2pClientA.ListBlockedPeers(ctx)
......
...@@ -76,7 +76,6 @@ func (n *NodeP2P) init(resourcesCtx context.Context, rollupCfg *rollup.Config, l ...@@ -76,7 +76,6 @@ func (n *NodeP2P) init(resourcesCtx context.Context, rollupCfg *rollup.Config, l
// notify of any new connections/streams/etc. // notify of any new connections/streams/etc.
n.host.Network().Notify(NewNetworkNotifier(log, metrics)) n.host.Network().Notify(NewNetworkNotifier(log, metrics))
// note: the IDDelta functionality was removed from libP2P, and no longer needs to be explicitly disabled. // note: the IDDelta functionality was removed from libP2P, and no longer needs to be explicitly disabled.
fmt.Printf("Constructing gossip sub...\n")
n.gs, err = NewGossipSub(resourcesCtx, n.host, n.gater, rollupCfg, setup, metrics, log) n.gs, err = NewGossipSub(resourcesCtx, n.host, n.gater, rollupCfg, setup, metrics, log)
if err != nil { if err != nil {
return fmt.Errorf("failed to start gossipsub router: %w", err) return fmt.Errorf("failed to start gossipsub router: %w", err)
......
package p2p package p2p
import ( import (
slices "golang.org/x/exp/slices"
log "github.com/ethereum/go-ethereum/log" log "github.com/ethereum/go-ethereum/log"
peer "github.com/libp2p/go-libp2p/core/peer" peer "github.com/libp2p/go-libp2p/core/peer"
slices "golang.org/x/exp/slices"
) )
// ConnectionFactor is the factor by which we multiply the connection score. // ConnectionFactor is the factor by which we multiply the connection score.
...@@ -14,8 +14,8 @@ const PeerScoreThreshold = -100 ...@@ -14,8 +14,8 @@ const PeerScoreThreshold = -100
// gater is an internal implementation of the [PeerGater] interface. // gater is an internal implementation of the [PeerGater] interface.
type gater struct { type gater struct {
connGater ConnectionGater connGater ConnectionGater
log log.Logger log log.Logger
banEnabled bool banEnabled bool
} }
...@@ -30,8 +30,8 @@ type PeerGater interface { ...@@ -30,8 +30,8 @@ type PeerGater interface {
// NewPeerGater returns a new peer gater. // NewPeerGater returns a new peer gater.
func NewPeerGater(connGater ConnectionGater, log log.Logger, banEnabled bool) PeerGater { func NewPeerGater(connGater ConnectionGater, log log.Logger, banEnabled bool) PeerGater {
return &gater{ return &gater{
connGater: connGater, connGater: connGater,
log: log, log: log,
banEnabled: banEnabled, banEnabled: banEnabled,
} }
} }
......
...@@ -3,12 +3,12 @@ package p2p_test ...@@ -3,12 +3,12 @@ package p2p_test
import ( import (
"testing" "testing"
peer "github.com/libp2p/go-libp2p/core/peer" node "github.com/ethereum-optimism/optimism/op-node/node"
p2p "github.com/ethereum-optimism/optimism/op-node/p2p" p2p "github.com/ethereum-optimism/optimism/op-node/p2p"
p2pMocks "github.com/ethereum-optimism/optimism/op-node/p2p/mocks"
log "github.com/ethereum/go-ethereum/log" log "github.com/ethereum/go-ethereum/log"
node "github.com/ethereum-optimism/optimism/op-node/node" peer "github.com/libp2p/go-libp2p/core/peer"
suite "github.com/stretchr/testify/suite" suite "github.com/stretchr/testify/suite"
p2pMocks "github.com/ethereum-optimism/optimism/op-node/p2p/mocks"
) )
// PeerGaterTestSuite tests peer parameterization. // PeerGaterTestSuite tests peer parameterization.
...@@ -16,7 +16,7 @@ type PeerGaterTestSuite struct { ...@@ -16,7 +16,7 @@ type PeerGaterTestSuite struct {
suite.Suite suite.Suite
mockGater *p2pMocks.ConnectionGater mockGater *p2pMocks.ConnectionGater
logger log.Logger logger log.Logger
} }
// SetupTest sets up the test suite. // SetupTest sets up the test suite.
...@@ -65,4 +65,3 @@ func (testSuite *PeerGaterTestSuite) TestPeerGaterUpdateNoBanning() { ...@@ -65,4 +65,3 @@ func (testSuite *PeerGaterTestSuite) TestPeerGaterUpdateNoBanning() {
// Notice: [BlockPeer] should not be called since banning is not enabled // Notice: [BlockPeer] should not be called since banning is not enabled
gater.Update(peer.ID("peer1"), float64(-100000)) gater.Update(peer.ID("peer1"), float64(-100000))
} }
...@@ -87,8 +87,8 @@ var DisabledPeerScoreParams = func(blockTime uint64) pubsub.PeerScoreParams { ...@@ -87,8 +87,8 @@ var DisabledPeerScoreParams = func(blockTime uint64) pubsub.PeerScoreParams {
// PeerScoreParamsByName is a map of name to function that returns a [pubsub.PeerScoreParams] based on the provided [rollup.Config]. // PeerScoreParamsByName is a map of name to function that returns a [pubsub.PeerScoreParams] based on the provided [rollup.Config].
var PeerScoreParamsByName = map[string](func(blockTime uint64) pubsub.PeerScoreParams){ var PeerScoreParamsByName = map[string](func(blockTime uint64) pubsub.PeerScoreParams){
"light": LightPeerScoreParams, "light": LightPeerScoreParams,
"none": DisabledPeerScoreParams, "none": DisabledPeerScoreParams,
} }
// AvailablePeerScoreParams returns a list of available peer score params. // AvailablePeerScoreParams returns a list of available peer score params.
......
package p2p package p2p
import ( import (
"sort"
"math" "math"
"time" "sort"
"testing" "testing"
"time"
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
...@@ -55,13 +55,13 @@ func (testSuite *PeerParamsTestSuite) TestGetPeerScoreParams() { ...@@ -55,13 +55,13 @@ func (testSuite *PeerParamsTestSuite) TestGetPeerScoreParams() {
testSuite.NoError(err) testSuite.NoError(err)
expected := LightPeerScoreParams(1) expected := LightPeerScoreParams(1)
testSuite.Equal(expected.DecayInterval, params.DecayInterval) testSuite.Equal(expected.DecayInterval, params.DecayInterval)
testSuite.Equal(time.Duration(1) * time.Second, params.DecayInterval) testSuite.Equal(time.Duration(1)*time.Second, params.DecayInterval)
params, err = GetPeerScoreParams("none", 1) params, err = GetPeerScoreParams("none", 1)
testSuite.NoError(err) testSuite.NoError(err)
expected = DisabledPeerScoreParams(1) expected = DisabledPeerScoreParams(1)
testSuite.Equal(expected.DecayInterval, params.DecayInterval) testSuite.Equal(expected.DecayInterval, params.DecayInterval)
testSuite.Equal(time.Duration(1) * time.Second, params.DecayInterval) testSuite.Equal(time.Duration(1)*time.Second, params.DecayInterval)
_, err = GetPeerScoreParams("invalid", 1) _, err = GetPeerScoreParams("invalid", 1)
testSuite.Error(err) testSuite.Error(err)
...@@ -76,7 +76,7 @@ func (testSuite *PeerParamsTestSuite) TestLightPeerScoreParams() { ...@@ -76,7 +76,7 @@ func (testSuite *PeerParamsTestSuite) TestLightPeerScoreParams() {
// calculate the behavior penalty decay // calculate the behavior penalty decay
duration := 10 * epoch duration := 10 * epoch
decay := math.Pow(DecayToZero, 1 / float64(duration / slot)) decay := math.Pow(DecayToZero, 1/float64(duration/slot))
testSuite.Equal(0.9261187281287935, decay) testSuite.Equal(0.9261187281287935, decay)
// Test the params // Test the params
...@@ -106,7 +106,7 @@ func (testSuite *PeerParamsTestSuite) TestDisabledPeerScoreParams() { ...@@ -106,7 +106,7 @@ func (testSuite *PeerParamsTestSuite) TestDisabledPeerScoreParams() {
// calculate the behavior penalty decay // calculate the behavior penalty decay
duration := 10 * epoch duration := 10 * epoch
decay := math.Pow(DecayToZero, 1 / float64(duration / slot)) decay := math.Pow(DecayToZero, 1/float64(duration/slot))
testSuite.Equal(0.9261187281287935, decay) testSuite.Equal(0.9261187281287935, decay)
// Test the params // Test the params
......
...@@ -2,8 +2,8 @@ package p2p ...@@ -2,8 +2,8 @@ package p2p
import ( import (
log "github.com/ethereum/go-ethereum/log" log "github.com/ethereum/go-ethereum/log"
peer "github.com/libp2p/go-libp2p/core/peer"
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
peer "github.com/libp2p/go-libp2p/core/peer"
) )
type scorer struct { type scorer struct {
......
...@@ -3,13 +3,13 @@ package p2p_test ...@@ -3,13 +3,13 @@ package p2p_test
import ( import (
"testing" "testing"
peer "github.com/libp2p/go-libp2p/core/peer" node "github.com/ethereum-optimism/optimism/op-node/node"
pubsub "github.com/libp2p/go-libp2p-pubsub"
p2p "github.com/ethereum-optimism/optimism/op-node/p2p" p2p "github.com/ethereum-optimism/optimism/op-node/p2p"
p2pMocks "github.com/ethereum-optimism/optimism/op-node/p2p/mocks"
log "github.com/ethereum/go-ethereum/log" log "github.com/ethereum/go-ethereum/log"
node "github.com/ethereum-optimism/optimism/op-node/node" pubsub "github.com/libp2p/go-libp2p-pubsub"
peer "github.com/libp2p/go-libp2p/core/peer"
suite "github.com/stretchr/testify/suite" suite "github.com/stretchr/testify/suite"
p2pMocks "github.com/ethereum-optimism/optimism/op-node/p2p/mocks"
) )
// PeerScorerTestSuite tests peer parameterization. // PeerScorerTestSuite tests peer parameterization.
...@@ -17,10 +17,10 @@ type PeerScorerTestSuite struct { ...@@ -17,10 +17,10 @@ type PeerScorerTestSuite struct {
suite.Suite suite.Suite
// mockConnGater *p2pMocks.ConnectionGater // mockConnGater *p2pMocks.ConnectionGater
mockGater *p2pMocks.PeerGater mockGater *p2pMocks.PeerGater
mockStore *p2pMocks.Peerstore mockStore *p2pMocks.Peerstore
mockMetricer *p2pMocks.GossipMetricer mockMetricer *p2pMocks.GossipMetricer
logger log.Logger logger log.Logger
} }
// SetupTest sets up the test suite. // SetupTest sets up the test suite.
...@@ -79,7 +79,7 @@ func (testSuite *PeerScorerTestSuite) TestSnapshotHook() { ...@@ -79,7 +79,7 @@ func (testSuite *PeerScorerTestSuite) TestSnapshotHook() {
// Apply the snapshot // Apply the snapshot
snapshotMap := map[peer.ID]*pubsub.PeerScoreSnapshot{ snapshotMap := map[peer.ID]*pubsub.PeerScoreSnapshot{
peer.ID("peer1"): &pubsub.PeerScoreSnapshot{ peer.ID("peer1"): {
Score: -100, Score: -100,
}, },
} }
...@@ -106,7 +106,7 @@ func (testSuite *PeerScorerTestSuite) TestSnapshotHookBlockPeer() { ...@@ -106,7 +106,7 @@ func (testSuite *PeerScorerTestSuite) TestSnapshotHookBlockPeer() {
// Apply the snapshot // Apply the snapshot
snapshotMap := map[peer.ID]*pubsub.PeerScoreSnapshot{ snapshotMap := map[peer.ID]*pubsub.PeerScoreSnapshot{
peer.ID("peer1"): &pubsub.PeerScoreSnapshot{ peer.ID("peer1"): {
Score: -101, Score: -101,
}, },
} }
......
package p2p_test package p2p_test
import ( import (
"context"
"fmt" "fmt"
"time"
"math/rand" "math/rand"
"context"
"testing" "testing"
"time"
p2p "github.com/ethereum-optimism/optimism/op-node/p2p"
node "github.com/ethereum-optimism/optimism/op-node/node" node "github.com/ethereum-optimism/optimism/op-node/node"
testlog "github.com/ethereum-optimism/optimism/op-node/testlog" p2p "github.com/ethereum-optimism/optimism/op-node/p2p"
p2pMocks "github.com/ethereum-optimism/optimism/op-node/p2p/mocks" p2pMocks "github.com/ethereum-optimism/optimism/op-node/p2p/mocks"
testlog "github.com/ethereum-optimism/optimism/op-node/testlog"
mock "github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
suite "github.com/stretchr/testify/suite" suite "github.com/stretchr/testify/suite"
log "github.com/ethereum/go-ethereum/log" log "github.com/ethereum/go-ethereum/log"
peer "github.com/libp2p/go-libp2p/core/peer"
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
host "github.com/libp2p/go-libp2p/core/host" host "github.com/libp2p/go-libp2p/core/host"
peer "github.com/libp2p/go-libp2p/core/peer"
bhost "github.com/libp2p/go-libp2p/p2p/host/blank" bhost "github.com/libp2p/go-libp2p/p2p/host/blank"
tswarm "github.com/libp2p/go-libp2p/p2p/net/swarm/testing" tswarm "github.com/libp2p/go-libp2p/p2p/net/swarm/testing"
) )
...@@ -28,10 +28,10 @@ import ( ...@@ -28,10 +28,10 @@ import (
type PeerScoresTestSuite struct { type PeerScoresTestSuite struct {
suite.Suite suite.Suite
mockGater *p2pMocks.ConnectionGater mockGater *p2pMocks.ConnectionGater
mockStore *p2pMocks.Peerstore mockStore *p2pMocks.Peerstore
mockMetricer *p2pMocks.GossipMetricer mockMetricer *p2pMocks.GossipMetricer
logger log.Logger logger log.Logger
} }
// SetupTest sets up the test suite. // SetupTest sets up the test suite.
...@@ -139,7 +139,9 @@ func (testSuite *PeerScoresTestSuite) TestNegativeScores() { ...@@ -139,7 +139,9 @@ func (testSuite *PeerScoresTestSuite) TestNegativeScores() {
// Create subscriptions // Create subscriptions
var subs []*pubsub.Subscription var subs []*pubsub.Subscription
for _, ps := range pubsubs { for _, ps := range pubsubs {
sub, err := ps.Subscribe("test") topic, err := ps.Join("test")
testSuite.NoError(err)
sub, err := topic.Subscribe()
testSuite.NoError(err) testSuite.NoError(err)
subs = append(subs, sub) subs = append(subs, sub)
} }
...@@ -148,7 +150,10 @@ func (testSuite *PeerScoresTestSuite) TestNegativeScores() { ...@@ -148,7 +150,10 @@ func (testSuite *PeerScoresTestSuite) TestNegativeScores() {
time.Sleep(3 * time.Second) time.Sleep(3 * time.Second)
for i := 0; i < 20; i++ { for i := 0; i < 20; i++ {
msg := []byte(fmt.Sprintf("message %d", i)) msg := []byte(fmt.Sprintf("message %d", i))
pubsubs[i%20].Publish("test", msg) topic, err := pubsubs[i%20].Join("test")
testSuite.NoError(err)
err = topic.Publish(ctx, msg)
testSuite.NoError(err)
time.Sleep(20 * time.Millisecond) time.Sleep(20 * time.Millisecond)
} }
...@@ -158,7 +163,7 @@ func (testSuite *PeerScoresTestSuite) TestNegativeScores() { ...@@ -158,7 +163,7 @@ func (testSuite *PeerScoresTestSuite) TestNegativeScores() {
// Collects all messages from a subscription // Collects all messages from a subscription
collectAll := func(sub *pubsub.Subscription) []*pubsub.Message { collectAll := func(sub *pubsub.Subscription) []*pubsub.Message {
var res []*pubsub.Message var res []*pubsub.Message
ctx, cancel := context.WithTimeout(context.Background(), 100 * time.Millisecond) ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel() defer cancel()
for { for {
msg, err := sub.Next(ctx) msg, err := sub.Next(ctx)
...@@ -182,6 +187,4 @@ func (testSuite *PeerScoresTestSuite) TestNegativeScores() { ...@@ -182,6 +187,4 @@ func (testSuite *PeerScoresTestSuite) TestNegativeScores() {
testSuite.NotEqual(hosts[0].ID(), m.ReceivedFrom) testSuite.NotEqual(hosts[0].ID(), m.ReceivedFrom)
} }
} }
} }
...@@ -30,9 +30,9 @@ import ( ...@@ -30,9 +30,9 @@ import (
// - banning peers based on score // - banning peers based on score
var ( var (
DisabledDiscovery = errors.New("discovery disabled") ErrDisabledDiscovery = errors.New("discovery disabled")
NoConnectionManager = errors.New("no connection manager") ErrNoConnectionManager = errors.New("no connection manager")
NoConnectionGater = errors.New("no connection gater") ErrNoConnectionGater = errors.New("no connection gater")
) )
type Node interface { type Node interface {
...@@ -236,7 +236,7 @@ func (s *APIBackend) DiscoveryTable(_ context.Context) ([]*enode.Node, error) { ...@@ -236,7 +236,7 @@ func (s *APIBackend) DiscoveryTable(_ context.Context) ([]*enode.Node, error) {
if dv5 := s.node.Dv5Udp(); dv5 != nil { if dv5 := s.node.Dv5Udp(); dv5 != nil {
return dv5.AllNodes(), nil return dv5.AllNodes(), nil
} else { } else {
return nil, DisabledDiscovery return nil, ErrDisabledDiscovery
} }
} }
...@@ -244,7 +244,7 @@ func (s *APIBackend) BlockPeer(_ context.Context, p peer.ID) error { ...@@ -244,7 +244,7 @@ func (s *APIBackend) BlockPeer(_ context.Context, p peer.ID) error {
recordDur := s.m.RecordRPCServerRequest("opp2p_blockPeer") recordDur := s.m.RecordRPCServerRequest("opp2p_blockPeer")
defer recordDur() defer recordDur()
if gater := s.node.ConnectionGater(); gater == nil { if gater := s.node.ConnectionGater(); gater == nil {
return NoConnectionGater return ErrNoConnectionGater
} else { } else {
return gater.BlockPeer(p) return gater.BlockPeer(p)
} }
...@@ -254,7 +254,7 @@ func (s *APIBackend) UnblockPeer(_ context.Context, p peer.ID) error { ...@@ -254,7 +254,7 @@ func (s *APIBackend) UnblockPeer(_ context.Context, p peer.ID) error {
recordDur := s.m.RecordRPCServerRequest("opp2p_unblockPeer") recordDur := s.m.RecordRPCServerRequest("opp2p_unblockPeer")
defer recordDur() defer recordDur()
if gater := s.node.ConnectionGater(); gater == nil { if gater := s.node.ConnectionGater(); gater == nil {
return NoConnectionGater return ErrNoConnectionGater
} else { } else {
return gater.UnblockPeer(p) return gater.UnblockPeer(p)
} }
...@@ -264,7 +264,7 @@ func (s *APIBackend) ListBlockedPeers(_ context.Context) ([]peer.ID, error) { ...@@ -264,7 +264,7 @@ func (s *APIBackend) ListBlockedPeers(_ context.Context) ([]peer.ID, error) {
recordDur := s.m.RecordRPCServerRequest("opp2p_listBlockedPeers") recordDur := s.m.RecordRPCServerRequest("opp2p_listBlockedPeers")
defer recordDur() defer recordDur()
if gater := s.node.ConnectionGater(); gater == nil { if gater := s.node.ConnectionGater(); gater == nil {
return nil, NoConnectionGater return nil, ErrNoConnectionGater
} else { } else {
return gater.ListBlockedPeers(), nil return gater.ListBlockedPeers(), nil
} }
...@@ -276,7 +276,7 @@ func (s *APIBackend) BlockAddr(_ context.Context, ip net.IP) error { ...@@ -276,7 +276,7 @@ func (s *APIBackend) BlockAddr(_ context.Context, ip net.IP) error {
recordDur := s.m.RecordRPCServerRequest("opp2p_blockAddr") recordDur := s.m.RecordRPCServerRequest("opp2p_blockAddr")
defer recordDur() defer recordDur()
if gater := s.node.ConnectionGater(); gater == nil { if gater := s.node.ConnectionGater(); gater == nil {
return NoConnectionGater return ErrNoConnectionGater
} else { } else {
return gater.BlockAddr(ip) return gater.BlockAddr(ip)
} }
...@@ -286,7 +286,7 @@ func (s *APIBackend) UnblockAddr(_ context.Context, ip net.IP) error { ...@@ -286,7 +286,7 @@ func (s *APIBackend) UnblockAddr(_ context.Context, ip net.IP) error {
recordDur := s.m.RecordRPCServerRequest("opp2p_unblockAddr") recordDur := s.m.RecordRPCServerRequest("opp2p_unblockAddr")
defer recordDur() defer recordDur()
if gater := s.node.ConnectionGater(); gater == nil { if gater := s.node.ConnectionGater(); gater == nil {
return NoConnectionGater return ErrNoConnectionGater
} else { } else {
return gater.UnblockAddr(ip) return gater.UnblockAddr(ip)
} }
...@@ -296,7 +296,7 @@ func (s *APIBackend) ListBlockedAddrs(_ context.Context) ([]net.IP, error) { ...@@ -296,7 +296,7 @@ func (s *APIBackend) ListBlockedAddrs(_ context.Context) ([]net.IP, error) {
recordDur := s.m.RecordRPCServerRequest("opp2p_listBlockedAddrs") recordDur := s.m.RecordRPCServerRequest("opp2p_listBlockedAddrs")
defer recordDur() defer recordDur()
if gater := s.node.ConnectionGater(); gater == nil { if gater := s.node.ConnectionGater(); gater == nil {
return nil, NoConnectionGater return nil, ErrNoConnectionGater
} else { } else {
return gater.ListBlockedAddrs(), nil return gater.ListBlockedAddrs(), nil
} }
...@@ -308,7 +308,7 @@ func (s *APIBackend) BlockSubnet(_ context.Context, ipnet *net.IPNet) error { ...@@ -308,7 +308,7 @@ func (s *APIBackend) BlockSubnet(_ context.Context, ipnet *net.IPNet) error {
recordDur := s.m.RecordRPCServerRequest("opp2p_blockSubnet") recordDur := s.m.RecordRPCServerRequest("opp2p_blockSubnet")
defer recordDur() defer recordDur()
if gater := s.node.ConnectionGater(); gater == nil { if gater := s.node.ConnectionGater(); gater == nil {
return NoConnectionGater return ErrNoConnectionGater
} else { } else {
return gater.BlockSubnet(ipnet) return gater.BlockSubnet(ipnet)
} }
...@@ -318,7 +318,7 @@ func (s *APIBackend) UnblockSubnet(_ context.Context, ipnet *net.IPNet) error { ...@@ -318,7 +318,7 @@ func (s *APIBackend) UnblockSubnet(_ context.Context, ipnet *net.IPNet) error {
recordDur := s.m.RecordRPCServerRequest("opp2p_unblockSubnet") recordDur := s.m.RecordRPCServerRequest("opp2p_unblockSubnet")
defer recordDur() defer recordDur()
if gater := s.node.ConnectionGater(); gater == nil { if gater := s.node.ConnectionGater(); gater == nil {
return NoConnectionGater return ErrNoConnectionGater
} else { } else {
return gater.UnblockSubnet(ipnet) return gater.UnblockSubnet(ipnet)
} }
...@@ -328,7 +328,7 @@ func (s *APIBackend) ListBlockedSubnets(_ context.Context) ([]*net.IPNet, error) ...@@ -328,7 +328,7 @@ func (s *APIBackend) ListBlockedSubnets(_ context.Context) ([]*net.IPNet, error)
recordDur := s.m.RecordRPCServerRequest("opp2p_listBlockedSubnets") recordDur := s.m.RecordRPCServerRequest("opp2p_listBlockedSubnets")
defer recordDur() defer recordDur()
if gater := s.node.ConnectionGater(); gater == nil { if gater := s.node.ConnectionGater(); gater == nil {
return nil, NoConnectionGater return nil, ErrNoConnectionGater
} else { } else {
return gater.ListBlockedSubnets(), nil return gater.ListBlockedSubnets(), nil
} }
...@@ -338,7 +338,7 @@ func (s *APIBackend) ProtectPeer(_ context.Context, p peer.ID) error { ...@@ -338,7 +338,7 @@ func (s *APIBackend) ProtectPeer(_ context.Context, p peer.ID) error {
recordDur := s.m.RecordRPCServerRequest("opp2p_protectPeer") recordDur := s.m.RecordRPCServerRequest("opp2p_protectPeer")
defer recordDur() defer recordDur()
if manager := s.node.ConnectionManager(); manager == nil { if manager := s.node.ConnectionManager(); manager == nil {
return NoConnectionManager return ErrNoConnectionManager
} else { } else {
manager.Protect(p, "api-protected") manager.Protect(p, "api-protected")
return nil return nil
...@@ -349,7 +349,7 @@ func (s *APIBackend) UnprotectPeer(_ context.Context, p peer.ID) error { ...@@ -349,7 +349,7 @@ func (s *APIBackend) UnprotectPeer(_ context.Context, p peer.ID) error {
recordDur := s.m.RecordRPCServerRequest("opp2p_unprotectPeer") recordDur := s.m.RecordRPCServerRequest("opp2p_unprotectPeer")
defer recordDur() defer recordDur()
if manager := s.node.ConnectionManager(); manager == nil { if manager := s.node.ConnectionManager(); manager == nil {
return NoConnectionManager return ErrNoConnectionManager
} else { } else {
manager.Unprotect(p, "api-protected") manager.Unprotect(p, "api-protected")
return nil return nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment