forked from External/grumble
Add support for ban expiry.
This commit is contained in:
parent
0fde3b9ae9
commit
2751c1824e
1 changed files with 24 additions and 1 deletions
25
server.go
25
server.go
|
|
@ -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()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue