mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-03 23:15:52 +00:00
52 lines
1.1 KiB
Python
52 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
|
|
|
|
from ctypes import *
|
|
import signal
|
|
import time
|
|
import threading
|
|
import os
|
|
|
|
lib_file = os.path.join(os.path.realpath('.'), 'liblokinet.so')
|
|
|
|
class LokiNET(threading.Thread):
|
|
|
|
lib = None
|
|
ctx = None
|
|
|
|
def load(self, lib, conf):
|
|
self.lib = CDLL(lib)
|
|
self.lib.llarp_ensure_config(conf)
|
|
self.ctx = self.lib.llarp_main_init(conf)
|
|
return self.ctx != 0
|
|
|
|
|
|
def signal(self, sig):
|
|
if self.ctx and self.lib:
|
|
self.lib.llarp_main_signal(self.ctx, int(sig))
|
|
|
|
def run(self):
|
|
code = self.lib.llarp_main_run(self.ctx)
|
|
print("llarp_main_run exited with status {}".format(code))
|
|
|
|
def close(self):
|
|
if self.lib and self.ctx:
|
|
self.lib.llarp_main_free(self.ctx)
|
|
|
|
def main():
|
|
loki = LokiNET()
|
|
if loki.load(lib_file, b'daemon.ini'):
|
|
loki.start()
|
|
try:
|
|
while True:
|
|
time.sleep(1)
|
|
except KeyboardInterrupt:
|
|
llarp.signal(signal.SIGINT)
|
|
finally:
|
|
loki.close()
|
|
return
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|