Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running federated node via CLI #447

Merged
merged 25 commits into from Sep 27, 2018
Merged

Conversation

KPrasch
Copy link
Member

@KPrasch KPrasch commented Sep 23, 2018

No description provided.

Copy link
Member

@jMyles jMyles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm uncomfortable with this pattern:

instance_of_foo = Bar(...)

That's what seems to be emerging here, and I'm not sure why. Perhaps it's part of the logic trying to move toward factory style?

Also... missleware?

full_filepath,
force: bool = True,
full_filepath: str,
force: bool = True, # TODO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this TODO?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To set Force to False by default, but, I changed my mind for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

self._interface_signature_object = interface_signature

# TODO: This gets messy when it is None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to move this comment down here? Haven't you obsoleted it above? Maybe just comment it out for now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - it's obsolete - needs cleanup

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@@ -34,6 +43,12 @@ class WrongMode(TypeError):
Raise when a Character tries to use another Character as decentralized when the latter is federated_only.
"""

@classmethod
def from_tls_hosting_power(cls, tls_hosting_power: TLSHostingPower, *args, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fucking interesting, man.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - I'm not using this anywhere yet, but if we continue to init VerifiableNode in the same fashion we do now, this makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this.

def certificate(self):
return self._crypto_power.power_ups(TLSHostingPower).keypair.certificate
@property
def common_name(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. Not kidding around.

So, common name is always from the cert? Surely it makes sense to check that it matches the checksum address before returning it?

Or are we in pretending-this-is-not-a-mixin pattern here?

Perhaps as I read on, it will become clearer. :-)

Copy link
Member Author

@KPrasch KPrasch Sep 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the thinking here is that common name is always from the certificate, which needs to better better validated. with regard to mixins, I've had a similar question while working with Learner and VerifiableNode. Is this class a mixin? If not, then I'm inclined to localize the attributes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't presently have a vision of it other than as a mixin, although there's no inherent reason that it can't be an inventory item.

@@ -46,21 +47,31 @@ class NotEnoughTeachers(RuntimeError):
pass

def __init__(self,
always_be_learning: bool = False,
start_learning_on_same_thread: bool = False,
start_learning_now: bool = False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm, yeah - good change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

always_be_learning=True,
known_certificates_dir=CERTIFICATE_DIR,
) # TODO: 289
ALICE = AliceConfiguration(network_middleware=RestMiddleware(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What am I dealing with here? This thing returns an Alice? Is this to be the canonical way to get an Alice? That seems like an anti-pattern to me. Why can't the user init the class they want?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the bottom of this call, there is a chained method call to .produce() which outputs an Alice. You can still init any Character directly, of course, but while debugging demo-code I wanted to use temporary directories as a means of handling the nodes runtime files, which is cleaner / easier to do with config.

FWIW I actually intend to reset this module before taking this PR off WIP

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, great.

@@ -14,17 +14,21 @@
class NodeConfiguration:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, config has grown to be something of a mirror of Character, as you expressed concern it might. I still think I like it, but I'm joining you in your trepidation.

Copy link
Member Author

@KPrasch KPrasch Sep 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same - I like like the benefits of having a layer between the filesystem and the character but also dislike the additional complexity. Overall Im +1 on NodeConfiguration classes.

I think the factory-style pattern relieves some tension regarding Character initialization.

rest_port=rest_port,
db_name='ursula-{}.db'.format(rest_port),
federated_only=federated_only)
URSULA = UrsulaConfiguration(temp=True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar concern to the one I raised above - is this to be the canonical way to get a Character?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deprecated ✔️

@@ -7,10 +7,10 @@

class RestMiddleware:

def consider_arrangement(self, arrangement):
def consider_arrangement(self, arrangement, certificate_filepath):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this change. Why do we ever want to pass in a cert other than the one that belongs to the Ursula in the arrangement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️ - removed.

@@ -242,7 +242,7 @@ def get_treasure_map(self, alice_verifying_key, label):
if not self.known_nodes and not self._learning_task.running:
# Quick sanity check - if we don't know of *any* Ursulas, and we have no
# plans to learn about any more, than this function will surely fail.
raise self.NotEnoughUrsulas
raise Ursula.NotEnoughUrsulas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand this change either. Do we really want this exception only to live on Ursula (and thus require Ursula to be imported everywhere we raise it?).

...and if we do, then is NotEnoughUrsulas still a good name?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - I do no think we want to require the import of Ursula in this case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@KPrasch
Copy link
Member Author

KPrasch commented Sep 24, 2018

I'm uncomfortable with this pattern:
instance_of_foo = Bar(...)

Not sure If I understand. Is there a specific place in the pull request you are referring to?

@KPrasch KPrasch changed the base branch from kokonusswasser to master September 24, 2018 19:55
@KPrasch KPrasch changed the base branch from master to kokonusswasser September 24, 2018 19:55
@KPrasch KPrasch changed the title [WIP] Running federated node via CLI Running federated node via CLI Sep 25, 2018
@KPrasch
Copy link
Member Author

KPrasch commented Sep 25, 2018

I'm unsure why CI is failing all builds with ImportError: cannot import name 'Route' - I cannot reproduce this type of failure locally.

@KPrasch
Copy link
Member Author

KPrasch commented Sep 25, 2018

The Issue was that a new version of APIStar has been released: https://github.com/encode/apistar/releases. Pinned version 0.5.42 for now.

@@ -34,7 +34,6 @@
def spin_up_ursula(rest_port, db_name, teachers=(), certificate_dir=None):
metadata_file = "examples-runtime-cruft/node-metadata-{}".format(rest_port)

asyncio.set_event_loop(asyncio.new_event_loop()) # Ugh. Awful. But needed until we shed the DHT.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we planning to remove asyncio completely? I think we might be able to use it for task scheduling (ie: kfrag expiration)

always_be_learning: bool = False,
start_learning_on_same_thread: bool = False,
start_learning_now: bool = False,
learn_on_same_thread: bool = False,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the need to move it to a different thread than the one you start it on?

if save_metadata and known_metadata_dir is None:
raise ValueError("Cannot save nodes without a known_metadata_dir")

known_nodes = known_nodes or tuple()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much better than before.

@@ -385,20 +378,26 @@ class Ursula(Character, VerifiableNode, Miner):
# TLSHostingPower still can enjoy default status, but on a different class
_default_crypto_powerups = [SigningPower, EncryptingPower]

class NotEnoughUrsulas(Learner.NotEnoughTeachers, MinerAgent.NotEnoughMiners):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move this here? Mostly because Ursula is here?

@@ -34,6 +43,12 @@ class WrongMode(TypeError):
Raise when a Character tries to use another Character as decentralized when the latter is federated_only.
"""

@classmethod
def from_tls_hosting_power(cls, tls_hosting_power: TLSHostingPower, *args, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this.

Copy link
Contributor

@tuxxy tuxxy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐧

Copy link
Member

@jMyles jMyles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like my concerns are addressed now, with the exception that I think that exceptions stemming from a dearth of nodes (Learners or Ursulas) rightly belong on Character (or a similarly universally positioned class).

@KPrasch KPrasch merged commit b700ae9 into nucypher:kokonusswasser Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants