mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 13:04:02 +03:00
Add tags for ip blocklisted metric
This commit is contained in:
+16
-2
@@ -83,7 +83,8 @@ type EventConcurrencyLimited struct {
|
||||
type EventIPBlocklisted struct {
|
||||
eventBase
|
||||
|
||||
RemoteIP net.IP
|
||||
RemoteIP net.IP
|
||||
IsBlockList bool
|
||||
}
|
||||
|
||||
// EventReplayAttack is emitted when mtg detects a replay attack on a
|
||||
@@ -172,7 +173,20 @@ func NewEventIPBlocklisted(remoteIP net.IP) EventIPBlocklisted {
|
||||
eventBase: eventBase{
|
||||
timestamp: time.Now(),
|
||||
},
|
||||
RemoteIP: remoteIP,
|
||||
RemoteIP: remoteIP,
|
||||
IsBlockList: true,
|
||||
}
|
||||
}
|
||||
|
||||
// NewEventIPAllowlisted creates a NewEventIPBlocklisted event with a mark that
|
||||
// it is supposed to be for allow list.
|
||||
func NewEventIPAllowlisted(remoteIP net.IP) EventIPBlocklisted {
|
||||
return EventIPBlocklisted{
|
||||
eventBase: eventBase{
|
||||
timestamp: time.Now(),
|
||||
},
|
||||
RemoteIP: remoteIP,
|
||||
IsBlockList: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,15 @@ func (suite *EventsTestSuite) TestEventIPBlocklisted() {
|
||||
|
||||
suite.Empty(evt.StreamID())
|
||||
suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
|
||||
suite.True(evt.IsBlockList)
|
||||
}
|
||||
|
||||
func (suite *EventsTestSuite) TestEventIPAllowlisted() {
|
||||
evt := mtglib.NewEventIPAllowlisted(net.ParseIP("10.0.0.10"))
|
||||
|
||||
suite.Empty(evt.StreamID())
|
||||
suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
|
||||
suite.False(evt.IsBlockList)
|
||||
}
|
||||
|
||||
func (suite *EventsTestSuite) TestEventReplayAttack() {
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ func (p *Proxy) Serve(listener net.Listener) error {
|
||||
if !p.allowlist.Contains(ipAddr) {
|
||||
conn.Close()
|
||||
logger.Info("ip was rejected by allowlist")
|
||||
p.eventStream.Send(p.ctx, NewEventIPBlocklisted(ipAddr))
|
||||
p.eventStream.Send(p.ctx, NewEventIPAllowlisted(ipAddr))
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user