Closed avieth closed 7 years ago
@edsko @dcoutts
This looks good to me. I think we should also rename remoteMaxIncoming
to remoteLastIncoming
, but the code for updating it is already correct (it was not doing any max
calc, just relying on increasing sequences).
This looks good to me. I think we should also rename remoteMaxIncoming to remoteLastIncoming, but the code for updating it is already correct (it was not doing any max calc, just relying on increasing sequences).
Done
I think this is good to merge. @qnikst any objections?
everything ok from my side.
Given a pair of endpoints, each of them knows
In order to close the socket, the peers must agree on these: locally- created of A must match remotely-created of B, and remotely-created of A must match locally-created of B.
When A sends CloseSocket, it can be sure that when it reaches B, B will have seen all of A's locally-created connections (property of TCP), so locally-created of A certainly matches remotely-created of B. To verify the other half, A sends its latest observed remotely-created connection identifier, and B just has to check that it matches its latest locally-created identifier. There's no need to use ordering, equality is enough.
The protocol is now more liberal: you don't have to allocate connection identifiers monotonically, you just have to ensure that they have a sufficiently long period. A period of n means that n in-flight CreatedNewConnection messages would give a false positive on the equality test.
The check for outgoing connections is still present, but it only detects a protocol error by the peer. If they agree on the latest connection identifier, but they send CloseSocket while we have outgoing connections, then they've tried to close the socket too early. There's a test case for this (testEarlyCloseSocket) demanding that EventConnectionLost is posted in this case.