Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Add minimal example #2062

Merged
merged 4 commits into from Mar 2, 2020
Merged

Add minimal example #2062

merged 4 commits into from Mar 2, 2020

Conversation

madadam
Copy link
Contributor

@madadam madadam commented Mar 2, 2020

Closes #2057

@madadam madadam requested review from dirvine and maqi March 2, 2020 12:52
@@ -0,0 +1,384 @@
// Copyright 2018 MaidSafe.net limited.
Copy link
Member

Choose a reason for hiding this comment

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

2020

ip: Option<IpAddr>,
base_port: Option<u16>,
) {
let mut join_handles = Vec::with_capacity(count);
Copy link
Member

Choose a reason for hiding this comment

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

why need to have this join_handles, is it will be dropped when return from this function ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They join the threads when dropped (see the ScopedJoinHandle wrapper at the bottom of the file). But maybe we don't really need that?

Copy link
Member

Choose a reason for hiding this comment

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

maybe it's useful later on, for supporting exchanging messages.
However, I don't see it's necessary currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I just tried it. We do need to collect the handles to keep the example running. Without it all the threads are killed immediately and the example terminates.

Copy link
Member

Choose a reason for hiding this comment

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

ok then

init_log(opts.verbosity);

if opts.count <= 1 {
start_single_node(opts.first, opts.bootstrap_contacts, opts.ip, opts.port)
Copy link
Member

Choose a reason for hiding this comment

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

wondering why need this start_single_node?
can spawn_first_node be used directly?
Also, maybe just call start_multiple_nodes shall be enough? or do we really want a single node example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You might want to start multiple instances of this example even across multiple machines, so the ability to start a single node is useful. Also "first node" isn't just the first node started in one instance of the example. It means the first node of the network. So you might want to start first node on one machine and normal node on another. That gives us the following options, all of which I think are valid:

  1. Single first node
  2. Single normal node
  3. Multiple nodes where exactly one of them is first
  4. Multiple nodes, all normal

loop {
// We need receive from multiple channels. As a minimum, we need to receive from the
// channels used internally by `Node` and from the node event channel. Additionally we might
// wand to receive from the client network event channel (not used in this example) or from
Copy link
Member

Choose a reason for hiding this comment

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

want?

const TARGET_SELF: &str = "minimal";
const TARGET_ROUTING: &str = "routing";

fn init_log(verbosity: u8) {
Copy link
Member

@dirvine dirvine Mar 2, 2020

Choose a reason for hiding this comment

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

Would https://github.com/rust-cli/clap-log-flag perhaps make it easier? Our CLI etc. uses this so it would be more consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps. But the logging logic I'm using currently is bit different. You can use -v, -vv and -vvv to enable logs (info, debug and trace respectively) from the routing crate only and -vvvv to enable logs from all crates. Doesn't seem I can achieve that with clap-log-flag which allows either only the current crate or all crates.

Also not sure such a simple feature justifies adding yet another dependency.

@@ -218,7 +217,7 @@ impl Chain {
Err(InsertError::ReplacedAlreadyInserted) => {
// TODO: If detecting duplicate vote from peer, penalise.
log_or_panic!(
Copy link
Member

@dirvine dirvine Mar 2, 2020

Choose a reason for hiding this comment

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

I am not sure log_or_panic is valid anywhere except POC work, but less so here. As this is an example we can log errors or panic, but I don't think mixing them is good. In the cases where it seems to log is fine, unless we get into a UB state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We still use log_or_panic in a bunch of places and this PR isn't really about that. I'm OK with replacing log_or_panic with something better, but it should be done as a separate task. We also haven't fully decided what that better thing should be.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I agree, we will get to it soon enough. Thanks chap

dirvine
dirvine previously approved these changes Mar 2, 2020
Copy link
Member

@dirvine dirvine left a comment

Choose a reason for hiding this comment

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

A couple of nice points, by @maqi worth, addressing but nice work @madadam this will help us a lot now and great to get a decent example to test the API. We can make great use of this.

maqi
maqi previously approved these changes Mar 2, 2020
@dirvine dirvine merged commit c315099 into maidsafe:fleming Mar 2, 2020
@madadam madadam deleted the example branch March 26, 2020 09:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write minimal example
3 participants