First implementation of customized Server and Protocol classes for DHT. Pending PR 32 on kademlia.

pull/21/head
jMyles 2017-08-30 22:11:02 -07:00
parent 3ed967335b
commit 8f509533c5
4 changed files with 55 additions and 0 deletions

View File

@ -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()

View File

@ -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()

13
nkms/network/protocols.py Normal file
View File

@ -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

5
nkms/network/server.py Normal file
View File

@ -0,0 +1,5 @@
from kademlia.network import Server
class NuCypherDHTServer(Server):
pass