Exemplo n.º 1
0
// Is the certificate hash banned?
func (server *Server) IsCertHashBanned(hash string) bool {
	server.banlock.RLock()
	defer server.banlock.RUnlock()

	for _, ban := range server.Bans {
		if ban.CertHash == hash && !ban.IsExpired() {
			return true
		}
	}

	return false
}
Exemplo n.º 2
0
// Is the incoming connection conn banned?
func (server *Server) IsConnectionBanned(conn net.Conn) bool {
	server.banlock.RLock()
	defer server.banlock.RUnlock()

	for _, ban := range server.Bans {
		addr := conn.RemoteAddr().(*net.TCPAddr)
		if ban.Match(addr.IP) && !ban.IsExpired() {
			return true
		}
	}

	return false
}
Exemplo n.º 3
0
// 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)
	}
}