import unittest from pynet import Encryptor, Node, PeerDefinition, NodeHooks from pynet.util import to_bytes, _run_node, send_data addr_1 = ("localhost", 54320) # addr_1 = "/tmp/pynet_test_node.sock" addr_2 = ("localhost", 54321) node_pk = Encryptor.new_key() master_encryptor = Encryptor(Encryptor.new_key(), node_pk.publickey()) master_def = PeerDefinition("master", None, master_encryptor.private_key.publickey()) def handle_message(sender, body): return (True, body.upper(), None) class HooksOverride(NodeHooks): def handle_raw_message(self, data): if data == b"register": self.node.write("Registered!", encrypt=False) return (True, None) else: return super().handle_raw_message(data) class TestNode(unittest.TestCase): @classmethod def setUpClass(cls): cls.addr = addr_1
def dump_config(args): print(Encryptor.new_key().exportKey("PEM").decode("UTF-8"))
def dump_config(args): node = Node(None, "/tmp/pynet-kvp.sock") node.add_peer(PeerDefinition("first among peers", "127.0.0.1:1337", Encryptor.new_key().publickey())) print(json.dumps(node.get_config(), sort_keys=True, indent=2, separators=(", ", ": ")))