Middleware -> RestMiddleware

pull/330/head
Kieran Prasch 2018-06-06 01:32:25 -07:00
parent 94d94d3407
commit e2eb556e10
8 changed files with 24 additions and 23 deletions

View File

@ -12,16 +12,17 @@ from nucypher.data_sources import DataSource
import maya
# This is already running in another process.
from nucypher.network.middleware import NetworkMiddleware
from nucypher.network.middleware import RestMiddleware
from umbral.keys import UmbralPublicKey
URSULA = Ursula.from_rest_url(NetworkMiddleware(),
URSULA = Ursula.from_rest_url(RestMiddleware(),
ip_address="localhost",
port=3601,
)
network_middleware = SandboxNetworkMiddleware([URSULA])
#########
# Alice #
#########

View File

@ -5,6 +5,10 @@ from nucypher.network.middleware import NetworkMiddleware
class SandboxNetworkMiddleware(NetworkMiddleware):
from nucypher.network.middleware import RestMiddleware
class SandboxNetworkyStuff(RestMiddleware):
def __init__(self, ursulas):
self.ursulas = ursulas
@ -25,5 +29,4 @@ class SandboxNetworkMiddleware(NetworkMiddleware):
def enact_policy(self, ursula, hrac, payload):
endpoint = 'https://{}:{}/kFrag/{}'.format(ursula.ip_address, ursula.rest_port, hrac.hex())
response = requests.post(endpoint, payload, verify=False)
# TODO: Something useful here and it's probably ready to go down into NetworkyStuff.
return response.status_code == 200

View File

@ -6,6 +6,7 @@ from nucypher.blockchain.eth.agents import NucypherTokenAgent, MinerAgent, Polic
from constant_sorrow import constants
class NucypherTokenActor:
"""
Concrete base class for any actor that will interface with NuCypher's ethereum smart contracts

View File

@ -20,7 +20,7 @@ from nucypher.crypto.constants import PUBLIC_KEY_LENGTH
from nucypher.crypto.kits import UmbralMessageKit
from nucypher.crypto.powers import CryptoPower, SigningPower, EncryptingPower, DelegatingPower, NoSigningPower
from nucypher.crypto.signing import signature_splitter, StrangerStamp
from nucypher.network.middleware import NetworkMiddleware
from nucypher.network.middleware import RestMiddleware
from nucypher.network.protocols import dht_value_splitter, dht_with_hrac_splitter
from nucypher.network.server import NucypherDHTServer, NucypherSeedOnlyDHTServer, ProxyRESTServer
from umbral.keys import UmbralPublicKey
@ -95,7 +95,7 @@ class Character:
# Identity and Network
#
if is_me is True:
self.network_middleware = network_middleware or NetworkMiddleware()
self.network_middleware = network_middleware or RestMiddleware()
try:
signing_power = self._crypto_power.power_ups(SigningPower)

View File

@ -2,15 +2,10 @@ import requests
from bytestring_splitter import BytestringSplitter, VariableLengthBytestring
from umbral.fragments import CapsuleFrag
from nucypher.blockchain.eth.agents import MinerAgent
class RestMiddleware:
class NetworkMiddleware(object):
class NotEnoughQualifiedUrsulas(MinerAgent.NotEnoughMiners):
pass
def consider_arrangement(self, arrangement=None):
def consider_arrangement(self, ursula, arrangement=None):
pass
def reencrypt(self, work_order):

View File

@ -12,7 +12,7 @@ from nucypher.data_sources import DataSource
from nucypher.keystore import keystore
from nucypher.keystore.db import Base
from nucypher.keystore.keypairs import SigningKeypair
from tests.utilities import MockNetworkMiddleware, make_ursulas
from tests.utilities import make_ursulas, MockRestMiddleware
@pytest.fixture(scope="module")
@ -36,7 +36,8 @@ def enacted_policy(idle_policy, ursulas, mock_miner_agent, mock_token_agent):
# Alice has a policy in mind and knows of enough qualifies Ursulas; she crafts an offer for them.
deposit = constants.NON_PAYMENT(b"0000000")
contract_end_datetime = maya.now() + datetime.timedelta(days=5)
network_middleware = MockNetworkMiddleware(ursulas)
network_middleware = MockRestMiddleware()
idle_policy.make_arrangements(network_middleware, deposit=deposit, quantity=3, expiration=contract_end_datetime)
idle_policy.enact(network_middleware) # REST call happens here, as does population of TreasureMap.
@ -48,7 +49,7 @@ def alice(ursulas, mock_policy_agent, deployed_testerchain):
etherbase, alice, bob, *everyone_else = deployed_testerchain.interface.w3.eth.accounts
_alice = Alice(network_middleware=MockNetworkMiddleware(ursulas),
_alice = Alice(network_middleware=MockRestMiddleware(),
policy_agent=mock_policy_agent, ether_address=alice)
return _alice
@ -56,7 +57,7 @@ def alice(ursulas, mock_policy_agent, deployed_testerchain):
@pytest.fixture(scope="module")
def bob(ursulas):
_bob = Bob(network_middleware=MockNetworkMiddleware(ursulas))
_bob = Bob(network_middleware=MockRestMiddleware())
return _bob
@ -76,7 +77,7 @@ def ursulas(deployed_testerchain):
@pytest.fixture(scope="module")
def treasure_map_is_set_on_dht(enacted_policy, ursulas):
network_middleware = MockNetworkMiddleware(ursulas)
network_middleware = MockRestMiddleware()
enacted_policy.publish_treasure_map(network_middleware, use_dht=True)

View File

@ -8,7 +8,7 @@ from kademlia.utils import digest
from nucypher.crypto.api import keccak_digest
from nucypher.crypto.kits import UmbralMessageKit
from nucypher.network.protocols import dht_value_splitter, dht_with_hrac_splitter
from tests.utilities import MockNetworkMiddleware, TEST_EVENT_LOOP
from tests.utilities import TEST_EVENT_LOOP, MockRestMiddleware
@pytest.mark.usefixtures('deployed_testerchain')
@ -50,7 +50,7 @@ def test_vladimir_illegal_interface_key_does_not_propagate(ursulas):
def test_alice_finds_ursula_via_rest(alice, ursulas):
network_middleware = MockNetworkMiddleware(ursulas)
network_middleware = MockRestMiddleware()
# Imagine alice knows of nobody.
alice.known_nodes = {}
@ -77,7 +77,7 @@ def test_alice_sets_treasure_map_on_network(enacted_policy, ursulas):
"""
Having enacted all the policies of a PolicyGroup, Alice creates a TreasureMap and sends it to Ursula via the DHT.
"""
networky_stuff = MockNetworkMiddleware(ursulas)
networky_stuff = MockRestMiddleware()
_, packed_encrypted_treasure_map, _, _ = enacted_policy.publish_treasure_map(network_middleare=networky_stuff, use_dht=True)
treasure_map_as_set_on_network = ursulas[0].server.storage[
@ -132,7 +132,7 @@ def test_bob_can_retreive_the_treasure_map_and_decrypt_it(enacted_policy, ursula
that Bob can retrieve it with only the information about which he is privy pursuant to the PolicyGroup.
"""
bob = enacted_policy.bob
networky_stuff = MockNetworkMiddleware(ursulas)
_ = MockRestMiddleware()
# Of course, in the real world, Bob has sufficient information to reconstitute a PolicyGroup, gleaned, we presume,
# through a side-channel with Alice.

View File

@ -4,12 +4,12 @@ from typing import List
from apistar.test import TestClient
from constant_sorrow import constants
from nucypher.characters import Ursula
from nucypher.network.middleware import NetworkMiddleware
#
# Setup
#
from nucypher.network.middleware import RestMiddleware
from nucypher.policy.models import Arrangement, Policy
TEST_EVENT_LOOP = asyncio.get_event_loop()
asyncio.set_event_loop(TEST_EVENT_LOOP)