Beispiel #1
0
    async def save_ip(self, ip: IPData):
        await self.update_score(ip)
        with await Redis.share() as redis:
            if ip.http is True:
                await redis.sadd(Config.REDIS_KEY_ABLE_HTTP, ip.to_str())
            else:
                await redis.srem(Config.REDIS_KEY_ABLE_HTTP, ip.to_str())

            if ip.https is True:
                await redis.sadd(Config.REDIS_KEY_ABLE_HTTPS, ip.to_str())
            else:
                await redis.srem(Config.REDIS_KEY_ABLE_HTTPS, ip.to_str())

            # Rules check
            for key, res in ip.rules.items():
                if res is True:
                    await redis.sadd(Config.REDIS_KEY_ABLE_RULES % key, ip.to_str())
                else:
                    await redis.srem(Config.REDIS_KEY_ABLE_RULES % key, ip.to_str())

            # Delay pool
            if ip.available():
                delay_key = self.get_delay_key(ip.delay)
                if delay_key:
                    await redis.sadd(delay_key, ip.to_str())

        if ip.available():
            await self.available_call(ip)
        else:
            await self.fail_call(ip)
Beispiel #2
0
 async def update_score(self, ip: IPData):
     with await Redis.share() as redis:
         score = await redis.zscore(Config.REDIS_KEY_IP_POOL, ip.to_str())
         ip.score = score if score is not None else 0
Beispiel #3
0
 async def available_call(self, ip: IPData):
     if ip.score >= Config.DEFAULT_MAX_SCORE:
         return
     with await Redis.share() as redis:
         await redis.zincrby(Config.REDIS_KEY_IP_POOL, Config.DEFAULT_INC_SCORE, ip.to_str())
Beispiel #4
0
 async def fail_call(self, ip: IPData):
     if ip.score <= Config.DEFAULT_MINI_SCORE:
         return
     with await Redis.share() as redis:
         await redis.zincrby(Config.REDIS_KEY_IP_POOL, -Config.DEFAULT_DEC_SCORE, ip.to_str())