From 8f509533c5373e8b780da564737e57bda6f9b503 Mon Sep 17 00:00:00 2001 From: jMyles Date: Wed, 30 Aug 2017 22:11:02 -0700 Subject: [PATCH] First implementation of customized Server and Protocol classes for DHT. Pending PR 32 on kademlia. --- entry_points/run_local_server.py | 17 +++++++++++++++++ examples/set_dht_value_without_listening.py | 20 ++++++++++++++++++++ nkms/network/protocols.py | 13 +++++++++++++ nkms/network/server.py | 5 +++++ 4 files changed, 55 insertions(+) create mode 100644 entry_points/run_local_server.py create mode 100644 examples/set_dht_value_without_listening.py create mode 100644 nkms/network/protocols.py create mode 100644 nkms/network/server.py diff --git a/entry_points/run_local_server.py b/entry_points/run_local_server.py new file mode 100644 index 000000000..e8988e983 --- /dev/null +++ b/entry_points/run_local_server.py @@ -0,0 +1,17 @@ +from nkms.network.server import NuCypherDHTServer +import asyncio + + +if __name__ == "__main__": + loop = asyncio.get_event_loop() + loop.set_debug(True) + loop.set_debug(True) + server = NuCypherDHTServer() + server.listen(8468) + + try: + loop.run_forever() + except KeyboardInterrupt: + pass + + loop.close() \ No newline at end of file diff --git a/examples/set_dht_value_without_listening.py b/examples/set_dht_value_without_listening.py new file mode 100644 index 000000000..98ab27993 --- /dev/null +++ b/examples/set_dht_value_without_listening.py @@ -0,0 +1,20 @@ +import asyncio +import logging + +from kademlia.network import Server +from nkms.network.protocols import NuCypherSeedOnlyProtocol + +key = "llamas" +value = "tons_of_things_keyed_llamas" + +logging.basicConfig(level=logging.DEBUG) +loop = asyncio.get_event_loop() +loop.set_debug(True) + +server = Server(protocol_class=NuCypherSeedOnlyProtocol) +server.listen(8469) +loop.run_until_complete(server.bootstrap([("127.0.0.1", 8468)])) +set = server.set(key, value) +loop.run_until_complete(set) +server.stop() +loop.close() diff --git a/nkms/network/protocols.py b/nkms/network/protocols.py new file mode 100644 index 000000000..62a58f6dc --- /dev/null +++ b/nkms/network/protocols.py @@ -0,0 +1,13 @@ +from kademlia.protocol import KademliaProtocol +import asyncio + + +class NuCypherHashProtocol(KademliaProtocol): + pass + + +class NuCypherSeedOnlyProtocol(NuCypherHashProtocol): + + @asyncio.coroutine + def _acceptRequest(self, msgID, data, address): + pass \ No newline at end of file diff --git a/nkms/network/server.py b/nkms/network/server.py new file mode 100644 index 000000000..ad4335c69 --- /dev/null +++ b/nkms/network/server.py @@ -0,0 +1,5 @@ +from kademlia.network import Server + + +class NuCypherDHTServer(Server): + pass \ No newline at end of file