X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=arper.py;h=b4c079edcc750307356b60fdba39ca5b43f5c38a;hb=532df2c5b57c7517dfb3dddd8c1358fbadf8baf3;hp=a665137c1c71fd90637add9cba91e125e44a31a4;hpb=5c212d7639f62fcb936f9d7a0bbe704a9f7b213d;p=python_utils.git diff --git a/arper.py b/arper.py index a665137..b4c079e 100644 --- a/arper.py +++ b/arper.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +# © Copyright 2021-2022, Scott Gasch + """A caching layer around the kernel's network mapping between IPs and MACs""" @@ -41,7 +43,7 @@ cfg.add_argument( cfg.add_argument( '--arper_cache_max_staleness', type=argparse_utils.valid_duration, - default=datetime.timedelta(seconds=60 * 15), + default=datetime.timedelta(seconds=60 * 30), metavar='DURATION', help='Max acceptable age of the kernel arp table cache', ) @@ -55,6 +57,17 @@ cfg.add_argument( @persistent.persistent_autoloaded_singleton() # type: ignore class Arper(persistent.Persistent): + """A caching layer around the kernel's network mapping between IPs and + MACs. This class restores persisted state that expires + periodically (see --arper_cache_max_staleness) at program startup + time. If it's unable to use the file's contents, it queries the + kernel (via arp) and uses an auxillary utility called arp-scan to + query the network. If it has to do this there's a latency hit but + it persists the collected data in the cache file. Either way, the + class behaves as a global singleton hosting this data thereafter. + + """ + def __init__( self, cached_local_state: Optional[BiDict] = None, @@ -118,10 +131,10 @@ class Arper(persistent.Persistent): @classmethod def load_state( - cls, - cache_file: str, - freshness_threshold_sec: int, - state: BiDict, + cls, + cache_file: str, + freshness_threshold_sec: int, + state: BiDict, ): if not file_utils.file_is_readable(cache_file): logger.debug('Can\'t read %s', cache_file)