X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Fio%2Fasync%2FAsyncTransport.h;h=8af868f7b79e586bedf18a3d706e67eac2658363;hp=40dca58b8e18acb6f61303008268cf7d445490e6;hb=74261e41a1b94490607457e38b3b1c54cf6374a4;hpb=76fcf3897e2600b0dbd719d84f0143148caf107b diff --git a/folly/io/async/AsyncTransport.h b/folly/io/async/AsyncTransport.h index 40dca58b..8af868f7 100644 --- a/folly/io/async/AsyncTransport.h +++ b/folly/io/async/AsyncTransport.h @@ -1,5 +1,5 @@ /* - * Copyright 2015 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,11 +17,13 @@ #pragma once #include -#include +#include +#include #include #include -#include +#include +#include #include @@ -37,7 +39,6 @@ namespace folly { class AsyncSocketException; class EventBase; -class IOBuf; class SocketAddress; /* @@ -70,6 +71,14 @@ inline WriteFlags operator|(WriteFlags a, WriteFlags b) { static_cast(a) | static_cast(b)); } +/* + * compound assignment union operator + */ +inline WriteFlags& operator|=(WriteFlags& a, WriteFlags b) { + a = a | b; + return a; +} + /* * intersection operator */ @@ -78,6 +87,14 @@ inline WriteFlags operator&(WriteFlags a, WriteFlags b) { static_cast(a) & static_cast(b)); } +/* + * compound assignment intersection operator + */ +inline WriteFlags& operator&=(WriteFlags& a, WriteFlags b) { + a = a & b; + return a; +} + /* * exclusion parameter */ @@ -320,6 +337,18 @@ class AsyncTransport : public DelayedDestruction, public AsyncSocketBase { */ virtual void getPeerAddress(SocketAddress* address) const = 0; + /** + * Get the certificate used to authenticate the peer. + */ + virtual ssl::X509UniquePtr getPeerCert() const { return nullptr; } + + /** + * The local certificate used for this connection. May be null + */ + virtual const X509* getSelfCert() const { + return nullptr; + } + /** * @return True iff end of record tracking is enabled */ @@ -332,6 +361,45 @@ class AsyncTransport : public DelayedDestruction, public AsyncSocketBase { virtual size_t getAppBytesReceived() const = 0; virtual size_t getRawBytesReceived() const = 0; + class BufferCallback { + public: + virtual ~BufferCallback() {} + virtual void onEgressBuffered() = 0; + 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; }; @@ -419,6 +487,15 @@ class AsyncReader { return false; } + /** + * Suggested buffer size, allocated for read operations, + * if callback is movable and supports folly::IOBuf + */ + + virtual size_t maxBufferSize() const { + return 64 * 1024; // 64K + } + /** * readBufferAvailable() will be invoked when data has been successfully * read. @@ -432,7 +509,7 @@ class AsyncReader { */ virtual void readBufferAvailable(std::unique_ptr /*readBuf*/) - noexcept {}; + noexcept {} /** * readEOF() will be invoked when the transport is closed. @@ -566,6 +643,11 @@ class AsyncTransportWrapper : virtual public AsyncTransport, virtual std::string getApplicationProtocol() noexcept { return ""; } + + /** + * Returns the name of the security protocol being used. + */ + virtual std::string getSecurityProtocol() const { return ""; } }; } // folly