4646#include " NdbSpin.h"
4747#include " InputStream.hpp"
4848#include " OutputStream.hpp"
49- #include " socket_io.h"
5049#include " portlib/NdbTCP.h"
5150
5251#include < mgmapi/mgmapi.h>
@@ -115,25 +114,32 @@ TransporterRegistry::get_bytes_received(NodeId node_id) const
115114
116115SocketServer::Session * TransporterService::newSession (ndb_socket_t sockfd)
117116{
117+ /* The connection is currently running over a plain network socket.
118+ If m_auth is a TlsAuthenticator, it might get upgraded to a TLS socket
119+ in server_authenticate().
120+ */
121+ NdbSocket secureSocket;
122+ secureSocket.init_from_new (sockfd);
123+
118124 DBUG_ENTER (" SocketServer::Session * TransporterService::newSession" );
119125 DEBUG_FPRINTF ((stderr, " New session created\n " ));
120- if (m_auth && !m_auth->server_authenticate (sockfd ))
126+ if (m_auth && !m_auth->server_authenticate (secureSocket ))
121127 {
122128 DEBUG_FPRINTF ((stderr, " Failed to authenticate new session\n " ));
123- ndb_socket_close_with_reset (sockfd, true ); // Close with reset
129+ secureSocket. close_with_reset ( true ); // Close with reset
124130 DBUG_RETURN (0 );
125131 }
126132
127133 BaseString msg;
128134 bool close_with_reset = true ;
129135 bool log_failure = false ;
130- if (!m_transporter_registry->connect_server (sockfd ,
136+ if (!m_transporter_registry->connect_server (secureSocket ,
131137 msg,
132138 close_with_reset,
133139 log_failure))
134140 {
135141 DEBUG_FPRINTF ((stderr, " New session failed in connect_server\n " ));
136- ndb_socket_close_with_reset (sockfd, close_with_reset);
142+ secureSocket. close_with_reset ( close_with_reset);
137143 if (log_failure)
138144 {
139145 g_eventLogger->warning (" TR : %s" , msg.c_str ());
@@ -469,7 +475,7 @@ TransporterRegistry::init(TransporterReceiveHandle& recvhandle)
469475}
470476
471477bool
472- TransporterRegistry::connect_server (ndb_socket_t sockfd ,
478+ TransporterRegistry::connect_server (NdbSocket & socket ,
473479 BaseString & msg,
474480 bool & close_with_reset,
475481 bool & log_failure)
@@ -480,7 +486,7 @@ TransporterRegistry::connect_server(ndb_socket_t sockfd,
480486
481487 // Read "hello" that consists of node id and other info
482488 // from client
483- SocketInputStream s_input (sockfd );
489+ SecureSocketInputStream s_input (socket );
484490 char buf[256 ]; // <int> <int> <int> <int> <..expansion..>
485491 if (s_input.gets (buf, sizeof (buf)) == nullptr ) {
486492 /* Could be spurious connection, need not log */
@@ -741,7 +747,7 @@ TransporterRegistry::connect_server(ndb_socket_t sockfd,
741747 */
742748
743749 // Avoid TIME_WAIT on server by requesting client to close connection
744- SocketOutputStream s_output (sockfd );
750+ SecureSocketOutputStream s_output (socket );
745751 if (s_output.println (" BYE" ) < 0 )
746752 {
747753 // Failed to request client close
@@ -751,8 +757,7 @@ TransporterRegistry::connect_server(ndb_socket_t sockfd,
751757
752758 // Wait for to close connection by reading EOF(i.e read returns 0)
753759 const int read_eof_timeout = 1000 ; // Fairly short timeout
754- if (read_socket (sockfd, read_eof_timeout,
755- buf, sizeof (buf)) == 0 )
760+ if (socket.read (read_eof_timeout, buf, sizeof (buf)) == 0 )
756761 {
757762 // Client gracefully closed connection, turn off close_with_reset
758763 close_with_reset = false ;
@@ -764,7 +769,7 @@ TransporterRegistry::connect_server(ndb_socket_t sockfd,
764769 }
765770
766771 // Send reply to client
767- SocketOutputStream s_output (sockfd );
772+ SecureSocketOutputStream s_output (socket );
768773 if (s_output.println (" %d %d" , t->getLocalNodeId (), t->m_type ) < 0 )
769774 {
770775 /* Strange, log it */
@@ -778,7 +783,7 @@ TransporterRegistry::connect_server(ndb_socket_t sockfd,
778783 // Setup transporter (transporter responsible for closing sockfd)
779784 DEBUG_FPRINTF ((stderr, " connect_server for trp_id %u\n " ,
780785 t->getTransporterIndex ()));
781- DBUG_RETURN (t->connect_server (sockfd , msg));
786+ DBUG_RETURN (t->connect_server (socket. ndb_socket () , msg)); // WL#15130 fix me soon
782787}
783788
784789void
0 commit comments