summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2017-06-28 22:18:04 -0400
committerAndrew Morrow <acm@mongodb.com>2017-07-05 13:44:03 -0400
commit477a40cc79c11ac18839997daf4301c2e4c748b1 (patch)
tree11adda42b6626f3c5b62828036735f9205193c50
parent7ef55bff9aaf6f75fd6dc2a71c8df9ebae25053a (diff)
downloadmongo-477a40cc79c11ac18839997daf4301c2e4c748b1.tar.gz
SERVER-27198 Remove ASIO based MessagingPort implementation
Also, consolidate the libraries in util/net, as they don't seem to need to be separate.
-rw-r--r--src/mongo/client/SConscript6
-rw-r--r--src/mongo/client/dbclient.cpp11
-rw-r--r--src/mongo/db/SConscript2
-rw-r--r--src/mongo/db/auth/SConscript4
-rw-r--r--src/mongo/db/repl/SConscript13
-rw-r--r--src/mongo/db/s/SConscript1
-rw-r--r--src/mongo/executor/SConscript6
-rw-r--r--src/mongo/rpc/SConscript2
-rw-r--r--src/mongo/s/SConscript2
-rw-r--r--src/mongo/s/catalog/SConscript2
-rw-r--r--src/mongo/s/sharding_mongod_test_fixture.h1
-rw-r--r--src/mongo/s/sharding_test_fixture.h1
-rw-r--r--src/mongo/util/net/SConscript76
-rw-r--r--src/mongo/util/net/asio_message_port.cpp668
-rw-r--r--src/mongo/util/net/asio_message_port.h161
-rw-r--r--src/mongo/util/net/asio_ssl_context.cpp69
-rw-r--r--src/mongo/util/net/asio_ssl_context.h85
-rw-r--r--src/mongo/util/net/listen.cpp8
-rw-r--r--src/mongo/util/net/message_port_mock.cpp130
-rw-r--r--src/mongo/util/net/message_port_mock.h103
-rw-r--r--src/mongo/util/net/message_port_startup_param.cpp56
-rw-r--r--src/mongo/util/net/message_port_startup_param.h35
22 files changed, 28 insertions, 1414 deletions
diff --git a/src/mongo/client/SConscript b/src/mongo/client/SConscript
index 3d478ee246c..04a5bc5cce1 100644
--- a/src/mongo/client/SConscript
+++ b/src/mongo/client/SConscript
@@ -23,7 +23,7 @@ env.Library(
'mongo_uri.cpp',
],
LIBDEPS=[
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
]
)
@@ -126,7 +126,7 @@ env.CppUnitTest(
],
LIBDEPS=[
'$BUILD_DIR/mongo/rpc/command_status',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
'$BUILD_DIR/mongo/util/md5',
'authentication',
]
@@ -211,7 +211,7 @@ env.Library(
'remote_command_targeter_factory_mock.cpp',
],
LIBDEPS=[
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
'$BUILD_DIR/mongo/s/coreshard',
]
)
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp
index 1e4d3240714..c8ed8838994 100644
--- a/src/mongo/client/dbclient.cpp
+++ b/src/mongo/client/dbclient.cpp
@@ -65,9 +65,7 @@
#include "mongo/util/concurrency/mutex.h"
#include "mongo/util/debug_util.h"
#include "mongo/util/log.h"
-#include "mongo/util/net/asio_message_port.h"
#include "mongo/util/net/message_port.h"
-#include "mongo/util/net/message_port_startup_param.h"
#include "mongo/util/net/socket_exception.h"
#include "mongo/util/net/ssl_manager.h"
#include "mongo/util/net/ssl_options.h"
@@ -837,14 +835,7 @@ Status DBClientConnection::connectSocketOnly(const HostAndPort& serverAddress) {
<< ", address is invalid");
}
- if (isMessagePortImplASIO()) {
- // `_so_timeout` is in seconds.
- auto ms = representAs<int64_t>(std::floor(_so_timeout * 1000)).value_or(kMaxMillisCount);
- _port.reset(new ASIOMessagingPort(
- ms > kMaxMillisCount ? Milliseconds::max() : Milliseconds(ms), _logLevel));
- } else {
- _port.reset(new MessagingPort(_so_timeout, _logLevel));
- }
+ _port.reset(new MessagingPort(_so_timeout, _logLevel));
if (serverAddress.host().empty()) {
return Status(ErrorCodes::InvalidOptions,
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 63e288e27eb..fad8e64c954 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -449,7 +449,7 @@ env.Library(
'$BUILD_DIR/mongo/util/concurrency/spin_lock',
'$BUILD_DIR/mongo/util/decorable',
'$BUILD_DIR/mongo/util/fail_point',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
'$BUILD_DIR/mongo/util/periodic_runner',
'$BUILD_DIR/mongo/transport/transport_layer_common',
'logical_session_cache',
diff --git a/src/mongo/db/auth/SConscript b/src/mongo/db/auth/SConscript
index 68cb4fc0c30..24662f62a00 100644
--- a/src/mongo/db/auth/SConscript
+++ b/src/mongo/db/auth/SConscript
@@ -253,7 +253,7 @@ env.Library(
LIBDEPS=[
'authentication_restriction',
'$BUILD_DIR/mongo/base',
- '$BUILD_DIR/mongo/util/net/cidr',
+ '$BUILD_DIR/mongo/util/net/network',
],
)
@@ -263,7 +263,7 @@ env.CppUnitTest(
LIBDEPS=[
'address_restriction',
'$BUILD_DIR/mongo/base',
- '$BUILD_DIR/mongo/util/net/cidr',
+ '$BUILD_DIR/mongo/util/net/network',
],
)
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript
index 2aaa710346d..00b40204e8f 100644
--- a/src/mongo/db/repl/SConscript
+++ b/src/mongo/db/repl/SConscript
@@ -426,7 +426,6 @@ env.Library(
'$BUILD_DIR/mongo/client/clientdriver',
'$BUILD_DIR/mongo/db/auth/authcore',
'$BUILD_DIR/mongo/db/auth/authorization_manager_global',
- '$BUILD_DIR/mongo/util/net/hostandport',
'$BUILD_DIR/mongo/util/net/network',
],
)
@@ -499,7 +498,7 @@ env.Library(
'$BUILD_DIR/mongo/db/s/sharding',
'$BUILD_DIR/mongo/db/service_context',
'$BUILD_DIR/mongo/executor/task_executor_interface',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
],
)
@@ -815,7 +814,7 @@ env.Library(
'replication_process',
'$BUILD_DIR/mongo/db/namespace_string',
'$BUILD_DIR/mongo/db/service_context',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
'$BUILD_DIR/mongo/util/decorable',
],
)
@@ -890,7 +889,7 @@ env.Library('replica_set_messages',
'$BUILD_DIR/mongo/db/common',
'$BUILD_DIR/mongo/db/server_options_core',
'$BUILD_DIR/mongo/transport/transport_layer_common',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
'optime',
'read_concern_args',
])
@@ -1069,7 +1068,7 @@ env.Library(
'$BUILD_DIR/mongo/db/namespace_string',
'$BUILD_DIR/mongo/executor/task_executor_interface',
'$BUILD_DIR/mongo/rpc/metadata',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
],
)
@@ -1082,7 +1081,7 @@ env.Library(
'optime',
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/rpc/metadata',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
],
)
@@ -1315,7 +1314,7 @@ env.Library(
'oplog_entry',
'optime',
'replica_set_messages',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
],
)
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index 94d4ce8b128..da09542b192 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -264,7 +264,6 @@ env.CppUnitTest(
'$BUILD_DIR/mongo/executor/thread_pool_task_executor_test_fixture',
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_mock',
'$BUILD_DIR/mongo/s/coreshard',
- '$BUILD_DIR/mongo/util/net/message_port_mock',
'$BUILD_DIR/mongo/s/shard_server_test_fixture',
],
)
diff --git a/src/mongo/executor/SConscript b/src/mongo/executor/SConscript
index de73d0ba464..3c8bcf9c60a 100644
--- a/src/mongo/executor/SConscript
+++ b/src/mongo/executor/SConscript
@@ -13,7 +13,7 @@ env.Library(
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
])
env.Library(target='remote_command',
@@ -23,7 +23,7 @@ env.Library(target='remote_command',
],
LIBDEPS=[
'$BUILD_DIR/mongo/rpc/metadata',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
])
env.Library(target='task_executor_interface',
@@ -81,7 +81,7 @@ env.Library(
],
LIBDEPS=[
'$BUILD_DIR/mongo/base',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
'connection_pool_stats',
'remote_command',
],
diff --git a/src/mongo/rpc/SConscript b/src/mongo/rpc/SConscript
index 2db964ffe9f..8bcb6d45095 100644
--- a/src/mongo/rpc/SConscript
+++ b/src/mongo/rpc/SConscript
@@ -222,7 +222,7 @@ env.Library(
'$BUILD_DIR/mongo/transport/transport_layer',
"$BUILD_DIR/mongo/util/concurrency/spin_lock",
'$BUILD_DIR/mongo/util/decorable',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
"$BUILD_DIR/mongo/util/processinfo",
],
)
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index 9407707f369..d1ed34879ca 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -137,7 +137,6 @@ env.Library(
'$BUILD_DIR/mongo/s/coreshard',
'$BUILD_DIR/mongo/transport/transport_layer_mock',
'$BUILD_DIR/mongo/util/clock_source_mock',
- '$BUILD_DIR/mongo/util/net/message_port_mock',
'sharding_egress_metadata_hook_for_mongos',
],
)
@@ -174,7 +173,6 @@ env.Library(
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_manager_impl',
'$BUILD_DIR/mongo/s/coreshard',
'$BUILD_DIR/mongo/util/clock_source_mock',
- '$BUILD_DIR/mongo/util/net/message_port_mock',
],
)
diff --git a/src/mongo/s/catalog/SConscript b/src/mongo/s/catalog/SConscript
index b3b664d02bb..99f2ce723c6 100644
--- a/src/mongo/s/catalog/SConscript
+++ b/src/mongo/s/catalog/SConscript
@@ -101,7 +101,7 @@ env.Library(
'$BUILD_DIR/mongo/s/catalog/dist_lock_catalog_interface',
'$BUILD_DIR/mongo/s/client/sharding_client',
'$BUILD_DIR/mongo/s/write_ops/batch_write_types',
- '$BUILD_DIR/mongo/util/net/hostandport',
+ '$BUILD_DIR/mongo/util/net/network',
],
)
diff --git a/src/mongo/s/sharding_mongod_test_fixture.h b/src/mongo/s/sharding_mongod_test_fixture.h
index fca43abd45d..154366115fb 100644
--- a/src/mongo/s/sharding_mongod_test_fixture.h
+++ b/src/mongo/s/sharding_mongod_test_fixture.h
@@ -34,7 +34,6 @@
#include "mongo/db/service_context_d_test_fixture.h"
#include "mongo/executor/network_test_env.h"
#include "mongo/unittest/unittest.h"
-#include "mongo/util/net/message_port_mock.h"
namespace mongo {
diff --git a/src/mongo/s/sharding_test_fixture.h b/src/mongo/s/sharding_test_fixture.h
index c14ed25dd37..0e33ac1c562 100644
--- a/src/mongo/s/sharding_test_fixture.h
+++ b/src/mongo/s/sharding_test_fixture.h
@@ -34,7 +34,6 @@
#include "mongo/executor/network_test_env.h"
#include "mongo/transport/session.h"
#include "mongo/unittest/unittest.h"
-#include "mongo/util/net/message_port_mock.h"
namespace mongo {
diff --git a/src/mongo/util/net/SConscript b/src/mongo/util/net/SConscript
index 792ee8bd9b6..33dd488cb1b 100644
--- a/src/mongo/util/net/SConscript
+++ b/src/mongo/util/net/SConscript
@@ -5,101 +5,43 @@ Import('env')
env = env.Clone()
env.Library(
- target='hostandport',
- source=[
- 'hostandport.cpp',
- 'sockaddr.cpp',
- ],
- LIBDEPS=[
- '$BUILD_DIR/mongo/base',
- ],
-)
-
-env.CppUnitTest(
- target='hostandport_test',
- source=[
- 'hostandport_test.cpp'
- ],
- LIBDEPS=[
- 'hostandport',
- ],
-)
-
-env.Library(
- target='cidr',
- source=[
- 'cidr.cpp',
- ],
- LIBDEPS=[
- '$BUILD_DIR/mongo/base',
- ],
-)
-
-env.CppUnitTest(
- target='cidr_test',
- source=[
- 'cidr_test.cpp',
- ],
- LIBDEPS=[
- '$BUILD_DIR/mongo/base',
- 'cidr',
- ],
-)
-
-networkEnv = env.Clone();
-
-networkEnv.InjectThirdPartyIncludePaths(libraries=[
- 'asio',
-])
-
-networkEnv.Library(
target='network',
source=[
- "asio_message_port.cpp",
- "asio_ssl_context.cpp",
+ "cidr.cpp",
+ "hostandport.cpp",
"hostname_canonicalization.cpp",
"listen.cpp",
"message.cpp",
"message_port.cpp",
- "message_port_startup_param.cpp",
"op_msg.cpp",
"sock.cpp",
- 'socket_exception.cpp',
+ "sockaddr.cpp",
+ "socket_exception.cpp",
"socket_poll.cpp",
"ssl_expiration.cpp",
"ssl_manager.cpp",
"ssl_options.cpp",
"thread_idle_callback.cpp",
+
],
LIBDEPS=[
+ '$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/db/auth/auth_rolename',
'$BUILD_DIR/mongo/db/bson/dotted_path_support',
'$BUILD_DIR/mongo/db/server_options_core',
- '$BUILD_DIR/mongo/db/server_parameters',
'$BUILD_DIR/mongo/util/background_job',
'$BUILD_DIR/mongo/util/concurrency/ticketholder',
'$BUILD_DIR/mongo/util/decorable',
'$BUILD_DIR/mongo/util/fail_point',
'$BUILD_DIR/mongo/util/options_parser/options_parser',
- '$BUILD_DIR/third_party/shim_asio',
- 'cidr',
- 'hostandport',
- ],
-)
-
-env.Library(
- target='message_port_mock',
- source=[
- "message_port_mock.cpp",
- ],
- LIBDEPS=[
- 'network',
],
)
env.CppUnitTest(
- target='sock_test',
+ target='network_test',
source=[
+ 'cidr_test.cpp',
+ 'hostandport_test.cpp',
'sock_test.cpp',
],
LIBDEPS=[
diff --git a/src/mongo/util/net/asio_message_port.cpp b/src/mongo/util/net/asio_message_port.cpp
deleted file mode 100644
index f12be672592..00000000000
--- a/src/mongo/util/net/asio_message_port.cpp
+++ /dev/null
@@ -1,668 +0,0 @@
-/**
- * Copyright (C) 2016 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects
- * for all of the code used other than as permitted herein. If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so. If you do not
- * wish to do so, delete this exception statement from your version. If you
- * delete this exception statement from all source files in the program,
- * then also delete it in the license file.
- */
-
-#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kNetwork
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/util/net/asio_message_port.h"
-
-#include <set>
-
-#include "mongo/base/init.h"
-#include "mongo/base/static_assert.h"
-#include "mongo/config.h"
-#include "mongo/stdx/memory.h"
-#include "mongo/util/fail_point_service.h"
-#include "mongo/util/invariant.h"
-#include "mongo/util/log.h"
-#include "mongo/util/net/asio_ssl_context.h"
-#include "mongo/util/net/message.h"
-#include "mongo/util/net/socket_exception.h"
-#include "mongo/util/net/ssl_manager.h"
-#include "mongo/util/net/ssl_options.h"
-#include "mongo/util/scopeguard.h"
-
-namespace mongo {
-
-namespace {
-const char kGET[] = "GET";
-const int kHeaderLen = sizeof(MSGHEADER::Value);
-const int kInitialMessageSize = 1024;
-
-#ifdef MONGO_CONFIG_SSL
-struct ASIOSSLContextPair {
- ASIOSSLContext server;
- ASIOSSLContext client;
-};
-
-const auto sslDecoration = SSLManagerInterface::declareDecoration<ASIOSSLContextPair>();
-
-MONGO_INITIALIZER_WITH_PREREQUISITES(ASIOSSLContextSetup, ("SSLManager"))(InitializerContext*) {
- if (getSSLManager()) {
- sslDecoration(getSSLManager())
- .server.init(SSLManagerInterface::ConnectionDirection::kIncoming);
- sslDecoration(getSSLManager())
- .client.init(SSLManagerInterface::ConnectionDirection::kOutgoing);
- }
- return Status::OK();
-}
-#endif
-
-} // namespace
-
-ASIOMessagingPort::ASIOMessagingPort(int fd, SockAddr farEnd)
- : _service(1),
- _timer(_service),
- _creationTime(curTimeMicros64()),
- _timeout(),
- _remote(),
- _isEncrypted(false),
- _awaitingHandshake(true),
- _x509PeerInfo(),
- _bytesIn(0),
- _bytesOut(0),
- _logLevel(logger::LogSeverity::Log()),
- _connectionId(),
- _tag(),
-#ifdef MONGO_CONFIG_SSL
- _context(ASIOSSLContext()),
- _sslSock(_service,
- getSSLManager() ? sslDecoration(getSSLManager()).server.getContext()
- : _context->getContext()) {
- if (getSSLManager()) {
- _context = boost::none;
- }
- _sslSock.lowest_layer().assign(
- asio::generic::stream_protocol(farEnd.getType(),
- farEnd.getType() == AF_UNIX ? 0 : IPPROTO_TCP),
- fd);
-#else
- _sock(_service,
- asio::generic::stream_protocol(farEnd.getType(),
- farEnd.getType() == AF_UNIX ? 0 : IPPROTO_TCP),
- fd) {
-#endif // MONGO_CONFIG_SSL
- _getSocket().non_blocking(true);
- _remote = HostAndPort(farEnd.getAddr(), farEnd.getPort());
- _timer.expires_at(decltype(_timer)::time_point::max());
- _setTimerCallback();
-}
-
-ASIOMessagingPort::ASIOMessagingPort(Milliseconds timeout, logger::LogSeverity logLevel)
- : _service(1),
- _timer(_service),
- _creationTime(curTimeMicros64()),
- _timeout(timeout),
- _remote(),
- _isEncrypted(false),
- _awaitingHandshake(true),
- _x509PeerInfo(),
- _bytesIn(0),
- _bytesOut(0),
- _logLevel(logLevel),
- _connectionId(),
- _tag(),
-#ifdef MONGO_CONFIG_SSL
- _context(ASIOSSLContext()),
- _sslSock(_service,
- getSSLManager() ? sslDecoration(getSSLManager()).client.getContext()
- : _context->getContext()) {
- if (getSSLManager()) {
- _context = boost::none;
- }
-#else
- _sock(_service) {
-#endif // MONGO_CONFIG_SSL
- if (*_timeout == Milliseconds(0)) {
- _timeout = boost::none;
- }
- _timer.expires_at(decltype(_timer)::time_point::max());
- _setTimerCallback();
-}
-
-ASIOMessagingPort::~ASIOMessagingPort() {
- shutdown();
-}
-
-void ASIOMessagingPort::setTimeout(Milliseconds millis) {
- if (millis == Milliseconds(0)) {
- _timeout = boost::none;
- _timer.expires_at(decltype(_timer)::time_point::max());
- } else {
- _timeout = millis;
- }
-}
-
-void ASIOMessagingPort::shutdown() {
- if (!_inShutdown.swap(true)) {
- if (_getSocket().native_handle() >= 0) {
- _getSocket().cancel();
-
- stdx::lock_guard<stdx::mutex> opInProgressGuard(_opInProgress);
-
- _getSocket().close();
- _awaitingHandshake = true;
- _isEncrypted = false;
- }
- }
-}
-
-asio::error_code ASIOMessagingPort::_read(char* buf, std::size_t size) {
- invariant(buf);
-
- stdx::lock_guard<stdx::mutex> opInProgressGuard(_opInProgress);
-
- // Try to do optimistic reads.
- asio::error_code ec;
- std::size_t bytesRead;
- if (!_isEncrypted) {
- bytesRead = asio::read(_getSocket(), asio::buffer(buf, size), ec);
- }
-#ifdef MONGO_CONFIG_SSL
- else {
- bytesRead = asio::read(_sslSock, asio::buffer(buf, size), ec);
- }
-#endif
- if (!ec && bytesRead == size) {
- _bytesIn += size;
- }
- if (ec != asio::error::would_block) {
- return ec;
- }
-
- // Fall back to async with timer if the operation would block.
- if (_timeout) {
- _timer.expires_from_now(decltype(_timer)::duration(
- durationCount<Duration<decltype(_timer)::duration::period>>(*_timeout)));
- }
- if (!_isEncrypted) {
- asio::async_read(
- _getSocket(),
- asio::buffer(buf + bytesRead, size - bytesRead),
- [&ec, size, bytesRead](const asio::error_code& err, std::size_t size_read) {
- invariant(err || (size - bytesRead) == size_read);
- ec = err;
- });
- }
-#ifdef MONGO_CONFIG_SSL
- else {
- asio::async_read(
- _sslSock,
- asio::buffer(buf + bytesRead, size - bytesRead),
- [&ec, size, bytesRead](const asio::error_code& err, std::size_t size_read) {
- invariant(err || (size - bytesRead) == size_read);
- ec = err;
- });
- }
-#endif // MONGO_CONFIG_SSL
- do {
- _service.run_one();
- } while (ec == asio::error::would_block);
-
- if (!ec) {
- _bytesIn += size;
- }
- return ec;
-}
-
-asio::error_code ASIOMessagingPort::_write(const char* buf, std::size_t size) {
- invariant(buf);
-
- stdx::lock_guard<stdx::mutex> opInProgressGuard(_opInProgress);
-
- // Try to do optimistic writes.
- asio::error_code ec;
- std::size_t bytesWritten;
- if (!_isEncrypted) {
- bytesWritten = asio::write(_getSocket(), asio::buffer(buf, size), ec);
- }
-#ifdef MONGO_CONFIG_SSL
- else {
- bytesWritten = asio::write(_sslSock, asio::buffer(buf, size), ec);
- }
-#endif
- if (!ec && bytesWritten == size) {
- _bytesOut += size;
- }
- if (ec != asio::error::would_block) {
- return ec;
- }
-
- // Fall back to async with timer if the operation would block.
- if (_timeout) {
- _timer.expires_from_now(decltype(_timer)::duration(
- durationCount<Duration<decltype(_timer)::duration::period>>(*_timeout)));
- }
-
- if (!_isEncrypted) {
- asio::async_write(
- _getSocket(),
- asio::buffer(buf + bytesWritten, size - bytesWritten),
- [&ec, size, bytesWritten](const asio::error_code& err, std::size_t size_written) {
- invariant(err || (size - bytesWritten) == size_written);
- ec = err;
- });
- }
-#ifdef MONGO_CONFIG_SSL
- else {
- asio::async_write(
- _sslSock,
- asio::buffer(buf + bytesWritten, size - bytesWritten),
- [&ec, size, bytesWritten](const asio::error_code& err, std::size_t size_written) {
- invariant(err || (size - bytesWritten) == size_written);
- ec = err;
- });
- }
-#endif // MONGO_CONFIG_SSL
- do {
- _service.run_one();
- } while (ec == asio::error::would_block);
-
- if (!ec) {
- _bytesOut += size;
- }
- return ec;
-}
-
-asio::error_code ASIOMessagingPort::_handshake(bool isServer, const char* buf, std::size_t size) {
-#ifdef MONGO_CONFIG_SSL
- auto handshakeType = isServer ? decltype(_sslSock)::server : decltype(_sslSock)::client;
-
- stdx::lock_guard<stdx::mutex> opInProgressGuard(_opInProgress);
-
- if (_timeout) {
- _timer.expires_from_now(decltype(_timer)::duration(
- durationCount<Duration<decltype(_timer)::duration::period>>(*_timeout)));
- }
-
- asio::error_code ec = asio::error::would_block;
- if (buf) {
- _sslSock.async_handshake(handshakeType,
- asio::buffer(buf, size),
- [&ec](const asio::error_code& err, std::size_t) { ec = err; });
- } else {
- _sslSock.async_handshake(handshakeType, [&ec](const asio::error_code& err) { ec = err; });
- }
-
- do {
- _service.run_one();
- } while (ec == asio::error::would_block);
-
- return ec;
-#else
- return asio::error::operation_not_supported;
-#endif
-}
-
-const asio::generic::stream_protocol::socket& ASIOMessagingPort::_getSocket() const {
-#ifdef MONGO_CONFIG_SSL
- return _sslSock.next_layer();
-#else
- return _sock;
-#endif
-}
-
-asio::generic::stream_protocol::socket& ASIOMessagingPort::_getSocket() {
- return const_cast<asio::generic::stream_protocol::socket&>(
- const_cast<const ASIOMessagingPort*>(this)->_getSocket());
-}
-
-bool ASIOMessagingPort::recv(Message& m) {
- try {
- if (getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")->shouldFail()) {
- throw SocketException(SocketException::RECV_ERROR, "fail point set");
- }
- SharedBuffer buf = SharedBuffer::allocate(kInitialMessageSize);
- MsgData::View md = buf.get();
-
- asio::error_code ec = _read(md.view2ptr(), kHeaderLen);
- if (ec) {
- if (ec == asio::error::misc_errors::eof) {
- // When the socket is closed, no need to log an error.
- return false;
- }
- throw asio::system_error(ec);
- }
-
- if (_awaitingHandshake) {
- MONGO_STATIC_ASSERT_MSG(sizeof(kGET) - 1 <= kHeaderLen,
- "HTTP GET string must be smaller than the message header.");
- if (memcmp(md.view2ptr(), kGET, strlen(kGET)) == 0) {
- std::string httpMsg =
- "It looks like you are trying to access MongoDB over HTTP on the native driver "
- "port.\n";
- LOG(_logLevel) << httpMsg;
- std::stringstream ss;
- ss << "HTTP/1.0 200 OK\r\nConnection: close\r\nContent-Type: "
- "text/plain\r\nContent-Length: "
- << httpMsg.size() << "\r\n\r\n"
- << httpMsg;
- auto s = ss.str();
- send(s.c_str(), s.size(), nullptr);
- return false;
- }
-#ifndef MONGO_CONFIG_SSL
- // If responseTo is not 0 or -1 for first packet assume SSL
- if (md.getResponseToMsgId() != 0 && md.getResponseToMsgId() != -1) {
- uasserted(40130,
- "SSL handshake requested, SSL feature not available in this build");
- }
-#else
- if (md.getResponseToMsgId() != 0 && md.getResponseToMsgId() != -1) {
- uassert(40131,
- "SSL handshake received but server is started without SSL support",
- sslGlobalParams.sslMode.load() != SSLParams::SSLMode_disabled);
-
- auto ec = _handshake(true, md.view2ptr(), kHeaderLen);
- if (ec) {
- throw asio::system_error(ec);
- }
-
- auto swPeerInfo =
- getSSLManager()->parseAndValidatePeerCertificate(_sslSock.native_handle(), "");
- if (!swPeerInfo.isOK()) {
- throw SocketException(SocketException::CONNECT_ERROR,
- swPeerInfo.getStatus().reason());
- }
- setX509PeerInfo(swPeerInfo.getValue().get_value_or(SSLPeerInfo()));
-
- _isEncrypted = true;
- _awaitingHandshake = false;
- return recv(m);
- }
- uassert(40132,
- "The server is configured to only allow SSL connections",
- sslGlobalParams.sslMode.load() != SSLParams::SSLMode_requireSSL);
-
-#endif // MONGO_CONFIG_SSL
- _awaitingHandshake = false;
- }
-
- int msgLen = md.getLen();
-
- if (static_cast<size_t>(msgLen) < sizeof(MSGHEADER::Value) ||
- static_cast<size_t>(msgLen) > MaxMessageSizeBytes) {
- LOG(_logLevel) << "recv(): message len " << msgLen << " is invalid. "
- << "Min: " << sizeof(MSGHEADER::Value)
- << ", Max: " << MaxMessageSizeBytes;
- return false;
- }
-
- if (msgLen > kInitialMessageSize) {
- buf.realloc(msgLen);
- md = buf.get();
- }
-
- ec = _read(md.data(), msgLen - kHeaderLen);
- if (ec) {
- throw asio::system_error(ec);
- }
-
- m.setData(std::move(buf));
- return true;
-
- } catch (const asio::system_error& e) {
- LOG(_logLevel) << "SocketException: remote: " << remote() << " error: " << redact(e.what());
- m.reset();
- return false;
- }
-}
-
-void ASIOMessagingPort::reply(Message& received, Message& response) {
- say(response, received.header().getId());
-}
-
-void ASIOMessagingPort::reply(Message& received, Message& response, int32_t responseToMsgId) {
- say(response, responseToMsgId);
-}
-
-bool ASIOMessagingPort::call(Message& toSend, Message& response) {
- try {
- say(toSend);
- } catch (const asio::system_error&) {
- return false;
- }
- bool success = recv(response);
- if (success) {
- if (response.header().getResponseToMsgId() != toSend.header().getId()) {
- response.reset();
- uasserted(40133, "Response ID did not match the sent message ID.");
- }
- }
- return success;
-}
-
-void ASIOMessagingPort::say(Message& toSend, int responseTo) {
- invariant(!toSend.empty());
- toSend.header().setId(nextMessageId());
- toSend.header().setResponseToMsgId(responseTo);
- return say(const_cast<const Message&>(toSend));
-}
-
-void ASIOMessagingPort::say(const Message& toSend) {
- invariant(!toSend.empty());
- auto buf = toSend.buf();
- if (buf) {
- send(buf, MsgData::ConstView(buf).getLen(), nullptr);
- }
-}
-
-unsigned ASIOMessagingPort::remotePort() const {
- return _remote.port();
-}
-
-HostAndPort ASIOMessagingPort::remote() const {
- return _remote;
-}
-
-SockAddr ASIOMessagingPort::remoteAddr() const {
- return SockAddr(_remote.host(), _remote.port(), AF_UNSPEC);
-}
-
-SockAddr ASIOMessagingPort::localAddr() const {
- auto ep = _getSocket().local_endpoint();
- switch (ep.protocol().family()) {
- case AF_INET:
- case AF_INET6: {
- asio::ip::tcp::endpoint tcpEP;
- tcpEP.resize(ep.size());
- memcpy(tcpEP.data(), ep.data(), ep.size());
- return SockAddr(tcpEP.address().to_string(), tcpEP.port(), ep.protocol().family());
- }
-#ifndef _WIN32
- case AF_UNIX: {
- asio::local::stream_protocol::endpoint localEP;
- localEP.resize(ep.size());
- memcpy(localEP.data(), ep.data(), ep.size());
- return SockAddr(localEP.path(), 0, AF_UNIX);
- }
-#endif // _WIN32
- default: { MONGO_UNREACHABLE; }
- }
-}
-
-void ASIOMessagingPort::send(const char* data, int len, const char*) {
- if (getGlobalFailPointRegistry()->getFailPoint("throwSockExcep")->shouldFail()) {
- throw SocketException(SocketException::SEND_ERROR, "fail point set");
- }
- asio::error_code ec = _write(data, len);
- if (ec) {
- throw SocketException(SocketException::SEND_ERROR, asio::system_error(ec).what());
- }
-}
-
-void ASIOMessagingPort::send(const std::vector<std::pair<char*, int>>& data, const char*) {
- for (auto&& pair : data) {
- send(pair.first, pair.second, nullptr);
- }
-}
-
-bool ASIOMessagingPort::connect(SockAddr& farEnd) {
- if (_timeout) {
- _timer.expires_from_now(decltype(_timer)::duration(
- durationCount<Duration<decltype(_timer)::duration::period>>(*_timeout)));
- }
- _remote = HostAndPort(farEnd.getAddr(), farEnd.getPort());
-
- asio::ip::tcp::resolver resolver(_service);
- asio::error_code ec = asio::error::would_block;
-
- stdx::lock_guard<stdx::mutex> opInProgressGuard(_opInProgress);
- if (farEnd.getType() == AF_UNIX) {
-#ifndef _WIN32
- asio::local::stream_protocol::endpoint endPoint(farEnd.getAddr());
- _getSocket().async_connect(endPoint, [&ec](const asio::error_code& err) { ec = err; });
-#else
- uasserted(40135, "Connect called on a Unix socket under windows build.");
-#endif // _WIN32
- } else {
- asio::ip::tcp::resolver::query query(_remote.host(), std::to_string(_remote.port()));
-
- resolver.async_resolve(
- query,
- [&ec, this](const asio::error_code& resolveErr, asio::ip::tcp::resolver::iterator i) {
- if (!resolveErr) {
- asio::ip::tcp::endpoint tcpEndpoint(*i);
- _getSocket().async_connect(tcpEndpoint,
- [&ec](const asio::error_code& err) { ec = err; });
- } else if (i == asio::ip::tcp::resolver::iterator()) {
- ec = asio::error::host_unreachable;
- }
- });
- }
-
- do {
- _service.run_one();
- } while (ec == asio::error::would_block);
-
- if (ec) {
- if (ec == asio::error::connection_refused) {
- LOG(_logLevel) << "Failed to connect to " << _remote << ", reason: Connection refused";
- } else if (ec == asio::error::connection_aborted && _timeout) {
- LOG(_logLevel) << "Failed to connect to " << _remote << " after " << _timeout->count()
- << " milliseconds, giving up.";
- } else {
- LOG(_logLevel) << "Failed to connect to " << _remote
- << ", reason: " << asio::system_error(ec).what();
- }
- return false;
- }
-
- _creationTime = curTimeMicros64();
- _awaitingHandshake = false;
- _getSocket().non_blocking(true);
- if (farEnd.getType() != AF_UNIX) {
- _getSocket().set_option(asio::ip::tcp::no_delay(true));
- }
-
- return true;
-}
-
-bool ASIOMessagingPort::secure(SSLManagerInterface* ssl, const std::string& remoteHost) {
-#ifdef MONGO_CONFIG_SSL
- auto ec = _handshake(false);
- if (ec) {
- return false;
- }
-
- auto swPeerInfo =
- getSSLManager()->parseAndValidatePeerCertificate(_sslSock.native_handle(), remoteHost);
- if (!swPeerInfo.isOK()) {
- throw SocketException(SocketException::CONNECT_ERROR, swPeerInfo.getStatus().reason());
- }
- setX509PeerInfo(swPeerInfo.getValue().get_value_or(SSLPeerInfo()));
-
- _isEncrypted = true;
- return true;
-#else
- return false;
-#endif
-}
-
-bool ASIOMessagingPort::isStillConnected() const {
- return _getSocket().is_open();
-}
-
-uint64_t ASIOMessagingPort::getSockCreationMicroSec() const {
- return _creationTime;
-}
-
-void ASIOMessagingPort::setLogLevel(logger::LogSeverity logLevel) {
- _logLevel = logLevel;
-}
-
-void ASIOMessagingPort::clearCounters() {
- _bytesIn = 0;
- _bytesOut = 0;
-}
-
-long long ASIOMessagingPort::getBytesIn() const {
- return _bytesIn;
-}
-
-long long ASIOMessagingPort::getBytesOut() const {
- return _bytesOut;
-}
-
-void ASIOMessagingPort::setX509PeerInfo(SSLPeerInfo x509PeerInfo) {
- _x509PeerInfo = std::move(x509PeerInfo);
-}
-
-const SSLPeerInfo& ASIOMessagingPort::getX509PeerInfo() const {
- return _x509PeerInfo;
-}
-
-void ASIOMessagingPort::setConnectionId(const long long connectionId) {
- _connectionId = connectionId;
-}
-
-long long ASIOMessagingPort::connectionId() const {
- return _connectionId;
-}
-
-void ASIOMessagingPort::setTag(const AbstractMessagingPort::Tag tag) {
- _tag = tag;
-}
-
-AbstractMessagingPort::Tag ASIOMessagingPort::getTag() const {
- return _tag;
-}
-
-void ASIOMessagingPort::_setTimerCallback() {
- _timer.async_wait([this](const asio::error_code& ec) {
- if (ec != asio::error::operation_aborted &&
- (_timer.expires_at() <= decltype(_timer)::clock_type::now())) {
- _getSocket().cancel();
- _timer.expires_at(decltype(_timer)::time_point::max());
- }
- _setTimerCallback();
- });
-}
-
-} // namespace mongo
diff --git a/src/mongo/util/net/asio_message_port.h b/src/mongo/util/net/asio_message_port.h
deleted file mode 100644
index 37280b0b714..00000000000
--- a/src/mongo/util/net/asio_message_port.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/**
- * Copyright (C) 2016 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects
- * for all of the code used other than as permitted herein. If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so. If you do not
- * wish to do so, delete this exception statement from your version. If you
- * delete this exception statement from all source files in the program,
- * then also delete it in the license file.
- */
-
-#pragma once
-
-#include <asio.hpp>
-#include <asio/system_timer.hpp>
-#include <boost/optional.hpp>
-#include <vector>
-
-#include "mongo/config.h"
-#include "mongo/platform/atomic_word.h"
-#include "mongo/stdx/mutex.h"
-#include "mongo/util/net/abstract_message_port.h"
-#include "mongo/util/net/asio_ssl_context.h"
-#include "mongo/util/net/message.h"
-#include "mongo/util/net/sockaddr.h"
-#include "mongo/util/time_support.h"
-
-#ifdef MONGO_CONFIG_SSL
-#include <asio/ssl.hpp>
-#endif
-
-namespace mongo {
-
-class ASIOMessagingPort final : public AbstractMessagingPort {
-public:
- /**
- * This is the "Ingress Constructor", used by the listener. For this, we already have a file
- * descriptor and address. This messaging port is already connected, and connect() should not be
- * called.
- */
- ASIOMessagingPort(int fd, SockAddr farEnd);
-
- /**
- * This is the "Egress Constructor", used by the dbclient. This messaging port is not connected
- * to any remote endpoint. In order to do any communications, the connect() method must be
- * called successfully.
- */
- ASIOMessagingPort(Milliseconds timeout, logger::LogSeverity logLevel);
-
- ~ASIOMessagingPort() override;
-
- void setTimeout(Milliseconds millis) override;
-
- void shutdown() override;
-
- bool call(Message& toSend, Message& response) override;
-
- bool recv(Message& m) override;
-
- void reply(Message& received, Message& response, int32_t responseToMsgId) override;
- void reply(Message& received, Message& response) override;
-
- void say(Message& toSend, int responseTo = 0) override;
- void say(const Message& toSend) override;
-
- void send(const char* data, int len, const char*) override;
- void send(const std::vector<std::pair<char*, int>>& data, const char*) override;
-
- bool connect(SockAddr& farEnd) override;
-
- HostAndPort remote() const override;
-
- unsigned remotePort() const override;
-
- SockAddr remoteAddr() const override;
-
- SockAddr localAddr() const override;
-
- bool isStillConnected() const override;
-
- uint64_t getSockCreationMicroSec() const override;
-
- void setLogLevel(logger::LogSeverity logLevel) override;
-
- void clearCounters() override;
-
- long long getBytesIn() const override;
-
- long long getBytesOut() const override;
-
- void setX509PeerInfo(SSLPeerInfo x509PeerInfo) override;
-
- const SSLPeerInfo& getX509PeerInfo() const override;
-
- void setConnectionId(const long long connectionId) override;
-
- long long connectionId() const override;
-
- void setTag(const AbstractMessagingPort::Tag tag) override;
-
- AbstractMessagingPort::Tag getTag() const override;
-
- bool secure(SSLManagerInterface* ssl, const std::string& remoteHost) override;
-
-private:
- void _setTimerCallback();
- asio::error_code _read(char* buf, std::size_t size);
- asio::error_code _write(const char* buf, std::size_t size);
- asio::error_code _handshake(bool isServer, const char* buf = nullptr, std::size_t size = 0);
- const asio::generic::stream_protocol::socket& _getSocket() const;
- asio::generic::stream_protocol::socket& _getSocket();
-
- asio::io_service _service;
-
- AtomicBool _inShutdown;
- stdx::mutex _opInProgress;
-
- asio::system_timer _timer;
- uint64_t _creationTime;
- boost::optional<Milliseconds> _timeout;
-
- HostAndPort _remote;
-
- bool _isEncrypted;
- bool _awaitingHandshake;
- SSLPeerInfo _x509PeerInfo;
-
- long long _bytesIn;
- long long _bytesOut;
-
- logger::LogSeverity _logLevel;
-
- long long _connectionId;
- AbstractMessagingPort::Tag _tag;
-
-#ifdef MONGO_CONFIG_SSL
- boost::optional<ASIOSSLContext> _context;
- asio::ssl::stream<asio::generic::stream_protocol::socket> _sslSock;
-#else
- asio::generic::stream_protocol::socket _sock;
-#endif
-};
-
-} // namespace mongo
diff --git a/src/mongo/util/net/asio_ssl_context.cpp b/src/mongo/util/net/asio_ssl_context.cpp
deleted file mode 100644
index eb9f4c2fa68..00000000000
--- a/src/mongo/util/net/asio_ssl_context.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Copyright (C) 2016 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects
- * for all of the code used other than as permitted herein. If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so. If you do not
- * wish to do so, delete this exception statement from your version. If you
- * delete this exception statement from all source files in the program,
- * then also delete it in the license file.
- */
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/config.h"
-#include "mongo/util/net/asio_ssl_context.h"
-
-#ifdef MONGO_CONFIG_SSL
-
-#include "mongo/base/init.h"
-#include "mongo/stdx/memory.h"
-
-#include <asio.hpp>
-#include <asio/ssl.hpp>
-
-namespace mongo {
-
-ASIOSSLContext::ASIOSSLContext()
- : _context(stdx::make_unique<asio::ssl::context>(asio::ssl::context::sslv23)),
- _mode(static_cast<SSLParams::SSLModes>(getSSLGlobalParams().sslMode.load())) {}
-
-ASIOSSLContext::ASIOSSLContext(ASIOSSLContext&& other) = default;
-
-ASIOSSLContext& ASIOSSLContext::operator=(ASIOSSLContext&& other) = default;
-
-void ASIOSSLContext::init(SSLManagerInterface::ConnectionDirection direction) {
- if (_mode != SSLParams::SSLMode_disabled) {
- uassertStatusOK(getSSLManager()->initSSLContext(
- _context->native_handle(), getSSLGlobalParams(), direction));
- }
-}
-
-asio::ssl::context& ASIOSSLContext::getContext() {
- return *_context;
-}
-
-SSLParams::SSLModes ASIOSSLContext::sslMode() const {
- return _mode;
-}
-
-} // namespace mongo
-
-#endif // MONGO_CONFIG_SSL
diff --git a/src/mongo/util/net/asio_ssl_context.h b/src/mongo/util/net/asio_ssl_context.h
deleted file mode 100644
index 53a68f1e1a3..00000000000
--- a/src/mongo/util/net/asio_ssl_context.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/**
- * Copyright (C) 2016 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects
- * for all of the code used other than as permitted herein. If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so. If you do not
- * wish to do so, delete this exception statement from your version. If you
- * delete this exception statement from all source files in the program,
- * then also delete it in the license file.
- */
-
-#pragma once
-
-#include "mongo/base/disallow_copying.h"
-#include "mongo/config.h"
-#include "mongo/util/net/ssl_manager.h"
-#include "mongo/util/net/ssl_options.h"
-
-#ifdef MONGO_CONFIG_SSL
-namespace asio {
-namespace ssl {
-class context;
-} // namespace ssl
-} // namespace asio
-
-namespace mongo {
-
-class ASIOSSLContext {
-public:
- MONGO_DISALLOW_COPYING(ASIOSSLContext);
-
- /**
- * A class to house the ASIO SSL context as well as the mongo SSL mode. This will be decorated
- * on to the SSLManager.
- */
- ASIOSSLContext();
-
- ASIOSSLContext(ASIOSSLContext&& other);
- ASIOSSLContext& operator=(ASIOSSLContext&& other);
-
- /**
- * This must be called before calling `getContext()`. This does all of the setup that requires
- * the SSLManager (which can't be done in construction due to this class being a decoration).
- */
- void init(SSLManagerInterface::ConnectionDirection direction);
-
- /**
- * A copy of the ASIO SSL context generated upon construction from the mongo::SSLParams.
- */
- asio::ssl::context& getContext();
-
- /**
- * The SSL operation mode. See enum SSLModes in ssl_options.h
- */
- SSLParams::SSLModes sslMode() const;
-
-private:
- std::unique_ptr<asio::ssl::context> _context;
- SSLParams::SSLModes _mode;
-};
-} // namespace mongo
-#else
-namespace mongo {
-
-// This is a dummy class for when we build without SSL.
-class ASIOSSLContext {};
-} // namespace mongo
-#endif // MONGO_CONFIG_SSL
diff --git a/src/mongo/util/net/listen.cpp b/src/mongo/util/net/listen.cpp
index 6e446f14ee1..c4177fda506 100644
--- a/src/mongo/util/net/listen.cpp
+++ b/src/mongo/util/net/listen.cpp
@@ -46,9 +46,7 @@
#include "mongo/util/concurrency/idle_thread_block.h"
#include "mongo/util/exit.h"
#include "mongo/util/log.h"
-#include "mongo/util/net/asio_message_port.h"
#include "mongo/util/net/message_port.h"
-#include "mongo/util/net/message_port_startup_param.h"
#include "mongo/util/net/ssl_manager.h"
#include "mongo/util/net/ssl_options.h"
#include "mongo/util/scopeguard.h"
@@ -600,11 +598,7 @@ void Listener::waitUntilListening() const {
void Listener::_accepted(const std::shared_ptr<Socket>& psocket, long long connectionId) {
std::unique_ptr<AbstractMessagingPort> port;
- if (isMessagePortImplASIO()) {
- port = stdx::make_unique<ASIOMessagingPort>(psocket->stealSD(), psocket->remoteAddr());
- } else {
- port = stdx::make_unique<MessagingPort>(psocket);
- }
+ port = stdx::make_unique<MessagingPort>(psocket);
port->setConnectionId(connectionId);
accepted(std::move(port));
}
diff --git a/src/mongo/util/net/message_port_mock.cpp b/src/mongo/util/net/message_port_mock.cpp
deleted file mode 100644
index c09d69f2bba..00000000000
--- a/src/mongo/util/net/message_port_mock.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-/**
- * Copyright (C) 2015 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kNetwork
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/util/net/message_port_mock.h"
-
-namespace mongo {
-
-using std::string;
-
-MessagingPortMock::MessagingPortMock() : AbstractMessagingPort(), _x509PeerInfo() {}
-MessagingPortMock::~MessagingPortMock() {}
-
-void MessagingPortMock::setTimeout(Milliseconds millis) {}
-
-void MessagingPortMock::shutdown() {}
-
-bool MessagingPortMock::call(Message& toSend, Message& response) {
- return true;
-}
-
-bool MessagingPortMock::recv(Message& m) {
- return true;
-}
-
-void MessagingPortMock::reply(Message& received, Message& response, int32_t responseToMsgId) {}
-void MessagingPortMock::reply(Message& received, Message& response) {}
-
-void MessagingPortMock::say(Message& toSend, int responseTo) {}
-void MessagingPortMock::say(const Message& toSend) {}
-
-bool MessagingPortMock::connect(SockAddr& farEnd) {
- return true;
-}
-
-void MessagingPortMock::send(const char* data, int len, const char* context) {}
-void MessagingPortMock::send(const std::vector<std::pair<char*, int>>& data, const char* context) {}
-
-HostAndPort MessagingPortMock::remote() const {
- return _remote;
-}
-
-unsigned MessagingPortMock::remotePort() const {
- return _remote.port();
-}
-
-SockAddr MessagingPortMock::remoteAddr() const {
- return SockAddr{};
-}
-
-SockAddr MessagingPortMock::localAddr() const {
- return SockAddr{};
-}
-
-bool MessagingPortMock::isStillConnected() const {
- return true;
-}
-
-void MessagingPortMock::setLogLevel(logger::LogSeverity logLevel) {}
-
-void MessagingPortMock::clearCounters() {}
-
-long long MessagingPortMock::getBytesIn() const {
- return 0;
-}
-
-long long MessagingPortMock::getBytesOut() const {
- return 0;
-}
-
-
-uint64_t MessagingPortMock::getSockCreationMicroSec() const {
- return 0;
-}
-
-void MessagingPortMock::setX509PeerInfo(SSLPeerInfo x509PeerInfo) {}
-
-const SSLPeerInfo& MessagingPortMock::getX509PeerInfo() const {
- return _x509PeerInfo;
-}
-
-void MessagingPortMock::setConnectionId(const long long connectionId) {}
-
-long long MessagingPortMock::connectionId() const {
- return 42;
-}
-
-void MessagingPortMock::setTag(const AbstractMessagingPort::Tag tag) {}
-
-AbstractMessagingPort::Tag MessagingPortMock::getTag() const {
- return 0;
-}
-
-bool MessagingPortMock::secure(SSLManagerInterface* ssl, const std::string& remoteHost) {
- return true;
-}
-
-void MessagingPortMock::setRemote(const HostAndPort& remote) {
- _remote = remote;
-}
-
-} // namespace mongo
diff --git a/src/mongo/util/net/message_port_mock.h b/src/mongo/util/net/message_port_mock.h
deleted file mode 100644
index bb7e8b678d7..00000000000
--- a/src/mongo/util/net/message_port_mock.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/**
- * Copyright (C) 2015 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects for
- * all of the code used other than as permitted herein. If you modify file(s)
- * with this exception, you may extend this exception to your version of the
- * file(s), but you are not obligated to do so. If you do not wish to do so,
- * delete this exception statement from your version. If you delete this
- * exception statement from all source files in the program, then also delete
- * it in the license file.
- */
-
-#pragma once
-
-#include <vector>
-
-#include "mongo/util/net/abstract_message_port.h"
-#include "mongo/util/net/message.h"
-#include "mongo/util/net/sockaddr.h"
-
-namespace mongo {
-
-class MessagingPortMock final : public AbstractMessagingPort {
- MONGO_DISALLOW_COPYING(MessagingPortMock);
-
-public:
- MessagingPortMock();
- ~MessagingPortMock();
-
- void setTimeout(Milliseconds millis) override;
-
- void shutdown() override;
-
- bool call(Message& toSend, Message& response) override;
-
- bool recv(Message& m) override;
-
- void reply(Message& received, Message& response, int32_t responseToMsgId) override;
- void reply(Message& received, Message& response) override;
-
- void say(Message& toSend, int responseTo = 0) override;
- void say(const Message& toSend) override;
-
- bool connect(SockAddr& farEnd) override;
-
- void send(const char* data, int len, const char* context) override;
- void send(const std::vector<std::pair<char*, int>>& data, const char* context) override;
-
- HostAndPort remote() const override;
- unsigned remotePort() const override;
- SockAddr remoteAddr() const override;
- SockAddr localAddr() const override;
-
- bool isStillConnected() const override;
-
- void setLogLevel(logger::LogSeverity logLevel) override;
-
- void clearCounters() override;
-
- long long getBytesIn() const override;
-
- long long getBytesOut() const override;
-
- uint64_t getSockCreationMicroSec() const override;
-
- void setX509PeerInfo(SSLPeerInfo x509PeerInfo) override;
-
- const SSLPeerInfo& getX509PeerInfo() const override;
-
- void setConnectionId(const long long connectionId) override;
-
- long long connectionId() const override;
-
- void setTag(const AbstractMessagingPort::Tag tag) override;
-
- AbstractMessagingPort::Tag getTag() const override;
-
- bool secure(SSLManagerInterface* ssl, const std::string& remoteHost) override;
-
- void setRemote(const HostAndPort& remote);
-
-private:
- HostAndPort _remote;
- SSLPeerInfo _x509PeerInfo;
-};
-
-} // namespace mongo
diff --git a/src/mongo/util/net/message_port_startup_param.cpp b/src/mongo/util/net/message_port_startup_param.cpp
deleted file mode 100644
index 704de92b012..00000000000
--- a/src/mongo/util/net/message_port_startup_param.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * Copyright (C) 2016 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects
- * for all of the code used other than as permitted herein. If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so. If you do not
- * wish to do so, delete this exception statement from your version. If you
- * delete this exception statement from all source files in the program,
- * then also delete it in the license file.
- */
-
-#include "mongo/platform/basic.h"
-
-#include "mongo/base/init.h"
-#include "mongo/db/server_parameters.h"
-
-namespace mongo {
-
-namespace {
-
-const char kMessagePortImplASIO[] = "ASIO";
-const char kMessagePortImplLegacy[] = "legacy";
-
-MONGO_EXPORT_STARTUP_SERVER_PARAMETER(messagePortImpl, std::string, kMessagePortImplLegacy);
-
-MONGO_INITIALIZER(messagePortImpl)(InitializerContext*) {
- if ((messagePortImpl != kMessagePortImplASIO) && (messagePortImpl != kMessagePortImplLegacy)) {
- return Status(ErrorCodes::BadValue, "unsupported message port option: " + messagePortImpl);
- }
- return Status::OK();
-}
-
-} // namespace
-
-bool isMessagePortImplASIO() {
- return messagePortImpl == kMessagePortImplASIO;
-}
-
-} // namespace mongo
diff --git a/src/mongo/util/net/message_port_startup_param.h b/src/mongo/util/net/message_port_startup_param.h
deleted file mode 100644
index 8a55ab8fbf3..00000000000
--- a/src/mongo/util/net/message_port_startup_param.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Copyright (C) 2016 MongoDB Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * As a special exception, the copyright holders give permission to link the
- * code of portions of this program with the OpenSSL library under certain
- * conditions as described in each individual source file and distribute
- * linked combinations including the program with the OpenSSL library. You
- * must comply with the GNU Affero General Public License in all respects
- * for all of the code used other than as permitted herein. If you modify
- * file(s) with this exception, you may extend this exception to your
- * version of the file(s), but you are not obligated to do so. If you do not
- * wish to do so, delete this exception statement from your version. If you
- * delete this exception statement from all source files in the program,
- * then also delete it in the license file.
- */
-
-#pragma once
-
-namespace mongo {
-
-bool isMessagePortImplASIO();
-
-} // namespace mongo