@@ -6,6 +6,7 @@ import sys
66import  time 
77import  platform 
88import  os 
9+ import  re 
910from  argparse  import  ArgumentParser  as  AP 
1011
1112is_windows  =  lambda  : platform .system ().lower () ==  'windows' 
@@ -40,12 +41,13 @@ except ImportError:
4041        print ("for other linuxs do:" )
4142        print ("\t pip3 install --user geoip" )
4243        print ("for other linuxs you are responsible for obtaining your owen geoip databases, glhf" )
44+         time .sleep (1 )
4345    else :
4446        print ("install it with:" )
4547        print ("\t pip3 install --user geoip" )
46-     print ("" )
47-     print ("press enter to continue without geoip" )
48-     sys .stdin .read (1 )
48+          print ()
49+          print ("press enter to continue without geoip" )
50+          sys .stdin .read (1 )
4951else :
5052    try :
5153        geoip_env_var  =  'GEOIP_DB_FILE' 
@@ -86,6 +88,7 @@ def ip_to_flag(ip):
8688class  Monitor :
8789
8890    _sample_size  =  12 
91+     filter  =  lambda  x  : True 
8992
9093    def  __init__ (self , url , introsetMode = False ):
9194        self .txrate  =  0 
@@ -144,7 +147,7 @@ class Monitor:
144147            self .win .addstr (" {} ->" .format (hopstr ))
145148
146149        self .win .addstr (" [{} ms latency]" .format (path ["intro" ]["latency" ]))
147-         self .win .addstr (" [{} until expire ]" .format (self .time_to (path ["expiresAt" ])))
150+         self .win .addstr (" [expires: {} ]" .format (self .time_to (path ["expiresAt" ])))
148151        if  path ["expiresSoon" ]:
149152            self .win .addstr ("(expiring)" )
150153        elif  path ["expired" ]:
@@ -153,13 +156,17 @@ class Monitor:
153156
154157    @staticmethod  
155158    def  time_to (timestamp ):
156-         """ return time until timestamp in seconds  formatted""" 
159+         """ return time until timestamp formatted""" 
157160        if  timestamp :
161+             unit  =  'seconds' 
158162            val  =  (timestamp  -  now ()) /  1000.0 
163+             if  abs (val ) >  60.0 :
164+                 val  /=  60.0 
165+                 unit  =  'minutes' 
159166            if  val  <  0 :
160-                 return  "{} seconds  ago" .format (0 - val )
167+                 return  "{:.2f} {}  ago" .format (0 - val ,  unit )
161168            else :
162-                 return  "{} seconds " .format (val )
169+                 return  "in {:.2f} {} " .format (val ,  unit )
163170        else :
164171            return  'never' 
165172
@@ -201,15 +208,18 @@ class Monitor:
201208        paths  =  status ["paths" ]
202209        self .win .addstr ("paths: {}" .format (len (paths )))
203210        for  path  in  paths :
204-             y_pos  =  self ._render_path (y_pos , path , "inbound" )
211+             if  self .filter ('localhost.loki' ):
212+                 y_pos  =  self ._render_path (y_pos , path , "localhost.loki" )
205213        for  session  in  (status ["remoteSessions" ] or  []):
206214            for  path  in  session ["paths" ]:
207-                 y_pos  =  self ._render_path (
208-                     y_pos , path , "[active] {}" .format (session ["currentConvoTag" ])
209-                 )
215+                 if  self .filter (session ["remoteIdentity" ]):
216+                     y_pos  =  self ._render_path (
217+                         y_pos , path , "[active] {}" .format (session ["currentConvoTag" ])
218+                     )
210219        for  session  in  (status ["snodeSessions" ] or  []):
211220            for  path  in  session ["paths" ]:
212-                 y_pos  =  self ._render_path (y_pos , path , "[snode]" )
221+                 if  self .filter (session ["endpoint" ]):
222+                     y_pos  =  self ._render_path (y_pos , path , "[snode]" )
213223        return  y_pos 
214224
215225    def  display_links (self , y_pos , data ):
@@ -407,18 +417,20 @@ class Monitor:
407417        """ 
408418        y_pos  +=  1 
409419        self .win .move (y_pos , 1 )
410-         self .win .addstr ("localhost.loki" )
411-         y_pos  =  self ._display_our_introset (y_pos , service )
412-         y_pos  +=  1 
420+         if  self .filter ("localhost.loki" ):
421+             self .win .addstr ("localhost.loki" )
422+             y_pos  =  self ._display_our_introset (y_pos , service )
423+             y_pos  +=  1 
413424        remotes  =  service ['remoteSessions' ] or  []
414425        for  session  in  remotes :
415-             y_pos  =  self ._display_session_introset (y_pos , session )
426+             if  self .filter (session ['remoteIdentity' ]):
427+                 y_pos  =  self ._display_session_introset (y_pos , session )
416428
417429    def  _display_intro (self , y_pos , intro , label , paths ):
418430        y_pos  +=  1 
419431        self .win .move (y_pos , 1 )
420432        path  =  'path'  in  intro  and  intro ['path' ][:4 ] or  '????' 
421-         self .win .addstr ('{}: ({}|{}) [expires in : {}] [{} paths]' .format (label , intro ['router' ][:8 ], path , self .time_to (intro ['expiresAt' ]), self .count_endpoints_in_path (paths , intro ['router' ])))
433+         self .win .addstr ('{}: ({}|{}) [expires: {}] [{} paths]' .format (label , intro ['router' ][:8 ], path , self .time_to (intro ['expiresAt' ]), self .count_endpoints_in_path (paths , intro ['router' ])))
422434        return  y_pos 
423435
424436    @staticmethod  
@@ -457,10 +469,13 @@ class Monitor:
457469        #print(context.keys()) 
458470        y_pos  +=  1 
459471        self .win .move (y_pos , 1 )
460-         readyState  =  context ['readyToSend' ] and  '✔️ '  or  '❌' 
472+         readyState  =  context ['readyToSend' ] and  '️✅ '  or  '❌' 
461473        self .win .addstr ('{} ({}) [{}]' .format (context ['remoteIdentity' ], context ['currentConvoTag' ], readyState ))
462474        y_pos  +=  1 
463475        self .win .move (y_pos , 1 )
476+         self .win .addstr ('created: {}' .format (self .time_to (context ['sessionCreatedAt' ])))
477+         y_pos  +=  1 
478+         self .win .move (y_pos , 1 )
464479        self .win .addstr ('last good send: {}' .format (self .time_to (context ['lastGoodSend' ])))
465480        y_pos  +=  1 
466481        self .win .move (y_pos , 1 )
@@ -544,13 +559,19 @@ def main():
544559
545560    ap .add_argument ("--introset" , action = 'store_const' , const = True , default = False , help = "run in introset inspection mode" )
546561    ap .add_argument ("--url" , default = 'tcp://127.0.0.1:1190' , type = str , help = 'url to lokinet rpc' )
562+     ap .add_argument ('--filter' , default = '.+' , type = str , help = "regex to filter entries" )
563+     ap .add_argument ('--invert-filter' , const = True , default = False , action = 'store_const' , help = 'invert regex filter matching' )
547564
548565    args  =  ap .parse_args ()
549566
550567    mon  =  Monitor (
551568        args .url ,
552569        args .introset 
553570    )
571+     mon .filter  =  lambda  x  : re .match (args .filter , x ) is  not None 
572+     if  args .invert_filter :
573+         old_filter  =  mon .filter 
574+         mon .filter  =  lambda  x  : not  old_filter (x )
554575    mon .run ()
555576
556577if  __name__  ==  "__main__" :
0 commit comments