コード例 #1
0
ファイル: check_infection_risk.py プロジェクト: osnas/epidose
def main():
    parser = argparse.ArgumentParser(
        description="Read Cuckoo filter and check against contacts")
    parser.add_argument("-d",
                        "--debug",
                        help="Run in debug mode logging to stderr",
                        action="store_true")
    parser.add_argument(
        "-D",
        "--database",
        help="Specify the database location",
        default="/var/lib/epidose/client-database.db",
    )
    parser.add_argument("-o",
                        "--observation",
                        help="Observation hash to check")
    parser.add_argument("-v",
                        "--verbose",
                        help="Set verbose logging",
                        action="store_true")
    parser.add_argument("filter", help="Cuckoo filter file")
    args = parser.parse_args()

    # Setup logging
    daemon = Daemon("check_infection", args)
    global logger
    logger = daemon.get_logger()

    with open(args.filter, "rb") as f:
        (capacity, ) = struct.unpack(">Q", f.read(8))
        cuckoo_filter = TracingDataBatch(fh=f, capacity=capacity)

    if args.observation:
        if (bytes(bytearray.fromhex(args.observation))
                in cuckoo_filter.infected_observations):
            print("Found")
            sys.exit(0)
        else:
            print("Not found")
            sys.exit(1)
    else:
        ct = ContactTracer(None,
                           args.database,
                           transmitter=False,
                           receiver=False)
        matches = ct.matches_with_batch(cuckoo_filter)
        logger.info(f"{'Contact match' if matches else 'No contact match'}")
        setup_leds()
        if matches:
            red_led_set(True)
            exit_code = 0
        else:
            red_led_set(False)
            exit_code = 1
        cleanup()
        sys.exit(exit_code)
コード例 #2
0
ファイル: watchdog_d.py プロジェクト: stefanos1316/epidose
def main():
    parser = argparse.ArgumentParser(
        description="Contact tracing beacon receiver")
    parser.add_argument("-d",
                        "--debug",
                        help="Run in debug mode logging to stderr",
                        action="store_true")
    parser.add_argument(
        "-D",
        "--database",
        help="Specify the database location",
        default="/var/lib/epidose/client-database.db",
    )
    parser.add_argument("-v",
                        "--verbose",
                        help="Set verbose logging",
                        action="store_true")
    args = parser.parse_args()

    daemon = Daemon("watchdog", args)

    # Setup logging
    global logger
    logger = daemon.get_logger()

    # Setup server connection
    proxy = client.ServerProxy(
        "http://localhost",
        transport=UnixStreamTransport("/run/supervisor.sock"))
    setup_leds()
    red_led_set(False)
    while True:
        if watchdog_check(proxy):
            # Signal heartbeat if no other signalling is active
            if led_change_age() > CHECK_INTERVAL * 2:
                green_led_set(True)
                sleep(FLASH_BLINK)
                green_led_set(False)
                sleep(FLASH_PAUSE)
                green_led_set(True)
                sleep(FLASH_BLINK)
                green_led_set(False)
        v = get_battery_voltage()
        logger.debug(f"Battery {v}")
        # Graceful shutdown when needed
        if v < SHUTDOWN_VOLTAGE:
            logger.debug("Battery exchausted; shutting down")
            schedule_power_off()
            system("shutdown now 'Battery exhausted (${v} V)'")
            exit(0)
        sleep(CHECK_INTERVAL)
コード例 #3
0
def main():
    parser = argparse.ArgumentParser(
        description="Contact tracing beacon receiver")
    parser.add_argument("-d",
                        "--debug",
                        help="Run in debug mode logging to stderr",
                        action="store_true")
    parser.add_argument(
        "-D",
        "--database",
        help="Specify the database location",
        default="/var/lib/epidose/client-database.db",
    )
    parser.add_argument(
        "-i",
        "--iface",
        help="Listen on the specified interface number, not [hci]0",
        type=int,
        default=0,
    )
    parser.add_argument("-t",
                        "--test",
                        help="Test script",
                        action="store_true")
    parser.add_argument("-v",
                        "--verbose",
                        help="Set verbose logging",
                        action="store_true")
    args = parser.parse_args()

    if args.test:
        args.debug = True
        args.database = ":memory:"

    # Setup logging
    daemon = Daemon("beacon_rx", args)
    global logger
    logger = daemon.get_logger()

    # Receive and process beacon packets
    global receiver
    receiver = ContactTracer(None, args.database, transmitter=False)
    if args.test:
        sys.exit(0)
    socket = bluez.hci_open_dev(args.iface)
    set_receive(socket)
    setup_leds()
    while True:
        process_packet(socket)