-
Notifications
You must be signed in to change notification settings - Fork 411
Encrypt ping messages before sending them #506
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
Encrypt ping messages before sending them #506
Conversation
lightning/src/ln/peer_handler.rs
Outdated
@@ -1209,7 +1216,8 @@ mod tests { | |||
assert_eq!(peers[0].peers.lock().unwrap().peers.len(), 1); | |||
|
|||
// 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
lightning/src/ln/peer_handler.rs
Outdated
// 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
lightning/src/ln/peer_handler.rs
Outdated
@@ -1209,7 +1216,8 @@ mod tests { | |||
assert_eq!(peers[0].peers.lock().unwrap().peers.len(), 1); | |||
|
|||
// 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 |
There was a problem hiding this comment.
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.
lightning/src/ln/peer_handler.rs
Outdated
// 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; | ||
} |
There was a problem hiding this comment.
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.
It’s intended to reference a file descriptor, which is, in fact, an index in a map, but also a token to be able to send data to a socket (which, of course, for us, has to be generic).
… On Feb 19, 2020, at 12:44, Arik Sosman ***@***.***> wrote:
@arik-so commented on this pull request.
In lightning/src/ln/peer_handler.rs:
> @@ -1209,7 +1216,8 @@ mod tests {
assert_eq!(peers[0].peers.lock().unwrap().peers.len(), 1);
// 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
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.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
There was a problem hiding this 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?
lightning/src/ln/peer_handler.rs
Outdated
peer.awaiting_pong = true; | ||
true | ||
} | ||
peer.awaiting_pong = !peer.awaiting_pong; // flip the condition |
There was a problem hiding this comment.
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?
beb0be0
to
d93bc3d
Compare
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. |
I thought I had fixed it, let me check.
… On Feb 19, 2020, at 1:45 PM, Matt Corallo ***@***.***> wrote:
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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#506>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAHCOLVYTEOICMA5W3MTNPDRDWR75ANCNFSM4KXNQNIQ>.
|
Yeah, PSA on commit messages: |
…decrypt it instead of shutting down the connection.
d93bc3d
to
b317f52
Compare
lightning/src/ln/peer_handler.rs
Outdated
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, remove unused code.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :).
This fixes #504.