You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
3.8 KiB

# -*- coding: UTF-8 -*-
# pEp package
# The names that are in _pEp that do not begin with an underscore, will be be imported into, and "re-exported" from this module.
# They are defined in boost-python/C++, and are directly part of the pEpPythonAdapter API
# The names that are in _pEp that DO begin with an underscore, will not be imported into this module, but will be accessible like _pEp._underscore_function().
# They are not directly part of the pEpPythonAdapter API, and are meant to be wrapped in this module.
# Example:
# def underscore_function():
# _pEp._underscore_function()
# __all__ could be used to limit the symbols exported when using from <pkg> import *
from .__version__ import version as __version__
except ImportError:
import warnings
warnings.warn("Error loading build-time defined, trying setuptools now...")
import setuptools_scm
__version__ = setuptools_scm.get_version()
del setuptools_scm
except Exception:
warnings.warn('could not determine %s package version' % __name__)
__version__ = '0.0.dev0+unknown'
# Imports all symbols EXCEPT the ones beginning with underscore
from ._pEp import *
# import the native module into the current namespace because we also need to access the names beginning
# with an underscore (of _pEp), but we dont want to import them into this module
import pEp._pEp
# 3rd party imports
from threading import Thread, Barrier
from time import sleep
# Executed on module import
def init():
# print(init, "called")
def start_sync() -> None:
"""starts the sync thread"""
def shutdown_sync() -> None :
"""call this to shut down the sync thread"""
def is_sync_active() -> bool:
"""True if sync is active, False otherwise"""
return Sync.getInstance().is_alive()
def message_to_send(msg):
override pEp.message_to_send(msg) with your own implementation
this callback is being called when a p≡p management message needs to be sent
print("message_to_send() - default callback\n")
print("overwrite this method")
def notify_handshake(me, partner, signal):
notifyHandshake(self, me, partner)
me own identity
partner identity of communication partner
signal the handshake signal
overwrite this method with an implementation of a handshake dialog
print("notify_handshake() - default callback\n")
print("overwrite this method")
class Sync(Thread):
__instance:'Sync' = None
barr = Barrier(2)
def __init__(self):
if Sync.__instance != None:
raise Exception("singleton!")
Sync.__instance = self
def getInstance() -> 'Sync':
if Sync.__instance == None:
return Sync.__instance
def run(self):
while pEp.do_protocol_step():
def start(self):
1. NEW ADLIB FUNC register_sync_callbacks() ONLY
2. create python thread that does do_sync_protocol()
3. NEWADLIB FUNC CallbackDispatcher.Signal_all_SYNC_NOTIFY_START()
# pEp.notifyHandshake_sync_start()
# sleep(2)
def start_sync():
def shutdown_sync():
if Sync.__instance:
if Sync.__instance.is_alive():
Sync.__instance = None
# pEp.notifyHandshake_sync_stop()