1
0
Fork 0
forked from External/grumble

Add support for ban expiry.

This commit is contained in:
Mikkel Krautz 2011-11-12 22:07:11 +01:00
parent 0fde3b9ae9
commit 2751c1824e

View file

@ -1133,6 +1133,27 @@ func (server *Server) RemoveChannel(channel *Channel) {
} }
} }
// Remove expired bans
func (server *Server) RemoveExpiredBans() {
server.banlock.Lock()
defer server.banlock.Unlock()
newBans := []ban.Ban{}
update := false
for _, ban := range server.Bans {
if !ban.IsExpired() {
newBans = append(newBans, ban)
} else {
update = true
}
}
if update {
server.Bans = newBans
server.UpdateFrozenBans(server.Bans)
}
}
// Is the incoming connection conn banned? // Is the incoming connection conn banned?
func (server *Server) IsBanned(conn net.Conn) bool { func (server *Server) IsBanned(conn net.Conn) bool {
server.banlock.RLock() server.banlock.RLock()
@ -1173,8 +1194,10 @@ func (server *Server) acceptLoop() {
} }
} }
// Remove expired bans
server.RemoveExpiredBans()
// Is the client banned? // Is the client banned?
// fixme(mkrautz): Clean up expired bans
if server.IsBanned(conn) { if server.IsBanned(conn) {
server.Printf("Rejected client %v: Banned", conn.RemoteAddr()) server.Printf("Rejected client %v: Banned", conn.RemoteAddr())
err := conn.Close() err := conn.Close()