46
46
#include " NdbSpin.h"
47
47
#include " InputStream.hpp"
48
48
#include " OutputStream.hpp"
49
- #include " socket_io.h"
50
49
#include " portlib/NdbTCP.h"
51
50
52
51
#include < mgmapi/mgmapi.h>
@@ -115,25 +114,32 @@ TransporterRegistry::get_bytes_received(NodeId node_id) const
115
114
116
115
SocketServer::Session * TransporterService::newSession (ndb_socket_t sockfd)
117
116
{
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
+
118
124
DBUG_ENTER (" SocketServer::Session * TransporterService::newSession" );
119
125
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 ))
121
127
{
122
128
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
124
130
DBUG_RETURN (0 );
125
131
}
126
132
127
133
BaseString msg;
128
134
bool close_with_reset = true ;
129
135
bool log_failure = false ;
130
- if (!m_transporter_registry->connect_server (sockfd ,
136
+ if (!m_transporter_registry->connect_server (secureSocket ,
131
137
msg,
132
138
close_with_reset,
133
139
log_failure))
134
140
{
135
141
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);
137
143
if (log_failure)
138
144
{
139
145
g_eventLogger->warning (" TR : %s" , msg.c_str ());
@@ -469,7 +475,7 @@ TransporterRegistry::init(TransporterReceiveHandle& recvhandle)
469
475
}
470
476
471
477
bool
472
- TransporterRegistry::connect_server (ndb_socket_t sockfd ,
478
+ TransporterRegistry::connect_server (NdbSocket & socket ,
473
479
BaseString & msg,
474
480
bool & close_with_reset,
475
481
bool & log_failure)
@@ -480,7 +486,7 @@ TransporterRegistry::connect_server(ndb_socket_t sockfd,
480
486
481
487
// Read "hello" that consists of node id and other info
482
488
// from client
483
- SocketInputStream s_input (sockfd );
489
+ SecureSocketInputStream s_input (socket );
484
490
char buf[256 ]; // <int> <int> <int> <int> <..expansion..>
485
491
if (s_input.gets (buf, sizeof (buf)) == nullptr ) {
486
492
/* Could be spurious connection, need not log */
@@ -741,7 +747,7 @@ TransporterRegistry::connect_server(ndb_socket_t sockfd,
741
747
*/
742
748
743
749
// Avoid TIME_WAIT on server by requesting client to close connection
744
- SocketOutputStream s_output (sockfd );
750
+ SecureSocketOutputStream s_output (socket );
745
751
if (s_output.println (" BYE" ) < 0 )
746
752
{
747
753
// Failed to request client close
@@ -751,8 +757,7 @@ TransporterRegistry::connect_server(ndb_socket_t sockfd,
751
757
752
758
// Wait for to close connection by reading EOF(i.e read returns 0)
753
759
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 )
756
761
{
757
762
// Client gracefully closed connection, turn off close_with_reset
758
763
close_with_reset = false ;
@@ -764,7 +769,7 @@ TransporterRegistry::connect_server(ndb_socket_t sockfd,
764
769
}
765
770
766
771
// Send reply to client
767
- SocketOutputStream s_output (sockfd );
772
+ SecureSocketOutputStream s_output (socket );
768
773
if (s_output.println (" %d %d" , t->getLocalNodeId (), t->m_type ) < 0 )
769
774
{
770
775
/* Strange, log it */
@@ -778,7 +783,7 @@ TransporterRegistry::connect_server(ndb_socket_t sockfd,
778
783
// Setup transporter (transporter responsible for closing sockfd)
779
784
DEBUG_FPRINTF ((stderr, " connect_server for trp_id %u\n " ,
780
785
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
782
787
}
783
788
784
789
void
0 commit comments