Example #1
0
//---------------------------------------------------------- ban an ip
func Ban(_ip net.IP) {
	config := cfg.Get()
	ban_time, err := strconv.Atoi(config["ban_time"])
	if err != nil {
		ban_time = DEFAULT_BAN_TIME
		log.Println("cannot get ban_timeout from config", err)
	}

	intip := _ip2int(_ip)

	// randomize the timeout, for effective DoS protection
	ban := uint32(ban_time)
	_banned_ips[intip] = time.Now().Unix() + int64(ban+helper.LCG()%ban)
}
Example #2
0
//------------------------------------------------ 随机概率丢骰子
func Dice(probability float32) bool {
	return helper.LCG() < uint32(probability*math.MaxUint32)
}