Skip to content

DHT refactoring #161

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

Merged
merged 4 commits into from
Jun 25, 2018
Merged

DHT refactoring #161

merged 4 commits into from
Jun 25, 2018

Conversation

kurnevsky
Copy link
Member

@kurnevsky kurnevsky commented Jun 23, 2018

This PR:

  • implements advanced LAN discovery from friend_connection.c
  • moves onion key refreshing to dht_main_loop
  • simplifies dht_server example

I decided to leave LAN discovery wake ups separated from dht_main_loop since:

  • it'd have required adding additional argument to server
  • LAN discovery is optional so if it's disabled we don't need LAN wake ups at all (at least in bootstrap server).

let server = server.join(lossless_handler).map(|_| ());
let server = server.join(lossy_handler).map(|_| ());
let server: IoFuture<()> = Box::new(network); // TODO: remove these boxes on rustc 1.26
let server: IoFuture<()> = Box::new(server.join(run_server(&server_obj)).map(|_| ()));
Copy link
Member

Choose a reason for hiding this comment

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

use select instead of join

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you explain why you think that select is should be used here? With select you must assume that all these futures are infinite whereas join explicitly shows that application will be terminated when all these futures are completed.

Copy link
Member

@kpp kpp Jun 23, 2018

Choose a reason for hiding this comment

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

Because if any of the futures resolves, we should return immediately. In your case we will wait until all futures are terminated.

Right now all these futures are infinite so it is better to use .select. If the server stops with a resolved future we will notice that some of these futures resolved and stopped the server.

Copy link
Member Author

Choose a reason for hiding this comment

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

But in case if one future resolves with error join won't wait other futures.
And another argument for join - select modifies error type to either of errors, so I can't just change join to select, I'll have to add map_err for every line here.

Copy link
Member

@kpp kpp Jun 25, 2018

Choose a reason for hiding this comment

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

A simple rule:

  • use select if you don't have to wait for the other futures to resolve.
  • use join if you need to wait for them.

Do we need to wait for other futures?

use futures::{Future, Stream};

macro_rules! unpack {
($variable:expr, $variant:path) => (
Copy link
Member

Choose a reason for hiding this comment

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

How about moving this macro definition to binary_io.rs.
Because this macro is used commonly in many files.

@kpp kpp merged commit 3d0ddf8 into master Jun 25, 2018
@kpp kpp deleted the dht_refactoring branch June 25, 2018 20:09
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.

3 participants