Skip to content

Conversation

@arik-so
Copy link
Contributor

@arik-so arik-so commented Feb 18, 2020

This fixes #504.

@arik-so arik-so requested a review from TheBlueMatt February 18, 2020 22:25
// Since timer_tick_occured() is called again when awaiting_pong is true, all Peers are disconnected
peers[0].timer_tick_occured();
assert_eq!(peers[0].peers.lock().unwrap().peers.len(), 0);
// TODO: simulate handshake completion to fully support ping exchange simulations
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just exchange the handshake? Shouldn't be that hard?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it's super trivial because the test needs to manually call the read events, but I'll give it a try. I originally thought it might be best reserved for a separate diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is proving to be mutex mess. I think it will be easier once one of (or preferably both) the modular handshake and the peer handler refactor into individual peer holders commits land. CC: @jkczyz

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have strong feelings about maintaining this test. It should be a few tests covering the different behaviors. Currently, it tests a subset of the behaviors and so will test a smaller subset when removing this part. It would probably be easier to test after refactoring, as you said.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, should be doable. Can you try building on the top commit on https://github.com/TheBlueMatt/rust-lightning/commits/2020-02-peer_handler-handshake

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wow, I had no idea you could use the descriptors for that

Copy link
Collaborator

Choose a reason for hiding this comment

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

Descriptors, ultimately, are an API for the PeerHandler to send data to a given socket. So that is, in fact, the only thing you can use the descriptors for :p

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. The word descriptor suggested to me that it's just something that describes the socket, aka to be used as a key to find it in the map.

Comment on lines 1089 to 1091
// check if the peer is ready for encryption
if !peer.channel_encryptor.is_ready_for_encryption() {
// let's wait for the peer to complete the handshake
Copy link
Contributor

Choose a reason for hiding this comment

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

The first comment doesn't add much; it simply restates the if expression. Could you replace it with the inner comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@TheBlueMatt TheBlueMatt added this to the 0.0.10 milestone Feb 19, 2020
// Since timer_tick_occured() is called again when awaiting_pong is true, all Peers are disconnected
peers[0].timer_tick_occured();
assert_eq!(peers[0].peers.lock().unwrap().peers.len(), 0);
// TODO: simulate handshake completion to fully support ping exchange simulations
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have strong feelings about maintaining this test. It should be a few tests covering the different behaviors. Currently, it tests a subset of the behaviors and so will test a smaller subset when removing this part. It would probably be easier to test after refactoring, as you said.

Comment on lines 1089 to 1093

// check if the peer is ready for encryption
// The peer needs to complete its handshake before we can exchange messages
if !peer.channel_encryptor.is_ready_for_encryption() {
// let's wait for the peer to complete the handshake
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd consider moving this before line 1078. The rationale being that this is a guard clause so what comes before does not need to be checked if this condition is true. That said, the above condition should be mutually exclusive with this one, so reordering should not affect the behavior.

@TheBlueMatt
Copy link
Collaborator

TheBlueMatt commented Feb 19, 2020 via email

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Looks good. One minor comment and can you squash the fixup commits?

peer.awaiting_pong = true;
true
}
peer.awaiting_pong = !peer.awaiting_pong; // flip the condition
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is pretty hard to read, can you just drop the peer at the top of this fn instead of waiting to the end and returning the awaiting_pong var?

@arik-so arik-so force-pushed the ping_encryption_fix branch from beb0be0 to d93bc3d Compare February 19, 2020 21:39
@TheBlueMatt
Copy link
Collaborator

Just a nit, but can you update the commit message? Just including the log of temp fixups that you pushed isn't really a useful commit message.

@arik-so
Copy link
Contributor Author

arik-so commented Feb 19, 2020 via email

@jkczyz
Copy link
Contributor

jkczyz commented Feb 19, 2020

Yeah, PSA on commit messages:

https://chris.beams.io/posts/git-commit/

…decrypt it instead of shutting down the connection.
@arik-so arik-so force-pushed the ping_encryption_fix branch from d93bc3d to b317f52 Compare February 19, 2020 22:09
peer_a.new_inbound_connection(fd.clone()).unwrap();
peer_a.peers.lock().unwrap().node_id_to_descriptor.insert(their_id, fd.clone());
let a_id = PublicKey::from_secret_key(&secp_ctx, &peer_a.our_node_secret);
//let b_id = PublicKey::from_secret_key(&secp_ctx, &peer_b.our_node_secret);
Copy link
Contributor

Choose a reason for hiding this comment

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

Eh, remove unused code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this code is actually directly taken from Matt's commit. If I remove it, will it cause you merging headaches, @TheBlueMatt?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oops, sorry, that was cause I was just playing and testing, you can remove it :).

@arik-so arik-so self-assigned this Feb 19, 2020
@TheBlueMatt TheBlueMatt merged commit 3e726c4 into lightningdevkit:master Feb 20, 2020
@TheBlueMatt TheBlueMatt modified the milestones: 0.0.10, 0.0.11 Feb 26, 2020
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.

Sending pings results in disconnection

3 participants