Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): add firewall module to logger config #1637

Merged
merged 2 commits into from
Dec 7, 2024
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
1 change: 1 addition & 0 deletions config/example_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
# 'trace', 'debug', 'info', 'warn', and 'error'.
[logger.levels]
_consensus = 'warn'
_firewall = 'warn'
_grpc = 'info'
_http = 'info'
_jsonrpc = 'info'
Expand Down
3 changes: 1 addition & 2 deletions sync/firewall/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type Firewall struct {
}

func NewFirewall(conf *Config, network network.Network, peerSet *peerset.PeerSet, state state.Facade,
log *logger.SubLogger,
) (*Firewall, error) {
blocker, err := ipblocker.New(conf.BannedNets)
if err != nil {
Expand All @@ -52,7 +51,7 @@ func NewFirewall(conf *Config, network network.Network, peerSet *peerset.PeerSet
blockRateLimit: blockRateLimit,
transactionRateLimit: transactionRateLimit,
consensusRateLimit: consensusRateLimit,
logger: log,
logger: logger.NewSubLogger("_firewall", nil),
}, nil
}

Expand Down
4 changes: 1 addition & 3 deletions sync/firewall/firewall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/pactus-project/pactus/sync/peerset/peer"
"github.com/pactus-project/pactus/sync/peerset/peer/status"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/util/logger"
"github.com/pactus-project/pactus/util/testsuite"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -36,7 +35,6 @@ func setup(t *testing.T, conf *Config) *testData {

ts := testsuite.NewTestSuite(t)

subLogger := logger.NewSubLogger("firewall", nil)
peerSet := peerset.NewPeerSet(1 * time.Minute)
state := state.MockingState(ts)
net := network.MockingNetwork(ts, ts.RandPeerID())
Expand All @@ -45,7 +43,7 @@ func setup(t *testing.T, conf *Config) *testData {
conf = DefaultConfig()
}
require.NoError(t, conf.BasicCheck())
firewall, err := NewFirewall(conf, net, peerSet, state, subLogger)
firewall, err := NewFirewall(conf, net, peerSet, state)
if err != nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func NewSynchronizer(

sync.peerSet = peerset.NewPeerSet(conf.SessionTimeout())
sync.logger = logger.NewSubLogger("_sync", sync)
fw, err := firewall.NewFirewall(conf.Firewall, network, sync.peerSet, state, sync.logger)
fw, err := firewall.NewFirewall(conf.Firewall, network, sync.peerSet, state)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func TestMain(m *testing.M) {
tConfigs[i].Logger.Levels["_consensus"] = "info"
tConfigs[i].Logger.Levels["_network"] = "info"
tConfigs[i].Logger.Levels["_pool"] = "info"
tConfigs[i].Logger.Levels["_firewall"] = "info"
tConfigs[i].Sync.Firewall.BannedNets = make([]string, 0)
tConfigs[i].Sync.BlockPerSession = 10
tConfigs[i].Network.EnableMdns = true
Expand Down
1 change: 1 addition & 0 deletions util/logger/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func DefaultConfig() *Config {
conf.Levels["_grpc"] = "info"
conf.Levels["_nonomsg"] = "info"
conf.Levels["_jsonrpc"] = "info"
conf.Levels["_firewall"] = "warn"

return conf
}
Expand Down
1 change: 1 addition & 0 deletions util/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func getLoggersInst() *logger {
conf.Levels["_pool"] = "debug"
conf.Levels["_http"] = "debug"
conf.Levels["_grpc"] = "debug"
conf.Levels["_firewall"] = "debug"
globalInst = &logger{
config: conf,
subs: make(map[string]*SubLogger),
Expand Down
Loading