mirror of https://github.com/nucypher/nucypher.git
Seed-only Server now (at least seems) to actually refuse to store data. Fixes #23.
parent
af4ae48089
commit
ab6cbaead6
|
@ -2,7 +2,7 @@ import asyncio
|
|||
import logging
|
||||
|
||||
from kademlia.network import Server
|
||||
from nkms.network.protocols import NuCypherSeedOnlyProtocol
|
||||
from nkms.network.server import NuCypherSeedOnlyDHTServer
|
||||
|
||||
key = "llamas"
|
||||
value = "tons_of_things_keyed_llamas"
|
||||
|
@ -11,7 +11,7 @@ logging.basicConfig(level=logging.DEBUG)
|
|||
loop = asyncio.get_event_loop()
|
||||
loop.set_debug(True)
|
||||
|
||||
server = Server(protocol_class=NuCypherSeedOnlyProtocol)
|
||||
server = NuCypherSeedOnlyDHTServer()
|
||||
server.listen(8469)
|
||||
loop.run_until_complete(server.bootstrap([("127.0.0.1", 8468)]))
|
||||
set = server.set(key, value)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from kademlia.node import Node
|
||||
from kademlia.protocol import KademliaProtocol
|
||||
import asyncio
|
||||
|
||||
|
||||
class NuCypherHashProtocol(KademliaProtocol):
|
||||
|
@ -7,7 +7,13 @@ class NuCypherHashProtocol(KademliaProtocol):
|
|||
|
||||
|
||||
class NuCypherSeedOnlyProtocol(NuCypherHashProtocol):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@asyncio.coroutine
|
||||
def _acceptRequest(self, msgID, data, address):
|
||||
pass
|
||||
def rpc_store(self, sender, nodeid, key, value):
|
||||
source = Node(nodeid, sender[0], sender[1])
|
||||
self.welcomeIfNewNode(source)
|
||||
self.log.debug(
|
||||
"got a store request from %s, but THIS VALUE WILL NOT BE STORED as this is a seed-only node." % str(
|
||||
sender))
|
||||
return True
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
from kademlia.network import Server
|
||||
from nkms.network.protocols import NuCypherSeedOnlyProtocol
|
||||
from nkms.network.storage import SeedOnlyStorage
|
||||
|
||||
|
||||
class NuCypherSeedOnlyDHTServer(Server):
|
||||
|
||||
protocol_class = NuCypherSeedOnlyProtocol
|
||||
protocol_class = NuCypherSeedOnlyProtocol
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.storage = SeedOnlyStorage()
|
|
@ -0,0 +1,7 @@
|
|||
from kademlia.storage import ForgetfulStorage
|
||||
|
||||
|
||||
class SeedOnlyStorage(ForgetfulStorage):
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
pass
|
|
@ -3,6 +3,10 @@ import asyncio
|
|||
from kademlia.network import Server
|
||||
from nkms.network.server import NuCypherSeedOnlyDHTServer
|
||||
|
||||
# Kademlia emits a bunch of useful logging info; uncomment below to see it.
|
||||
# import logging
|
||||
# logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
|
||||
def test_seed_only_node():
|
||||
"""
|
||||
|
@ -39,8 +43,8 @@ def test_seed_only_node():
|
|||
assert len(seed_only_server_stored_items) == 0
|
||||
|
||||
# If the full server tries to store something...
|
||||
key_that_is_not_stored = "european_swallow"
|
||||
value_that_is_not_stored = "grip_it_by_the_husk"
|
||||
key_that_is_not_stored = b"european_swallow"
|
||||
value_that_is_not_stored = b"grip_it_by_the_husk"
|
||||
setter = full_server.set(key_that_is_not_stored, value_that_is_not_stored)
|
||||
loop.run_until_complete(setter)
|
||||
|
||||
|
|
Loading…
Reference in New Issue