func (blf *BlackListFilter) isBlock(s *netlib.Session) bool { host, _, err := net.SplitHostPort(s.RemoteAddr()) if err != nil { return true } ip := net.ParseIP(host) blf.lock.RLock() defer blf.lock.RUnlock() for e := blf.blacklist.Front(); e != nil; e = e.Next() { if e.Value.(*net.IPNet).Contains(ip) { return true } } return false }
func (ctf *ConnectionThrottleFilter) isConnectionOk(s *netlib.Session) bool { host, _, err := net.SplitHostPort(s.RemoteAddr()) if err != nil { return false } tNow := time.Now() value := ctf.clients.Get(host) if value != nil { tLast := value.(time.Time) if tNow.Sub(tLast) < time.Duration(ctf.AllowedInterval)*time.Millisecond { ctf.clients.Set(host, tNow) return false } } ctf.clients.Set(host, tNow) return true }