19 #include <TransporterRegistry.hpp>
20 #include <TransporterCallback.hpp>
21 #include "Transporter.hpp"
22 #include "TransporterInternalDefinitions.hpp"
24 #include <SocketAuthenticator.hpp>
25 #include <InputStream.hpp>
26 #include <OutputStream.hpp>
28 #include <EventLogger.hpp>
32 TransporterType _type,
33 const char *lHostName,
34 const char *rHostName,
36 bool _isMgmConnection,
41 bool _compression,
bool _checksum,
bool _signalId,
42 Uint32 max_send_buffer)
43 : m_s_port(s_port), remoteNodeId(rNodeId), localNodeId(lNodeId),
44 isServer(lNodeId==serverNodeId),
45 m_packer(_signalId, _checksum), m_max_send_buffer(max_send_buffer),
46 m_overload_limit(0xFFFFFFFF), isMgmConnection(_isMgmConnection),
49 m_transporter_registry(t_reg)
51 DBUG_ENTER(
"Transporter::Transporter");
52 if (rHostName && strlen(rHostName) > 0){
54 Ndb_getInAddr(&remoteHostAddress, rHostName);
59 ndbout <<
"Unable to setup transporter. Node " << rNodeId
60 <<
" must have hostname. Update configuration." << endl;
65 strncpy(localHostName, lHostName,
sizeof(localHostName));
67 DBUG_PRINT(
"info",(
"rId=%d lId=%d isServer=%d rHost=%s lHost=%s s_port=%d",
68 remoteNodeId, localNodeId, isServer,
72 byteOrder = _byteorder;
73 compressionUsed = _compression;
74 checksumUsed = _checksum;
75 signalIdUsed = _signalId;
77 m_timeOutMillis = 30000;
79 m_connect_address.s_addr= 0;
91 m_socket_client->set_connect_timeout(m_timeOutMillis);
95 #if defined (_SC_IOV_MAX) && defined (HAVE_SYSCONF)
96 long res = sysconf(_SC_IOV_MAX);
99 m_os_max_iovec = (Uint32)res;
107 delete m_socket_client;
114 if (configure_derived(conf) &&
115 conf->s_port == m_s_port &&
117 strcmp(conf->localHostName, localHostName) == 0 &&
118 conf->remoteNodeId == remoteNodeId &&
119 conf->localNodeId == localNodeId &&
120 (conf->serverNodeId == conf->localNodeId) == isServer &&
121 conf->checksum == checksumUsed &&
122 conf->signalId == signalIdUsed &&
123 conf->isMgmConnection == isMgmConnection &&
124 conf->type == m_type)
131 Transporter::connect_server(NDB_SOCKET_TYPE sockfd,
134 DBUG_ENTER(
"Transporter::connect_server");
138 msg.
assfmt(
"line: %u : already connected ??", __LINE__);
143 my_socket_connect_address(sockfd, &m_connect_address);
147 msg.
assfmt(
"line: %u : connect_server_impl failed", __LINE__);
159 NDB_SOCKET_TYPE sockfd;
160 DBUG_ENTER(
"Transporter::connect_client");
171 if (!m_socket_client->init())
174 if (pre_connect_options(m_socket_client->m_sockfd) != 0)
177 if (strlen(localHostName) > 0)
179 if (m_socket_client->bind(localHostName, 0) != 0)
182 sockfd= m_socket_client->connect();
192 DBUG_ENTER(
"Transporter::connect_client(sockfd)");
196 DBUG_PRINT(
"error", (
"Already connected"));
200 if (!my_socket_valid(sockfd))
202 DBUG_PRINT(
"error", (
"Socket " MY_SOCKET_FORMAT
" is not valid",
203 MY_SOCKET_FORMAT_VALUE(sockfd)));
207 DBUG_PRINT(
"info",(
"server port: %d, isMgmConnection: %d",
208 m_s_port, isMgmConnection));
211 DBUG_PRINT(
"info", (
"Sending own nodeid: %d and transporter type: %d",
212 localNodeId, m_type));
214 if (s_output.println(
"%d %d", localNodeId, m_type) < 0)
216 DBUG_PRINT(
"error", (
"Send of 'hello' failed"));
217 NDB_CLOSE_SOCKET(sockfd);
222 DBUG_PRINT(
"info", (
"Reading reply"));
225 if (s_input.gets(buf, 256) == 0)
227 DBUG_PRINT(
"error", (
"Failed to read reply"));
228 NDB_CLOSE_SOCKET(sockfd);
233 int nodeId, remote_transporter_type= -1;
234 int r= sscanf(buf,
"%d %d", &nodeId, &remote_transporter_type);
243 DBUG_PRINT(
"error", (
"Failed to parse reply"));
244 NDB_CLOSE_SOCKET(sockfd);
248 DBUG_PRINT(
"info", (
"nodeId=%d remote_transporter_type=%d",
249 nodeId, remote_transporter_type));
252 if (nodeId != remoteNodeId)
254 g_eventLogger->
error(
"Connected to wrong nodeid: %d, expected: %d",
255 nodeId, remoteNodeId);
256 NDB_CLOSE_SOCKET(sockfd);
261 if (remote_transporter_type != -1 &&
262 remote_transporter_type != m_type)
264 g_eventLogger->
error(
"Connection to node: %d uses different transporter "
265 "type: %d, expected type: %d",
266 nodeId, remote_transporter_type, m_type);
267 NDB_CLOSE_SOCKET(sockfd);
272 my_socket_connect_address(sockfd, &m_connect_address);
274 if (!connect_client_impl(sockfd))