lightning-terminal
lightning-terminal copied to clipboard
Enhancement: reliable transition from first to second handshake
This is a tracking issue for a known possible race that could occur. It doesn't seem to have been surfaced as actually happening at all but want to make an issue so that we can deal with it in future as I feel it is bound come up at some point.
Basically, with the shift to LNC handshake v2, what we do is we create the first connection of a session using v1 which will require the client and server to meet at the mailbox using SID 1. Then once the first handshake is complete and both sides have the other sides static key, then any future connection will be made with handshake v2 meeting at the mailbox using SID 2.
The deciding factor used for each side to decide to create the mailbox using SID1 or SID2 is if they do or do not have the remote static key stored. And since one side will get the remote key they need before the other side gets the one that they need, there is this "limbo" state in the first handshake where if both sides shutdown at that point then one side will have what they need to meet at mailbox SID2 but the other side wont yet and so will try to meet again at SID1.
The window for this limbo state is incredibly small. Basically, if you connect using an LNC session and the first handshake is complete and you are successfully exchanging info with the server, then you are good to go and you know for a fact that the next time you reconnect, both of you will switch over to mailbox SID2. So basically the coast is clear after the first handshake is complete. And I imagine that if someone does run into this race during the very first connection, they would just create a new session.