From: Kyle Nekritz Date: Fri, 4 Mar 2016 22:28:22 +0000 (-0800) Subject: Add replay safety method and callback to AsyncTransport. X-Git-Tag: deprecate-dynamic-initializer~7 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=cb8456bddf1fd695293d5668c4048f8d519c7f32;p=folly.git Add replay safety method and callback to AsyncTransport. Summary: This allows the transport to signal to a higher layer when it has become replay-safe. Reviewed By: siyengar Differential Revision: D2974057 fb-gh-sync-id: 436f0c66b78f72ad34cdf4fe117771ea96b4388b shipit-source-id: 436f0c66b78f72ad34cdf4fe117771ea96b4388b --- diff --git a/folly/io/async/AsyncTransport.h b/folly/io/async/AsyncTransport.h index 8919ab34..08ba3284 100644 --- a/folly/io/async/AsyncTransport.h +++ b/folly/io/async/AsyncTransport.h @@ -345,6 +345,38 @@ class AsyncTransport : public DelayedDestruction, public AsyncSocketBase { virtual void onEgressBufferCleared() = 0; }; + /** + * Callback class to signal when a transport that did not have replay + * protection gains replay protection. This is needed for 0-RTT security + * protocols. + */ + class ReplaySafetyCallback { + public: + virtual ~ReplaySafetyCallback() = default; + + /** + * Called when the transport becomes replay safe. + */ + virtual void onReplaySafe() = 0; + }; + + /** + * False if the transport does not have replay protection, but will in the + * future. + */ + virtual bool isReplaySafe() const { return true; } + + /** + * Set the ReplaySafeCallback on this transport. + * + * This should only be called if isReplaySafe() returns false. + */ + virtual void setReplaySafetyCallback(ReplaySafetyCallback* callback) { + if (callback) { + CHECK(false) << "setReplaySafetyCallback() not supported"; + } + } + protected: virtual ~AsyncTransport() = default; }; diff --git a/folly/io/async/test/MockAsyncTransport.h b/folly/io/async/test/MockAsyncTransport.h index 5ad241c1..8b4e9228 100644 --- a/folly/io/async/test/MockAsyncTransport.h +++ b/folly/io/async/test/MockAsyncTransport.h @@ -65,6 +65,11 @@ class MockAsyncTransport: public AsyncTransportWrapper { }; +class MockReplaySafetyCallback : public AsyncTransport::ReplaySafetyCallback { + public: + GMOCK_METHOD0_(, noexcept, , onReplaySafe, void()); +}; + class MockReadCallback: public AsyncTransportWrapper::ReadCallback { public: MOCK_METHOD2(getReadBuffer, void(void**, size_t*));