o
    Fj                     @   sP   d dl Z d dlZe jddddZddd	Zdd
dZdd Zdd Zdd ZdS )    N	localhosti  T)hostportdecode_responses<      c                 C   s`   d|  }t   }|| }t|d| t|t||i t|| t|}|||kdS )Nz	velocity:r   )request_counthigh_velocity)timeredis_clientzremrangebyscorezaddstrexpirezcard)ipwindow_seconds	thresholdkeycurrent_timewindow_startr    r   //home/djax/ivt_ai_plugin/scoring/redis_state.pycheck_velocity   s"   


r   c                 C   s4   d|  d| }t |}t ||d dt|iS )Nz
duplicate::1	duplicate)r   existssetexbool)r   
user_agentr   r   is_duplicater   r   r   check_duplicate&   s   
r"   c                 C   s.   t | } t |}d|  d| }dt|iS )Nblocked:r   blocked)r   r   r   )r   r    r   r   r   r   check_blocked5   s
   
r%   c              	   C   sL   t | } t |}d|  d| }tj|| ||d|t t dd dS )Nr#   r   ,)r   r    
risk_scorefeatures
blocked_atmappingT)r   r   hsetjoinr
   )r   r    r'   r(   r   r   r   r   store_blocked@   s   
r.   c                 C   sT   t | } t |}d|  d| }t|dd}tj|| |t t dd d|iS )Nzsuspicious:r   count   )r   r    	last_seenr*   suspicious_count)r   r   hincrbyr,   r
   )r   r    r   r/   r   r   r   track_suspiciousS   s   

r4   )r   r   )r   )	redisr
   Redisr   r   r"   r%   r.   r4   r   r   r   r   <module>   s    

