mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 03:44:01 +03:00
Add EventIPBlocklisted
This commit is contained in:
@@ -31,3 +31,12 @@ type EventConcurrencyLimited struct {
|
||||
func (e EventConcurrencyLimited) StreamID() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
type EventIPBlocklisted struct {
|
||||
CreatedAt time.Time
|
||||
RemoteIP net.IP
|
||||
}
|
||||
|
||||
func (e EventIPBlocklisted) StreamID() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ func (suite *EventsTestSuite) TestEventConcurrencyLimited() {
|
||||
suite.Empty(mtglib.EventConcurrencyLimited{}.StreamID())
|
||||
}
|
||||
|
||||
func (suite *EventsTestSuite) TestEventIPBlocklisted() {
|
||||
suite.Empty(mtglib.EventIPBlocklisted{}.StreamID())
|
||||
}
|
||||
|
||||
func TestEvents(t *testing.T) {
|
||||
t.Parallel()
|
||||
suite.Run(t, &EventsTestSuite{})
|
||||
|
||||
@@ -52,6 +52,16 @@ func (p *Proxy) Serve(listener net.Listener) error {
|
||||
return fmt.Errorf("cannot accept a new connection: %w", err)
|
||||
}
|
||||
|
||||
if addr := conn.RemoteAddr().(*net.TCPAddr).IP; p.ipBlocklist.Contains(addr) {
|
||||
conn.Close()
|
||||
p.eventStream.Send(p.ctx, EventIPBlocklisted{
|
||||
CreatedAt: time.Now(),
|
||||
RemoteIP: addr,
|
||||
})
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
err = p.workerPool.Invoke(conn)
|
||||
|
||||
switch {
|
||||
|
||||
Reference in New Issue
Block a user