Add replay safety method and callback to AsyncTransport.
authorKyle Nekritz <knekritz@fb.com>
Fri, 4 Mar 2016 22:28:22 +0000 (14:28 -0800)
committerFacebook Github Bot 3 <facebook-github-bot-3-bot@fb.com>
Fri, 4 Mar 2016 22:35:20 +0000 (14:35 -0800)
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

folly/io/async/AsyncTransport.h
folly/io/async/test/MockAsyncTransport.h

index 8919ab346f42c07df361c59daa477501a9a46727..08ba3284a028bc4c3c8acef61e0270f64197c15f 100644 (file)
@@ -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;
 };
index 5ad241c1fa41363b91170885d3c0731125ca753f..8b4e9228b4e55b82dd944b2ca9f01fbcab1b188b 100644 (file)
@@ -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*));