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

Implement ConnectionReuse correctly #111

Closed
wants to merge 19 commits into from

Conversation

tomaka
Copy link
Member

@tomaka tomaka commented Jan 24, 2018

The current implementation is a dummy. This PR replaces it with a better one.

Copy link
Contributor

@debris debris left a comment

Choose a reason for hiding this comment

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

lgtm. Would be just nice to add more comments/explanations in few places, so the next person looking into this code understand better what's going on :)

to_signal: Vec<task::Task>,
struct Shared<M> where M: StreamMuxer {
// List of active muxers.
active_connections: FnvHashMap<Multiaddr, M>,
Copy link
Contributor

Choose a reason for hiding this comment

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

fnv is faster for small keys. do you know what is the threshold? when the key is considered to be 'short' and when it is not 'short' any more? I'm just curious

Copy link
Member Author

Choose a reason for hiding this comment

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

I found this (old) link: http://cglab.ca/~abeinges/blah/hash-rs/
Most the time the multiaddr will be something like /ip4/a.b.c.d/tcp/e which is 8 bytes. Fnv may indeed be more appropriate here.

@@ -127,31 +142,36 @@ where
}

fn dial(self, addr: Multiaddr) -> Result<Self::Dial, (Self, Multiaddr)> {
Copy link
Contributor

Choose a reason for hiding this comment

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

what does Err variant represent? and in what cases is it returned?

Copy link
Member Author

Choose a reason for hiding this comment

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

Happens if the multiaddress is invalid or not supported. This should be documented in the Transport trait if it isn't the case.

{
type Item = (O, Multiaddr);
type Item = (future::FutureResult<M::Substream, IoError>, Multiaddr);
Copy link
Contributor

Choose a reason for hiding this comment

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

what does item represent and how should each case be handled?

@@ -233,7 +235,7 @@ impl<T, C, H, If, F> Future for SwarmFuture<T, C, H, F>
self.listeners.push(listener);
},
Ok(Async::Ready(None)) => {},
Err(err) => return Err(err),
Err(_err) => {}, // Ignoring errors
Copy link
Contributor

Choose a reason for hiding this comment

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

why are errors being ignored here?

Copy link
Member Author

Choose a reason for hiding this comment

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

An error happens if the remote sends us bad data, so we just drop the connection. This probably needs a comment and a log entry.

// We extract everything at the start, then insert back the elements that we still want at
// the next iteration.
for n in (0 .. self.connections.len()).rev() {
let (muxer, mut next_incoming, client_addr) = self.connections.swap_remove(n);
Copy link
Contributor

Choose a reason for hiding this comment

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

formatting is inconsistent here (spaces)


// Check whether any upgrade (to a muxer) on an incoming connection is ready.
for n in (0 .. self.current_upgrades.len()).rev() {
let (mut current_upgrade, client_addr) = self.current_upgrades.swap_remove(n);
match current_upgrade.poll() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Mixed tabs and spaces

Ok(Async::Ready(None)) | Err(_) => {
// The sender and receiver are both in the same struct, therefore the link can
// never break.
unreachable!()
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this comment into a string inside unreachable!


for (offset, future) in lock.incoming.iter_mut().enumerate() {
// Check whether any incoming substream is ready.
for n in (0 .. lock.next_incoming.len()).rev() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Mixed tabs and spaces

@@ -874,26 +891,31 @@ where
///
/// This function returns the next incoming substream. You are strongly encouraged to call it
/// if you have a muxed transport.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe word this "Muxed transports may block processing incoming connections if this function is not called" or similar, "strongly encouraged" is unhelpful and obscure.

upgrade.upgrade(connection, upgrade_id, Endpoint::Dialer, &addr)
.map(|u| (u, addr))
});
.map(|(future, addr)| {
Copy link
Contributor

Choose a reason for hiding this comment

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

Mixed tabs and spaces

@tomaka
Copy link
Member Author

tomaka commented Mar 7, 2018

Closing in favour of #117

@tomaka tomaka closed this Mar 7, 2018
@tomaka tomaka deleted the connection-reuse-correct branch March 7, 2018 10:29
tomaka added a commit that referenced this pull request Mar 7, 2018
* Implement ConnectionReuse correctly

* Add some tests and fixes

* Remove useless boolean in active_connections

* Correctly run tests

* Optimize the processing

* Next incoming is now in two steps

* Remove log

* Fix dialing a node even if we already have a connection

* Add a proper PeerId to Peerstore

* Turn identify into a transport layer

* Expose the dialed multiaddress

* Add identified nodes to the peerstore

* Allow configuring the TTL of the addresses

* Split identify in two modules

* Some comments and tweaks

* Run rustfmt

* Add test and bugfix

* Fix wrong address reported when dialing

* Fix websocket browser code

* Ignore errors in the swarm

* Fix multiplex test

* Fix some style concerns

* Fix concerns
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