/*
- * 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.
#pragma once
#include <memory>
-#include <sys/uio.h>
+#include <folly/io/IOBuf.h>
+#include <folly/io/async/AsyncSocketBase.h>
#include <folly/io/async/DelayedDestruction.h>
#include <folly/io/async/EventBase.h>
-#include <folly/io/async/AsyncSocketBase.h>
+#include <folly/io/async/ssl/OpenSSLPtrTypes.h>
+#include <folly/portability/SysUio.h>
#include <openssl/ssl.h>
class AsyncSocketException;
class EventBase;
-class IOBuf;
class SocketAddress;
/*
static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
}
+/*
+ * compound assignment union operator
+ */
+inline WriteFlags& operator|=(WriteFlags& a, WriteFlags b) {
+ a = a | b;
+ return a;
+}
+
/*
* intersection operator
*/
static_cast<uint32_t>(a) & static_cast<uint32_t>(b));
}
+/*
+ * compound assignment intersection operator
+ */
+inline WriteFlags& operator&=(WriteFlags& a, WriteFlags b) {
+ a = a & b;
+ return a;
+}
+
/*
* exclusion parameter
*/
*/
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
*/
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;
};
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.
*/
virtual void readBufferAvailable(std::unique_ptr<IOBuf> /*readBuf*/)
- noexcept {};
+ noexcept {}
/**
* readEOF() will be invoked when the transport is closed.