First bug is that when a server processes two ClientHellos for the same host, they will race and one will get stomped. This causes a memory leak from undisposed state as well as unsync'd state from the mishandled Handshake. This is 100% repro'd by DtlsConnectionTests.ConnectLikeAJerk. A double check pattern fixes this, but will affect the rate at which we can accept new connections.
Second is that if a client sends two ClientHellos with no Cookie information, the server sends back the cookie in HelloVerifyRequest twice as well. Each HelloVerifyRequest would reset the client's ClientRandom and resend it to the server. The server would have a 50/50 chance of accepting the right ClientRandom, but won't find out until verifying the final connection. This repros very consistently by DtlsConnectionTests.ConnectLikeAJerk, but can also repro by DtlsConnectionTests.TestResentClientHelloConnects. This is fixed by not rotating the ClientRandom unless we are also rotating the Cookie.
Bonus bug: SocketCapture was reusing its buffer which could cause torn packets during tests.
Bonus optimization: PeerData was reset twice when created. One with defaults and immediate with real values. Not anymore.
First bug is that when a server processes two ClientHellos for the same host, they will race and one will get stomped. This causes a memory leak from undisposed state as well as unsync'd state from the mishandled Handshake. This is 100% repro'd by DtlsConnectionTests.ConnectLikeAJerk. A double check pattern fixes this, but will affect the rate at which we can accept new connections.
Second is that if a client sends two ClientHellos with no Cookie information, the server sends back the cookie in HelloVerifyRequest twice as well. Each HelloVerifyRequest would reset the client's ClientRandom and resend it to the server. The server would have a 50/50 chance of accepting the right ClientRandom, but won't find out until verifying the final connection. This repros very consistently by DtlsConnectionTests.ConnectLikeAJerk, but can also repro by DtlsConnectionTests.TestResentClientHelloConnects. This is fixed by not rotating the ClientRandom unless we are also rotating the Cookie.
Bonus bug: SocketCapture was reusing its buffer which could cause torn packets during tests.
Bonus optimization: PeerData was reset twice when created. One with defaults and immediate with real values. Not anymore.
Various other bonus renames for clarity.