diff --git a/Jamulus.pro b/Jamulus.pro index 421a7c6218..b38017ac96 100644 --- a/Jamulus.pro +++ b/Jamulus.pro @@ -399,6 +399,8 @@ HEADERS += src/plugins/audioreverb.h \ src/serverlogging.h \ src/settings.h \ src/socket.h \ + src/tcpserver.h \ + src/tcpconnection.h \ src/util.h \ src/recorder/jamrecorder.h \ src/recorder/creaperproject.h \ @@ -507,6 +509,8 @@ SOURCES += src/plugins/audioreverb.cpp \ src/settings.cpp \ src/signalhandler.cpp \ src/socket.cpp \ + src/tcpserver.cpp \ + src/tcpconnection.cpp \ src/util.cpp \ src/recorder/jamrecorder.cpp \ src/recorder/creaperproject.cpp \ diff --git a/docs/TCP.md b/docs/TCP.md new file mode 100644 index 0000000000..ef79e50e44 --- /dev/null +++ b/docs/TCP.md @@ -0,0 +1,215 @@ +# TCP FALLBACK FOR THE JAMULUS PROTOCOL + +## THE PROBLEM BEING SOLVED + +All Jamulus protocol (non-audio) messages are currently delivered over the same UDP channel as the audio. For most protocol messages, this is fine, but those that send a list of servers from a directory, or a list of clients from a server, can generate a UDP datagram that is too large to fit into a single physical packet. Physical packets are constrained by the MTU of the Ethernet interface (normally 1500 bytes or less), and further by any limitations in links between hops on the internet. Neither the client nor the server has any control over these limitation. It's also possible a large welcome message could require fragmentation. + +The UDP protocol itself allows datagrams up to be up to nearly 65535 bytes in size, minus any protocol overhead. IPv4 will allow nearly all of this size to be used, in theory. If the IPv4 datagram being sent by a node (host or router) is too large to fit into a single packet on the outgoing interface, the IP protocol will fragment the packet into pieces that do fit, with IP headers that contain the information needed to order and reassemble the fragments into a single datagram at the receiving end. Normally intermediate hops do not perform any reassembly, but will further fragment an IP packet if it will not fit the MTU of the outgoing interface. + +The receiving end's IP stack needs to store all the received fragments as they arrive and can only reassemble them into the original datagram once all fragments have been received. The loss of even one fragment renders the whole datagram lost, and the remaining received fragments consume resources until they time out and are discarded. There are also possibilities for a denial of service attack if an attacker deliberately sends lots of fragments with one or more missing. + +If a directory has more than around 35 servers registered (depending on the length of the name, city, etc.), the list of servers sent to a client when requested is certain to be fragmented. Similarly, if a powerful server has a lot of clients connected, e.g. a big band or large choir, the list of clients sent to each connected client could be large enough to get fragmented. In either of these cases, a client that is unable to receive fragmented IP packets will show an empty list or an empty mixer panel. + +There are several reasons that fragmented IP datagrams can fail to make it from server to client: + +* The configuration of a user's router, either accidentally or deliberately. Sometimes a user can be helped by a knowledgeable friend to check and fix this, but often not. +* The configuration of an intermediate router along the path from server to client. This is fairly rare, but could be a carrier's deliberate choice to avoid the kind of DoS attack mentioned above. For whatever reason, it is outside the control of the user or server operator. +* The IPv6 protocol deliberately has no provision for fragmentation of datagrams at the IP layer of intermediate hops. So this is a complete show-stopper for the use of IPv6 in directories, as there is therefore no support at all for large UDP messages. + +The IPv6 limitation means that resolving this issue is a prerequisite to implementing IPv6 support in directories. + +## CONNECTIONLESS MODE - CLIENT CONNECT DIALOG + +The basic summary is that TCP need only be used as a fallback when it is determined that a UDP message from a directory or server failed to reach the client, probably due to fragmentation, _and_ that the directory or server explicitly supports TCP. + +### Current operation when client opens Connect dialog + +1. Client sends `CLM_REQ_SERVER_LIST` to the selected directory server to ask for a list of registered servers. It then starts a 2.5 sec re-request timer. + +2. Directory server fetches its internal list of registered servers, and sends a `CLM_SEND_EMPTY_MESSAGE` to each listed server, with the IP and UDP port of the requesting client as parameters. + +3. Directory server sends `CLM_RED_SERVER_LIST` (reduced server list) to client. + + a. If/when client receives `CLM_RED_SERVER_LIST`, it populates its list of servers with the reduced info, and sets an internal flag to say it has done so. It checks this flag to avoid processing a repeat reduced server list. + + b. If the list is large and fragmented, and the path does not correctly pass fragments, the client will not receive the list. + +4. Directory server sends `CLM_SERVER_LIST` to client. It does this immediately after sending the reduced list above. + + a. If/when the client receives `CLM_SERVER_LIST`, it populates its list of servers with the full info, replacing any existing list that contained reduced info. It then stops the 2.5 sec re-request timer mentioned above, so that the server list is not requested again. + + b. If the list is large and fragmented, and the path does not correctly pass fragments, the client will not receive the list, and the request timer will be left running to retry. + +5. While client is displaying the server list, it periodically pings each server with `CLM_PING_MS_WITHNUMCLIENTS` including a timestamp in the message. + +6. Each pinged server, when it receives the ping, will create a `CLM_PING_MS_WITHNUMCLIENTS` in reply, containing a copy of the received timestamp, and the number of clients currently connected to that server. + +7. When the client receives the reply, it can calculate the round-trip time from the received timestamp and the current time. + +8. If the number of connected clients returned is different from the previously received number for that server, the client sends a `CLM_REQ_CONN_CLIENTS_LIST` to the server. + + a. The server responds with a list of clients in a `CLM_CONN_CLIENTS_LIST`. Most servers only have a small number of clients connected, and this message is not large enough to need IP fragmentation. + + b. If the server is a large one with many clients connected (e.g. for a choir, big band or WorldJam green room), the client list may be large enough to be fragmented by the IP layer. In that case, it might not be received by the requesting client, although in most cases it will. + +9. If/when the client receives the client list from the server, it can display the list of connected clients under the relevant server, if this is enabled in the GUI. + +10. The five steps above (5-9) continue until the user clicks Connect or closes the dialog. + +### Enhancement for TCP support + +1. A server (which may also be a directory) can be configured with the command-line option `--enabletcp` to enable TCP operation. + +2. If the directory server has TCP enabled, then *after* it has sent the `CLM_RED_SERVER_LIST` and `CLM_SERVER_LIST` by UDP, it will send a new message `CLM_TCP_SUPPORTED` to the client, with a data field of `CLM_SERVER_LIST`. This data field enables the client to know which request may need to be retried over TCP. + + a. An older version of client that does not support TCP will ignore this message and continue operating in the normal way just on UDP. + + b. A newer client that supports TCP should receive and process the `CLM_TCP_SUPPORTED` message *after* it has received and processed the UDP server list, unless fragmentation (or another cause) prevented the list from arriving. + + c. If such a client has already processed a full server list from `CLM_SERVER_LIST`, it will have no need to open a TCP connection to the directory, so this will be skipped. + + d. If the client receives `CLM_TCP_SUPPORTED` having *not* received and processed a `CLM_SERVER_LIST`, it will open a TCP connection to the directory server, and request the server list again over the TCP connection. + +3. If the directory server accepts a TCP connection and receives a `CLM_REQ_SERVER_LIST` over it, it will process the request in the same way as for a UDP request, with the following differences: + + a. There is no need for the directory to send `CLM_SEND_EMPTY_MESSAGE` to the servers in the list, since that was already done in response to the original UDP request. + + b. There is no need for the directory to send `CLM_RED_SERVER_LIST` to the client, since the TCP connection is reliable, so the directory server just sends the `CLM_SERVER_LIST` over the TCP connection. + +4. When the client has received the `CLM_SERVER_LIST` over TCP, it closes the TCP connection, populates its list of servers in the connect dialog in the normal way and stops the 2.5 sec re-request timer. + +5. The client starts pinging each listed server as normal, using UDP, and the server responds with a ping including the timestamp and number of clients, as described above. + +6. As above, if the number of connected clients has changed, the client sends a `CLM_REQ_CONN_CLIENTS_LIST` over UDP in the normal way. + +7. If a server in the list supports TCP, when it has sent a reply to the client list request with `CLM_CONN_CLIENTS_LIST`, it will follow it immediately with a `CLM_TCP_SUPPORTED`, with a data field of `CLM_CONN_CLIENTS_LIST`. + + a. An older version of client that does not support TCP will ignore the `CLM_TCP_SUPPORTED` message and continue operating in the normal way just on UDP. + + b. A newer client that supports TCP should received the `CLM_TCP_SUPPORTED` message *after* it has received and processed the UDP client list, unless fragmentation (or another cause) prevented the list from arriving. + + c. If such a client has already processed a client list from `CLM_CONN_CLIENTS_LIST`, it will have no need to open a TCP connection to the server, so this will be skipped. + + d. If the client receives `CLM_TCP_SUPPORTED` having *not* received and processed a `CLM_CONN_CLIENTS_LIST`, it will open a TCP connection to the server, and request the client list again over the TCP connection. + +8. If the server accepts a TCP connection and receives a `CLM_REQ_CONN_CLIENTS_LIST` over it, it will process the request in the same way as for a UDP request, but will send the reply over the TCP connection. + +9. When the client has received the `CLM_CONN_CLIENTS_LIST` over TCP, it closes the TCP connection and updates the list of clients for that server in the GUI. However, it will note for that server that TCP is needed, and if/when the number of connected clients next changes while the connect dialog is still open, it will immediately request the updated list via TCP instead of UDP. + + +### Summary + +By sending the `CLM_TCP_SUPPORTED` message immediately *after* sending a potentially large list of servers or connected clients, it allows a client easily to determine whether or not it needs to fall back to TCP without the necessity of timeouts or other delays. It will only need to use TCP if it has not already succeeded in receiving the message over UDP. + +## CONNECTED MODE + +### Existing operation when client clicks on Connect + +All these steps use UDP only. + +1. Client starts sending an audio stream to the server. This audio stream continues in parallel with the protocol exchange below. + + a. Server does not yet start sending an audio stream to the client. + +2. Server sees the audio stream and looks up the source IP:port in its channel table, finding no channel that matches. + +3. Server allocates a new channel in the channels array and stores the source IP:port in it. The channel index becomes the Channel ID of the connected client. + +4. Server sends a `CLIENT_ID` message to the client, containing the Channel ID mentioned above. + + a. Client replies with `ACKN (CLIENT_ID)`. *Note that all messages that do not begin `CLM_` need to be acked by the receiving side. For clarity, these `ACKN` messages will not be mentioned below.* + +5. Server sends `CONN_CLIENTS_LIST` to the client, containing a list of all current clients in the session. + +6. Server sends `REQ_SPLIT_MESS_SUPPORT` to ask the client if it supports split messages. + +7. Client sends back `SPLIT_MESS_SUPPORTED` immediately. + +7. Server sends `REQ_NETW_TRANSPORT_PROPS` to ask for the clients network transport parameters. + +8. Client sends `NETW_TRANSPORT_PROPS` containing the codec, packet size, number of channels, bitrate, etc. + +9. Server sends `REQ_JITT_BUF_SIZE` to ask for the client's required jitter buffer sizes. + +10. Client sends `JIT_BUF_SIZE`, containing the positions of the "server" jitter buffer slider in the Settings dialog. This is telling the server what size jitter buffer to use for receiving audio data from the client. (The position of the "client" jitter buffer slider is not needed by the server, as it is only used locally in the client). + +11. Server sends `REQ_CHANNEL_INFOS` to ask for the identity information for the channel. + +12. Client sends `CHANNEL_INFOS` containing the identity information from the user's profile settings in the client (country, instrument, skill level, name, city). + +13. Now that the server has received the `CHANNEL_INFOS` from the client, it starts to send the mixed audio stream to the client. + +14. Server sends `CHAT_TEXT` containing the server welcome message, if any. If there is none, this message is skipped. + +15. Server sends `VERSION_AND_OS` to tell the client the version of Jamulus on the server and the server platform. + +After this, messages are sent by either side when there is something to notify: + +* From server to client: + + - `CLM_CHANNEL_LEVEL_LIST` - list of audio levels for each channel. Sent every 250ms by a timer. + - `RECORDER_STATE` - current state of the server-based recording. Sent when the state changes? + - `JITT_BUF_SIZE` - the size of the receiving jitter buffer for this connection on the server. Sent in Auto mode when the value changes. + - `CLM_PING_MS` - sent in response to a `CLM_PING_MS` received from the client. For client-side ping time calculation. + - `CONN_CLIENTS_LIST` - list of connected clients. Sent when the list changes due to a client connecting or leaving. This message could be large on a server with many clients. + +* From client to server: + + - `CLM_PING_MS` - contains a timestamp and requests the server to send back the same timestamp, so that the round-trip time can be measured. Sent every 500ms by a timer. + - `NETW_TRANSPORT_PROPS` - specifies codec, packet size, bitrate, etc. Sent when the user changes Audio Channels, Audio Quality, Buffer Delay or Small Network Buffers. + - `CHANNEL_GAIN` - specifies the user's requested gain for a specific channel. Sent when the user moves a fader, but rate limited to avoid many changes in succession being sent. + - `JITT_BUF_SIZE` - specifies the requested size of the server's jitter buffer, or Auto. + - `CLM_DISCONNECTION` - sent when the user clicks on Disconnect, or connects to another server. + + +### TCP usage in Connected Mode + +The connected-mode protocol messages sent over UDP are all sequence numbered and acknowledged, in order to be robust against potential packet loss. Over TCP, such packet loss will not occur, as sequencing and acknowledgement all happen at the TCP network layer. + +Consequently, TCP will not be used for connected-mode protocol messages. + +The reason for using a TCP connection in an active session is just to provide a reliable path for delivering a list of connected clients that could be large and subject to fragmentation (if it is sent over UDP). So the established TCP connection is only used to deliver client lists, and not other protocol messages. + +Therefore, if the server has an active TCP connection from the client, it will use the connectionless `CLM_CONN_CLIENTS_LIST` message to deliver updates for the connected client list. If there is no active TCP connection, updates will be delivered using the connected-mode `CONN_CLIENTS_LIST` over UDP as at present. + +So the sequence is as follows: + +1. As soon as a TCP-enabled server sees audio from a new client and creates a channel for it, it will send `CLM_TCP_SUPPORTED` to the client, with a data field of `CLM_CLIENT_ID`. + +2. The server will then send the connected-mode `CLIENT_ID` message as normal, containing the channel ID that has been allocated. + +3. An older version of client that does not support TCP will ignore the `CLM_TCP_SUPPORTED` message and continue operating in the normal way just on UDP. + +4. A newer client that supports TCP will receive the `CLM_TCP_SUPPORTED` message, and will note that the server supports TCP. The client will open a long-lived TCP connection to the server (on the same port number as UDP). + +5. The server will accept the TCP connection, and will wait for the first message to arrive via that connection. + +6. When a newer client receives the `CLIENT_ID` message from a server it knows supports TCP, the client will send, as its first message over the connection, a `CLM_CLIENT_ID` message containing the channel ID that it received over UDP. (`CLM_CLIENT_ID` is a newly-defined connectionless message). + +7. The server will lookup the channel specified by the `CLM_CLIENT_ID` message, and *will check that the IP address of the channel matches the remote address of the TCP connection*. If it does not, it will close the connection. This prevents hijacking of a session by sending another client's ID. + +8. If the TCP connection matches the client channel, the socket descriptor will be stored in the channel, and the channel pointer will be stored in the TCP Connection instance. + +9. Any messages from the client that arrive over TCP will be handled in the same way as messages received over UDP. Responses will be send back over TCP too. At present, there are no such messages defined. Existing protocol messages will continue to use UDP. + +10. Updates to the Connected Clients List generated by the server will be sent over TCP as `CLM_CONN_CLIENTS_LIST`, if there is an active socket descriptor stored for the channel. If not, they will be sent over UDP as `CONN_CLIENTS_LIST` in the normal way. + +11. In order to keep the long-term TCP connection alive via firewalls, NAT routers, etc., the client will start a periodic timer (e.g. 15 sec) to send a `CLM_EMPTY_MESSAGE` over the TCP connection. This causes no action at the server, but keeps the TCP connection alive. + +12. The server will start an idle timeout, resetting it each time a message is received. If the idle timer times out, the server will close the TCP connection. + +13. Audio packets will continue to always use the UDP socket. + +14. To disconnect, a client will send `CLM_DISCONNECT` over UDP exactly as at present, and will also close the TCP connection. + +If the server receives a disconnection of the TCP socket, it will revert to UDP for connected client updates. It could send another `CLM_TCP_SUPPORTED` to invite the client to re-establish a TCP connection. + +## OTHER CONSIDERATIONS + +The server should only be configured to offer TCP by specifying `--enabletcp` if the server operator has also configured any firewall to allow the inbound TCP connections. + +If a server were to offer TCP to the client, but the server's firewall didn't allow the incoming TCP connection, the client request for TCP would wait until its request times out. + +This has to be the responsibility of the server/directory operator, and is why TCP operation must be controlled by a command-line option, rather than always enabled. The operator should only enable TCP in the Jamulus server if they know their environment has been configured to support it. + +Most operators of small servers of directories will not need to be concerned with TCP at all. _The only server operators who will need to enable TCP support are those running large directories (e.g. Volker, Peter) or those running a large server designed to support many simultaneous client connections._ diff --git a/src/channel.cpp b/src/channel.cpp index 7755b7ec92..7c50bf2c2a 100644 --- a/src/channel.cpp +++ b/src/channel.cpp @@ -48,6 +48,7 @@ // CChannel implementation ***************************************************** CChannel::CChannel ( const bool bNIsServer ) : + pTcpConnection ( nullptr ), vecfGains ( MAX_NUM_CHANNELS, 1.0f ), vecfPannings ( MAX_NUM_CHANNELS, 0.5f ), iCurSockBufNumFrames ( INVALID_INDEX ), @@ -103,7 +104,7 @@ CChannel::CChannel ( const bool bNIsServer ) : QObject::connect ( &Protocol, &CProtocol::ChangeChanPan, this, &CChannel::OnChangeChanPan ); - QObject::connect ( &Protocol, &CProtocol::ClientIDReceived, this, &CChannel::ClientIDReceived ); + QObject::connect ( &Protocol, &CProtocol::ClientIDReceived, this, &CChannel::OnClientIDReceived ); QObject::connect ( &Protocol, &CProtocol::RawAudioSupported, this, &CChannel::RawAudioSupported ); @@ -736,3 +737,25 @@ void CChannel::UpdateSocketBufferSize() SetSockBufNumFrames ( SockBuf.GetAutoSetting(), true ); } } + +void CChannel::OnClientIDReceived ( int iChanID ) +{ + qDebug() << Q_FUNC_INFO << "iChanID =" << iChanID; + emit ClientIDReceived ( iChanID ); +} + +void CChannel::CreateConClientListMes ( const CVector& vecChanInfo, CProtocol& ConnLessProtocol ) +{ + if ( pTcpConnection ) + { + qDebug() << "- sending client list via TCP"; + + ConnLessProtocol.CreateCLConnClientsListMes ( InetAddr, vecChanInfo, pTcpConnection ); + } + else + { + qDebug() << "- sending client list via UDP"; + + Protocol.CreateConClientListMes ( vecChanInfo ); + } +} diff --git a/src/channel.h b/src/channel.h index eea8b0c8e2..9b71d0e6ba 100644 --- a/src/channel.h +++ b/src/channel.h @@ -108,6 +108,9 @@ class CChannel : public QObject void SetAddress ( const CHostAddress& NAddr ) { InetAddr = NAddr; } const CHostAddress& GetAddress() const { return InetAddr; } + void SetTcpConnection ( CTcpConnection* pConnection ) { pTcpConnection = pConnection; } + CTcpConnection* GetTcpConnection() { return pTcpConnection; } + void ResetInfo() { bIsIdentified = false; @@ -184,7 +187,7 @@ class CChannel : public QObject void CreateReqChannelLevelListMes() { Protocol.CreateReqChannelLevelListMes(); } //### TODO: END ###// - void CreateConClientListMes ( const CVector& vecChanInfo ) { Protocol.CreateConClientListMes ( vecChanInfo ); } + void CreateConClientListMes ( const CVector& vecChanInfo, CProtocol& ConnLessProtocol ); void CreateRecorderStateMes ( const ERecorderState eRecorderState ) { Protocol.CreateRecorderStateMes ( eRecorderState ); } @@ -209,7 +212,8 @@ class CChannel : public QObject } // connection parameters - CHostAddress InetAddr; + CHostAddress InetAddr; + CTcpConnection* pTcpConnection; // channel info CChannelCoreInfo ChannelInfo; @@ -278,11 +282,12 @@ public slots: PutProtocolData ( iRecCounter, iRecID, vecbyMesBodyData, RecHostAddr ); } - void OnProtocolCLMessageReceived ( int iRecID, CVector vecbyMesBodyData, CHostAddress RecHostAddr ) + void OnProtocolCLMessageReceived ( int iRecID, CVector vecbyMesBodyData, CHostAddress RecHostAddr, CTcpConnection* pTcpConnection ) { - emit DetectedCLMessage ( vecbyMesBodyData, iRecID, RecHostAddr ); + emit DetectedCLMessage ( vecbyMesBodyData, iRecID, RecHostAddr, pTcpConnection ); } + void OnClientIDReceived ( int iChanID ); void OnNewConnection() { emit NewConnection(); } signals: @@ -306,7 +311,7 @@ public slots: void RecorderStateReceived ( ERecorderState eRecorderState ); void Disconnected(); - void DetectedCLMessage ( CVector vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr ); + void DetectedCLMessage ( CVector vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr, CTcpConnection* pTcpConnection ); void ParseMessageBody ( CVector vecbyMesBodyData, int iRecCounter, int iRecID ); }; diff --git a/src/client.cpp b/src/client.cpp index b1638ab272..8b97572e2a 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -170,7 +170,9 @@ CClient::CClient ( const quint16 iPortNumber, QObject::connect ( &ConnLessProtocol, &CProtocol::CLRedServerListReceived, this, &CClient::CLRedServerListReceived ); - QObject::connect ( &ConnLessProtocol, &CProtocol::CLConnClientsListMesReceived, this, &CClient::CLConnClientsListMesReceived ); + QObject::connect ( &ConnLessProtocol, &CProtocol::CLTcpSupported, this, &CClient::OnCLTcpSupported ); + + QObject::connect ( &ConnLessProtocol, &CProtocol::CLConnClientsListMesReceived, this, &CClient::OnCLConnClientsListMesReceived ); QObject::connect ( &ConnLessProtocol, &CProtocol::CLPingReceived, this, &CClient::OnCLPingReceived ); @@ -274,11 +276,81 @@ void CClient::OnSendProtMessage ( CVector vecMessage ) Socket.SendPacket ( vecMessage, Channel.GetAddress() ); } -void CClient::OnSendCLProtMessage ( CHostAddress InetAddr, CVector vecMessage ) +void CClient::OnSendCLProtMessage ( CHostAddress InetAddr, CVector vecMessage, CTcpConnection* pTcpConnection, enum EProtoMode eProtoMode ) { + if ( pTcpConnection ) + { + // already have TCP connection - just send and return + pTcpConnection->write ( (const char*) &( (CVector) vecMessage )[0], vecMessage.Size() ); + return; + } + // the protocol queries me to call the function to send the message // send it through the network - Socket.SendPacket ( vecMessage, InetAddr ); + if ( eProtoMode != PROTO_UDP ) + { + // create a TCP client connection and send message + QTcpSocket* pSocket = new QTcpSocket ( this ); + + // timer for TCP connect timeout because Qt defaults to 30 seconds + // and we want it to be 3 seconds (TCP_CONNECT_TIMEOUT_MS) + QTimer* pTimer = new QTimer ( this ); + pTimer->setSingleShot ( true ); + + connect ( pTimer, &QTimer::timeout, this, [this, pSocket, pTimer, InetAddr]() { + if ( pSocket->state() != QAbstractSocket::ConnectedState ) + { + pSocket->abort(); + pSocket->deleteLater(); + qWarning() << "- Jamulus-TCP: timeout connecting to" << InetAddr.toString(); + } + pTimer->deleteLater(); + } ); + +#if QT_VERSION >= QT_VERSION_CHECK( 5, 15, 0 ) +# define ERRORSIGNAL &QTcpSocket::errorOccurred +#else +# define ERRORSIGNAL QOverload::of ( &QAbstractSocket::error ) +#endif + connect ( pSocket, ERRORSIGNAL, this, [this, pSocket, pTimer] ( QAbstractSocket::SocketError err ) { + Q_UNUSED ( err ); + + pTimer->stop(); + pTimer->deleteLater(); + + qWarning() << "- TCP connection error:" << pSocket->errorString(); + // may want to specifically handle ConnectionRefusedError? + pSocket->deleteLater(); + } ); + + connect ( pSocket, &QTcpSocket::connected, this, [this, pSocket, pTimer, InetAddr, vecMessage, eProtoMode]() { + pTimer->stop(); + pTimer->deleteLater(); + + // connection succeeded, give it to a CTcpConnection + CTcpConnection* pTcpConnection = new CTcpConnection ( pSocket, + InetAddr, + this, + &Channel, + eProtoMode == PROTO_TCP_LONG ); // client connection, will self-delete on disconnect + + if ( eProtoMode == PROTO_TCP_LONG ) + { + Channel.SetTcpConnection ( pTcpConnection ); // link session connection with channel + } + + pTcpConnection->write ( (const char*) &( (CVector) vecMessage )[0], vecMessage.Size() ); + + // the CTcpConnection object will pass the reply back up to CClient::Channel + } ); + + pSocket->connectToHost ( InetAddr.InetAddr, InetAddr.iPort ); + pTimer->start ( TCP_CONNECT_TIMEOUT_MS ); + } + else + { + Socket.SendPacket ( vecMessage, InetAddr ); + } } void CClient::OnInvalidPacketReceived ( CHostAddress RecHostAddr ) @@ -293,10 +365,10 @@ void CClient::OnInvalidPacketReceived ( CHostAddress RecHostAddr ) } } -void CClient::OnDetectedCLMessage ( CVector vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr ) +void CClient::OnDetectedCLMessage ( CVector vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr, CTcpConnection* pTcpConnection ) { // connection less messages are always processed - ConnLessProtocol.ParseConnectionLessMessageBody ( vecbyMesBodyData, iRecID, RecHostAddr ); + ConnLessProtocol.ParseConnectionLessMessageBody ( vecbyMesBodyData, iRecID, RecHostAddr, pTcpConnection ); } void CClient::OnJittBufSizeChanged ( int iNewJitBufSize ) @@ -1000,6 +1072,16 @@ void CClient::OnClientIDReceived ( int iServerChanID ) ClearClientChannels(); } + // if TCP Supported has already been received, make TCP connection to server + iClientID = iServerChanID; // for sending back to server over TCP + + if ( bTcpSupported ) + { + // *** Make TCP connection + qDebug() << Q_FUNC_INFO << "need to make TCP connection for" << iClientID; + ConnLessProtocol.CreateCLClientIDMes ( Channel.GetAddress(), iClientID, PROTO_TCP_LONG ); // create persistent TCP connection + } + // allocate and map client-side channel 0 int iChanID = FindClientChannel ( iServerChanID, true ); // should always return channel 0 @@ -1035,11 +1117,52 @@ void CClient::OnRawAudioSupported() } } +void CClient::OnCLTcpSupported ( CHostAddress InetAddr, int iID ) +{ + qDebug() << "- TCP supported at server" << InetAddr.toString() << "for ID =" << iID; + + if ( iID != PROTMESSID_CLM_CLIENT_ID ) + { + emit CLTcpSupported ( InetAddr, iID ); // pass to connect dialog + return; + } + + // if client ID already received, make TCP connection to server + bTcpSupported = true; + + if ( iClientID != INVALID_INDEX ) + { + // *** Make TCP connection + qDebug() << Q_FUNC_INFO << "need to make TCP connection for" << iClientID; + Q_ASSERT ( InetAddr == Channel.GetAddress() ); + ConnLessProtocol.CreateCLClientIDMes ( InetAddr, iClientID, PROTO_TCP_LONG ); // create persistent TCP connection + } +} + +void CClient::OnCLConnClientsListMesReceived ( CHostAddress InetAddr, CVector vecChanInfo, CTcpConnection* pTcpConnection ) +{ + // test if we are receiving for the connect dialog or a connected session + if ( pTcpConnection && pTcpConnection->IsSession() ) + { + qDebug() << "- sending client list to client dialog"; + OnConClientListMesReceived ( vecChanInfo ); // connected session + } + else + { + qDebug() << "- sending client list to connect dialog"; + emit CLConnClientsListMesReceived ( InetAddr, vecChanInfo ); // connect dialog + } +} + void CClient::Start() { // init object Init(); + // clear TCP info + iClientID = INVALID_INDEX; + bTcpSupported = false; + // initialise client channels ClearClientChannels(); @@ -1060,6 +1183,14 @@ void CClient::Stop() // stop audio interface Sound.Stop(); + // close any session TCP connection + CTcpConnection* pTcpConnection = Channel.GetTcpConnection(); + if ( pTcpConnection ) + { + Channel.SetTcpConnection ( nullptr ); + pTcpConnection->disconnectFromHost(); + } + // disable channel Channel.SetEnable ( false ); diff --git a/src/client.h b/src/client.h index 27c78cdf3d..f1b60c119d 100644 --- a/src/client.h +++ b/src/client.h @@ -303,9 +303,15 @@ class CClient : public QObject void CreateCLServerListReqVerAndOSMes ( const CHostAddress& InetAddr ) { ConnLessProtocol.CreateCLReqVersionAndOSMes ( InetAddr ); } - void CreateCLServerListReqConnClientsListMes ( const CHostAddress& InetAddr ) { ConnLessProtocol.CreateCLReqConnClientsListMes ( InetAddr ); } + void CreateCLServerListReqConnClientsListMes ( const CHostAddress& InetAddr, enum EProtoMode eProtoMode ) + { + ConnLessProtocol.CreateCLReqConnClientsListMes ( InetAddr, eProtoMode ); + } - void CreateCLReqServerListMes ( const CHostAddress& InetAddr ) { ConnLessProtocol.CreateCLReqServerListMes ( InetAddr ); } + void CreateCLReqServerListMes ( const CHostAddress& InetAddr, enum EProtoMode eProtoMode ) + { + ConnLessProtocol.CreateCLReqServerListMes ( InetAddr, eProtoMode ); + } int EstimatedOverallDelay ( const int iPingTimeMs ); @@ -449,12 +455,16 @@ class CClient : public QObject int maxGainOrPanId; int iCurPingTime; + // for TCP protocol support + bool bTcpSupported; + int iClientID; + protected slots: void OnHandledSignal ( int sigNum ); void OnSendProtMessage ( CVector vecMessage ); void OnInvalidPacketReceived ( CHostAddress RecHostAddr ); - void OnDetectedCLMessage ( CVector vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr ); + void OnDetectedCLMessage ( CVector vecbyMesBodyData, int iRecID, CHostAddress RecHostAddr, CTcpConnection* pTcpConnection ); void OnReqJittBufSize() { CreateServerJitterBufferMessage(); } void OnJittBufSizeChanged ( int iNewJitBufSize ); @@ -468,8 +478,9 @@ protected slots: } } void OnCLPingReceived ( CHostAddress InetAddr, int iMs ); + void OnCLTcpSupported ( CHostAddress InetAddr, int iID ); - void OnSendCLProtMessage ( CHostAddress InetAddr, CVector vecMessage ); + void OnSendCLProtMessage ( CHostAddress InetAddr, CVector vecMessage, CTcpConnection* pTcpConnection, enum EProtoMode eProtoMode ); void OnCLPingWithNumClientsReceived ( CHostAddress InetAddr, int iMs, int iNumClients ); @@ -484,6 +495,13 @@ protected slots: void OnMuteStateHasChangedReceived ( int iServerChanID, bool bIsMuted ); void OnCLChannelLevelListReceived ( CHostAddress InetAddr, CVector vecLevelList ); void OnConClientListMesReceived ( CVector vecChanInfo ); + void OnCLConnClientsListMesReceived ( CHostAddress InetAddr, CVector vecChanInfo, CTcpConnection* pTcpConnection ); + +public slots: + void OnCLSendEmptyMes ( CHostAddress InetAddr, CTcpConnection* pTcpConnection ) + { + ConnLessProtocol.CreateCLEmptyMes ( InetAddr, pTcpConnection ); + } signals: void ConClientListMesReceived ( CVector vecChanInfo ); @@ -499,6 +517,8 @@ protected slots: void CLRedServerListReceived ( CHostAddress InetAddr, CVector vecServerInfo ); + void CLTcpSupported ( CHostAddress InetAddr, int iID ); + void CLConnClientsListMesReceived ( CHostAddress InetAddr, CVector vecChanInfo ); void CLPingTimeWithNumClientsReceived ( CHostAddress InetAddr, int iPingTime, int iNumClients ); diff --git a/src/clientdlg.cpp b/src/clientdlg.cpp index 09409d7eaf..f0873fad4d 100644 --- a/src/clientdlg.cpp +++ b/src/clientdlg.cpp @@ -529,6 +529,8 @@ CClientDlg::CClientDlg ( CClient* pNCliP, QObject::connect ( pClient, &CClient::CLRedServerListReceived, this, &CClientDlg::OnCLRedServerListReceived ); + QObject::connect ( pClient, &CClient::CLTcpSupported, this, &CClientDlg::OnCLTcpSupported ); + QObject::connect ( pClient, &CClient::CLConnClientsListMesReceived, this, &CClientDlg::OnCLConnClientsListMesReceived ); QObject::connect ( pClient, &CClient::CLPingTimeWithNumClientsReceived, this, &CClientDlg::OnCLPingTimeWithNumClientsReceived ); diff --git a/src/clientdlg.h b/src/clientdlg.h index 687fe811f4..2b72e7140c 100644 --- a/src/clientdlg.h +++ b/src/clientdlg.h @@ -222,13 +222,16 @@ public slots: void OnNewLocalInputText ( QString strChatText ) { pClient->CreateChatTextMes ( strChatText ); } - void OnReqServerListQuery ( CHostAddress InetAddr ) { pClient->CreateCLReqServerListMes ( InetAddr ); } + void OnReqServerListQuery ( CHostAddress InetAddr, enum EProtoMode eProtoMode ) { pClient->CreateCLReqServerListMes ( InetAddr, eProtoMode ); } void OnCreateCLServerListPingMes ( CHostAddress InetAddr ) { pClient->CreateCLServerListPingMes ( InetAddr ); } void OnCreateCLServerListReqVerAndOSMes ( CHostAddress InetAddr ) { pClient->CreateCLServerListReqVerAndOSMes ( InetAddr ); } - void OnCreateCLServerListReqConnClientsListMes ( CHostAddress InetAddr ) { pClient->CreateCLServerListReqConnClientsListMes ( InetAddr ); } + void OnCreateCLServerListReqConnClientsListMes ( CHostAddress InetAddr, enum EProtoMode eProtoMode ) + { + pClient->CreateCLServerListReqConnClientsListMes ( InetAddr, eProtoMode ); + } void OnCLServerListReceived ( CHostAddress InetAddr, CVector vecServerInfo ) { @@ -240,6 +243,8 @@ public slots: ConnectDlg.SetServerList ( InetAddr, vecServerInfo, true ); } + void OnCLTcpSupported ( CHostAddress InetAddr, int iID ) { ConnectDlg.SetTcpSupported ( InetAddr, iID ); } + void OnCLConnClientsListMesReceived ( CHostAddress InetAddr, CVector vecChanInfo ) { ConnectDlg.SetConnClientsList ( InetAddr, vecChanInfo ); diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index 02324121e3..e6fc5d36ee 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -193,7 +193,7 @@ CClientRpc::CClientRpc ( CClient* pClient, CClientSettings* pSettings, CRpcServe if ( NetworkUtil::ParseNetworkAddress ( jsonDirectoryIp.toString(), haDirectoryAddress, false ) ) { // send the request for the server list - pClient->CreateCLReqServerListMes ( haDirectoryAddress ); + pClient->CreateCLReqServerListMes ( haDirectoryAddress, PROTO_UDP ); response["result"] = "ok"; } else diff --git a/src/connectdlg.cpp b/src/connectdlg.cpp index 05127ded37..61bcf4fcda 100644 --- a/src/connectdlg.cpp +++ b/src/connectdlg.cpp @@ -358,7 +358,7 @@ void CConnectDlg::RequestServerList() false ) ) { // send the request for the server list - emit ReqServerListQuery ( haDirectoryAddress ); + emit ReqServerListQuery ( haDirectoryAddress, PROTO_UDP ); // start timer, if this message did not get any respond to retransmit // the server list request message @@ -401,7 +401,7 @@ void CConnectDlg::OnTimerReRequestServList() { // note that this is a connection less message which may get lost // and therefore it makes sense to re-transmit it - emit ReqServerListQuery ( haDirectoryAddress ); + emit ReqServerListQuery ( haDirectoryAddress, PROTO_UDP ); } } @@ -553,6 +553,9 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVectorsetData ( LVC_NAME, Qt::UserRole, CurHostAddress.toString() ); + enum EClientFetchMode eFetchMode = CFM_UDP_REQUEST; // start off in UDP mode + pNewListViewItem->setData ( LVC_CLIENTS, Qt::UserRole, eFetchMode ); // initialise fetch mode + // per default expand the list item (if not "show all servers") if ( bShowAllMusicians ) { @@ -566,6 +569,48 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVector ( pCurListViewItem->data ( LVC_CLIENTS, Qt::UserRole ).toInt() ); + + if ( eFetchMode == CFM_UDP_REQUEST ) + { + // client list not yet received - switch to TCP mode + eFetchMode = CFM_TCP; + pCurListViewItem->setData ( LVC_CLIENTS, Qt::UserRole, eFetchMode ); // remember for future fetches + + emit CreateCLServerListReqConnClientsListMes ( InetAddr, PROTO_TCP_ONCE ); // close TCP connection after receiving reply + } + } + } + break; + + default: + break; + } +} + void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr, const CVector& vecChanInfo ) { // find the server with the correct address @@ -573,6 +618,16 @@ void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr, const CVect if ( pCurListViewItem ) { + // find the current fetch mode for the client list for this server + enum EClientFetchMode eFetchMode = static_cast ( pCurListViewItem->data ( LVC_CLIENTS, Qt::UserRole ).toInt() ); + + if ( eFetchMode != CFM_TCP ) + { + // not switched to TCP mode - set to UDP for successful fetch + eFetchMode = CFM_UDP_RESULT; + pCurListViewItem->setData ( LVC_CLIENTS, Qt::UserRole, eFetchMode ); + } + // first remove any existing children DeleteAllListViewItemChilds ( pCurListViewItem ); @@ -1011,7 +1066,16 @@ void CConnectDlg::SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, // connected clients, if not then request the client names if ( iNumClients != pCurListViewItem->childCount() ) { - emit CreateCLServerListReqConnClientsListMes ( InetAddr ); + // find the current fetch mode for the client list for this server + enum EClientFetchMode eFetchMode = static_cast ( pCurListViewItem->data ( LVC_CLIENTS, Qt::UserRole ).toInt() ); + + if ( eFetchMode != CFM_TCP ) + { + // not switched to TCP mode - reset for next UDP fetch + eFetchMode = CFM_UDP_REQUEST; + pCurListViewItem->setData ( LVC_CLIENTS, Qt::UserRole, eFetchMode ); + } + emit CreateCLServerListReqConnClientsListMes ( InetAddr, eFetchMode == CFM_TCP ? PROTO_TCP_ONCE : PROTO_UDP ); } // this is the first time a ping time was received, set item to visible diff --git a/src/connectdlg.h b/src/connectdlg.h index 2d82a8c454..3bc6f63b57 100644 --- a/src/connectdlg.h +++ b/src/connectdlg.h @@ -91,6 +91,8 @@ class CConnectDlg : public CBaseDlg, private Ui_CConnectDlgBase void SetServerList ( const CHostAddress& InetAddr, const CVector& vecServerInfo, const bool bIsReducedServerList = false ); + void SetTcpSupported ( const CHostAddress& InetAddr, int iID ); + void SetConnClientsList ( const CHostAddress& InetAddr, const CVector& vecChanInfo ); void SetPingTimeAndNumClientsResult ( const CHostAddress& InetAddr, const int iPingTime, const int iNumClients ); @@ -115,6 +117,15 @@ class CConnectDlg : public CBaseDlg, private Ui_CConnectDlgBase }; protected: + // UDP/TCP mode for fetching client list - stored in data field for LVC_CLIENTS column + enum EClientFetchMode + { + CFM_UDP_REQUEST, // set when sending request by UDP + CFM_UDP_RESULT, // set when received a client list by UDP + CFM_TCP, // set when "TCP Supported" message arrives but client list has not arrived - + // re-request using TCP and remain in TCP mode + }; + virtual void showEvent ( QShowEvent* ); virtual void hideEvent ( QHideEvent* ); @@ -157,8 +168,8 @@ public slots: void OnCurrentServerItemChanged ( QTreeWidgetItem* current, QTreeWidgetItem* previous ); signals: - void ReqServerListQuery ( CHostAddress InetAddr ); + void ReqServerListQuery ( CHostAddress InetAddr, enum EProtoMode eProtoMode ); void CreateCLServerListPingMes ( CHostAddress InetAddr ); void CreateCLServerListReqVerAndOSMes ( CHostAddress InetAddr ); - void CreateCLServerListReqConnClientsListMes ( CHostAddress InetAddr ); + void CreateCLServerListReqConnClientsListMes ( CHostAddress InetAddr, enum EProtoMode eProtoMode ); }; diff --git a/src/main.cpp b/src/main.cpp index f840503b88..d3f9be044e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -119,6 +119,7 @@ int main ( int argc, char** argv ) bool bUseTranslation = true; bool bCustomPortNumberGiven = false; bool bDisableIPv6 = false; + bool bEnableTcp = false; int iNumServerChannels = DEFAULT_USED_NUM_CHANNELS; quint16 iPortNumber = DEFAULT_PORT_NUMBER; int iJsonRpcPortNumber = INVALID_PORT; @@ -281,6 +282,16 @@ int main ( int argc, char** argv ) // Server only: + // Enable TCP server --------------------------------------------------- + if ( GetFlagArgument ( argv, i, "--enabletcp", "--enabletcp" ) ) + { + bEnableTcp = true; + qInfo() << "- TCP server enabled"; + CommandLineOptions << "--enabletcp"; + ServerOnlyOptions << "--enabletcp"; + continue; + } + // Disconnect all clients on quit -------------------------------------- if ( GetFlagArgument ( argv, i, "-d", "--discononquit" ) ) { @@ -1018,6 +1029,7 @@ int main ( int argc, char** argv ) bDisableRecording, bDelayPan, bDisableIPv6, + bEnableTcp, eLicenceType ); #ifndef NO_JSON_RPC @@ -1144,6 +1156,7 @@ QString UsageArguments ( char** argv ) " -s, --server start Server\n" " --serverbindip IPv4 address the Server will bind to (rather than all)\n" " (only works if IPv6 is unavailable or disabled with --noipv6)\n" + " --enabletcp enable TCP server for Jamulus protocol\n" " -T, --multithreading use multithreading to make better use of\n" " multi-core CPUs and support more Clients\n" " -u, --numchannels maximum number of channels\n" diff --git a/src/protocol.cpp b/src/protocol.cpp index a595a24e45..0c0cf1d2cc 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -387,6 +387,11 @@ CONNECTION LESS MESSAGES +--------------------+--------------+ +- PROTMESSID_CLM_EMPTY_MESSAGE: Empty message (No-op) + + note: does not have any data -> n = 0 + + - PROTMESSID_CLM_DISCONNECTION: Disconnect message note: does not have any data -> n = 0 @@ -459,6 +464,28 @@ CONNECTION LESS MESSAGES five times for one registration request at 500ms intervals. Beyond this, it should "ping" every 15 minutes (standard re-registration timeout). + + +- PROTMESSID_CLM_TCP_SUPPORTED: TCP supported message + + +-------------------------------------------------------+ + | 2 bytes ID of message to be potentially sent over TCP | + +-------------------------------------------------------+ + + the ID indicates which type of message relates to it: + - PROTMESSID_CLM_SERVER_LIST + - PROTMESSID_CLM_CONN_CLIENTS_LIST + - PROTMESSID_CLM_CLIENT_ID + + +- PROTMESSID_CLM_CLIENT_ID: Sends the client's channel ID back to the server + + +---------------------------------+ + | 1 byte channel ID of the client | + +---------------------------------+ + + the ID informs the server with which channel to associate the TCP connection + */ #include "protocol.h" @@ -632,7 +659,11 @@ void CProtocol::CreateAndImmSendAcknMess ( const int& iID, const int& iCnt ) emit MessReadyForSending ( vecAcknMessage ); } -void CProtocol::CreateAndImmSendConLessMessage ( const int iID, const CVector& vecData, const CHostAddress& InetAddr ) +void CProtocol::CreateAndImmSendConLessMessage ( const int iID, + const CVector& vecData, + const CHostAddress& InetAddr, + CTcpConnection* pTcpConnection, + enum EProtoMode eProtoMode ) { CVector vecNewMessage; @@ -641,7 +672,7 @@ void CProtocol::CreateAndImmSendConLessMessage ( const int iID, const CVector& vecbyMesBodyData, const int iRecCounter, const int iRecID ) @@ -869,7 +900,10 @@ void CProtocol::ParseMessageBody ( const CVector& vecbyMesBodyData, con } } -void CProtocol::ParseConnectionLessMessageBody ( const CVector& vecbyMesBodyData, const int iRecID, const CHostAddress& InetAddr ) +void CProtocol::ParseConnectionLessMessageBody ( const CVector& vecbyMesBodyData, + const int iRecID, + const CHostAddress& InetAddr, + CTcpConnection* pTcpConnection ) { //### TEST: BEGIN ###// // Test channel implementation: randomly delete protocol messages (50 % loss) @@ -901,7 +935,7 @@ void CProtocol::ParseConnectionLessMessageBody ( const CVector& vecbyMe break; case PROTMESSID_CLM_REQ_SERVER_LIST: - EvaluateCLReqServerListMes ( InetAddr ); + EvaluateCLReqServerListMes ( InetAddr, pTcpConnection ); break; case PROTMESSID_CLM_SEND_EMPTY_MESSAGE: @@ -933,11 +967,11 @@ void CProtocol::ParseConnectionLessMessageBody ( const CVector& vecbyMe break; case PROTMESSID_CLM_CONN_CLIENTS_LIST: - EvaluateCLConnClientsListMes ( InetAddr, vecbyMesBodyData ); + EvaluateCLConnClientsListMes ( InetAddr, vecbyMesBodyData, pTcpConnection ); break; case PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST: - EvaluateCLReqConnClientsListMes ( InetAddr ); + EvaluateCLReqConnClientsListMes ( InetAddr, pTcpConnection ); break; case PROTMESSID_CLM_CHANNEL_LEVEL_LIST: @@ -947,6 +981,14 @@ void CProtocol::ParseConnectionLessMessageBody ( const CVector& vecbyMe case PROTMESSID_CLM_REGISTER_SERVER_RESP: EvaluateCLRegisterServerResp ( InetAddr, vecbyMesBodyData ); break; + + case PROTMESSID_CLM_TCP_SUPPORTED: + EvaluateCLTcpSupportedMes ( InetAddr, vecbyMesBodyData ); + break; + + case PROTMESSID_CLM_CLIENT_ID: + EvaluateCLClientIDMes ( InetAddr, vecbyMesBodyData, pTcpConnection ); + break; } } @@ -2046,7 +2088,7 @@ bool CProtocol::EvaluateCLUnregisterServerMes ( const CHostAddress& InetAddr ) return false; // no error } -void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr, const CVector vecServerInfo ) +void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr, const CVector vecServerInfo, CTcpConnection* pTcpConnection ) { const int iNumServers = vecServerInfo.Size(); @@ -2101,7 +2143,7 @@ void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr, const CVec PutStringUTF8OnStream ( vecData, iPos, strUTF8City ); } - CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_LIST, vecData, InetAddr ); + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_LIST, vecData, InetAddr, pTcpConnection ); } bool CProtocol::EvaluateCLServerListMes ( const CHostAddress& InetAddr, const CVector& vecData ) @@ -2261,15 +2303,15 @@ bool CProtocol::EvaluateCLRedServerListMes ( const CHostAddress& InetAddr, const return false; // no error } -void CProtocol::CreateCLReqServerListMes ( const CHostAddress& InetAddr ) +void CProtocol::CreateCLReqServerListMes ( const CHostAddress& InetAddr, enum EProtoMode eProtoMode ) { - CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REQ_SERVER_LIST, CVector ( 0 ), InetAddr ); + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REQ_SERVER_LIST, CVector ( 0 ), InetAddr, nullptr, eProtoMode ); } -bool CProtocol::EvaluateCLReqServerListMes ( const CHostAddress& InetAddr ) +bool CProtocol::EvaluateCLReqServerListMes ( const CHostAddress& InetAddr, CTcpConnection* pTcpConnection ) { // invoke message action - emit CLReqServerList ( InetAddr ); + emit CLReqServerList ( InetAddr, pTcpConnection ); return false; // no error } @@ -2312,11 +2354,11 @@ bool CProtocol::EvaluateCLSendEmptyMesMes ( const CVector& vecData ) return false; // no error } -void CProtocol::CreateCLEmptyMes ( const CHostAddress& InetAddr ) +void CProtocol::CreateCLEmptyMes ( const CHostAddress& InetAddr, CTcpConnection* pTcpConnection ) { // special message: for this message there exist no Evaluate // function - CreateAndImmSendConLessMessage ( PROTMESSID_CLM_EMPTY_MESSAGE, CVector ( 0 ), InetAddr ); + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_EMPTY_MESSAGE, CVector ( 0 ), InetAddr, pTcpConnection ); } void CProtocol::CreateCLDisconnection ( const CHostAddress& InetAddr ) @@ -2404,7 +2446,7 @@ bool CProtocol::EvaluateCLReqVersionAndOSMes ( const CHostAddress& InetAddr ) return false; // no error } -void CProtocol::CreateCLConnClientsListMes ( const CHostAddress& InetAddr, const CVector& vecChanInfo ) +void CProtocol::CreateCLConnClientsListMes ( const CHostAddress& InetAddr, const CVector& vecChanInfo, CTcpConnection* pTcpConnection ) { const int iNumClients = vecChanInfo.Size(); @@ -2452,10 +2494,10 @@ void CProtocol::CreateCLConnClientsListMes ( const CHostAddress& InetAddr, const PutStringUTF8OnStream ( vecData, iPos, strUTF8City ); } - CreateAndImmSendConLessMessage ( PROTMESSID_CLM_CONN_CLIENTS_LIST, vecData, InetAddr ); + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_CONN_CLIENTS_LIST, vecData, InetAddr, pTcpConnection ); } -bool CProtocol::EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr, const CVector& vecData ) +bool CProtocol::EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr, const CVector& vecData, CTcpConnection* pTcpConnection ) { int iPos = 0; // init position pointer const int iDataLen = vecData.Size(); @@ -2509,20 +2551,20 @@ bool CProtocol::EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr, con } // invoke message action - emit CLConnClientsListMesReceived ( InetAddr, vecChanInfo ); + emit CLConnClientsListMesReceived ( InetAddr, vecChanInfo, pTcpConnection ); return false; // no error } -void CProtocol::CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr ) +void CProtocol::CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr, enum EProtoMode eProtoMode ) { - CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST, CVector ( 0 ), InetAddr ); + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST, CVector ( 0 ), InetAddr, nullptr, eProtoMode ); } -bool CProtocol::EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr ) +bool CProtocol::EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr, CTcpConnection* pTcpConnection ) { // invoke message action - emit CLReqConnClientsList ( InetAddr ); + emit CLReqConnClientsList ( InetAddr, pTcpConnection ); return false; // no error } @@ -2620,9 +2662,80 @@ bool CProtocol::EvaluateCLRegisterServerResp ( const CHostAddress& InetAddr, con return false; // no error } +void CProtocol::CreateCLTcpSupportedMes ( const CHostAddress& InetAddr, const int iID ) +{ + int iPos = 0; // init position pointer + + // build data vector (2 bytes long) + CVector vecData ( 2 ); + + // message ID just sent (2 bytes) + PutValOnStream ( vecData, iPos, static_cast ( iID ), 2 ); + + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_TCP_SUPPORTED, vecData, InetAddr ); +} + +bool CProtocol::EvaluateCLTcpSupportedMes ( const CHostAddress& InetAddr, const CVector& vecData ) +{ + int iPos = 0; // init position pointer + + // check size + if ( vecData.Size() != 2 ) + { + return true; // return error code + } + + // invoke message action + emit CLTcpSupported ( InetAddr, static_cast ( GetValFromStream ( vecData, iPos, 2 ) ) ); + + return false; // no error +} + +void CProtocol::CreateCLClientIDMes ( const CHostAddress& InetAddr, const int iChanID, enum EProtoMode eProtoMode ) +{ + int iPos = 0; // init position pointer + + // build data vector (1 byte long) + CVector vecData ( 1 ); + + // channel ID (1 byte) + PutValOnStream ( vecData, iPos, static_cast ( iChanID ), 1 ); + + CreateAndImmSendConLessMessage ( PROTMESSID_CLM_CLIENT_ID, vecData, InetAddr, nullptr, eProtoMode ); +} + +bool CProtocol::EvaluateCLClientIDMes ( const CHostAddress& InetAddr, const CVector& vecData, CTcpConnection* pTcpConnection ) +{ + int iPos = 0; // init position pointer + + // check size + if ( vecData.Size() != 1 ) + { + return true; // return error code + } + + // channel ID + const int iCurID = static_cast ( GetValFromStream ( vecData, iPos, 1 ) ); + + // invoke message action + emit CLClientIDReceived ( InetAddr, iCurID, pTcpConnection ); + + return false; // no error +} + /******************************************************************************\ * Message generation and parsing * \******************************************************************************/ +int CProtocol::GetBodyLength ( const CVector& vecbyData ) +{ + int iCurPos = 5; // position of length calculation + + // 2 bytes length + const int iLenBy = static_cast ( GetValFromStream ( vecbyData, iCurPos, 2 ) ); + + return iLenBy + 2; // remaining length to read, including CRC +} + bool CProtocol::ParseMessageFrame ( const CVector& vecbyData, const int iNumBytesIn, CVector& vecbyMesBodyData, diff --git a/src/protocol.h b/src/protocol.h index 4621fe31b7..422e4b3c98 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -53,6 +53,7 @@ #include #include "global.h" #include "util.h" +#include "tcpconnection.h" /* Definitions ****************************************************************/ // protocol message IDs @@ -106,6 +107,8 @@ #define PROTMESSID_CLM_REGISTER_SERVER_RESP 1016 // status of server registration request #define PROTMESSID_CLM_REGISTER_SERVER_EX 1017 // register server with extended information #define PROTMESSID_CLM_RED_SERVER_LIST 1018 // reduced server list +#define PROTMESSID_CLM_TCP_SUPPORTED 1019 // TCP is supported +#define PROTMESSID_CLM_CLIENT_ID 1020 // Client ID associated with TCP connection // special IDs #define PROTMESSID_SPECIAL_SPLIT_MESSAGE 2001 // a container for split messages @@ -121,6 +124,14 @@ #define MESS_SPLIT_PART_SIZE_BYTES 550 #define MAX_NUM_MESS_SPLIT_PARTS ( MAX_SIZE_BYTES_NETW_BUF / MESS_SPLIT_PART_SIZE_BYTES ) +/* Enum for protocol mode *****************************************************/ +enum EProtoMode +{ + PROTO_UDP, + PROTO_TCP_ONCE, + PROTO_TCP_LONG, +}; + /* Classes ********************************************************************/ class CProtocol : public QObject { @@ -165,18 +176,22 @@ class CProtocol : public QObject void CreateCLRegisterServerMes ( const CHostAddress& InetAddr, const CHostAddress& LInetAddr, const CServerCoreInfo& ServerInfo ); void CreateCLRegisterServerExMes ( const CHostAddress& InetAddr, const CHostAddress& LInetAddr, const CServerCoreInfo& ServerInfo ); void CreateCLUnregisterServerMes ( const CHostAddress& InetAddr ); - void CreateCLServerListMes ( const CHostAddress& InetAddr, const CVector vecServerInfo ); + void CreateCLServerListMes ( const CHostAddress& InetAddr, const CVector vecServerInfo, CTcpConnection* pTcpConnection ); void CreateCLRedServerListMes ( const CHostAddress& InetAddr, const CVector vecServerInfo ); - void CreateCLReqServerListMes ( const CHostAddress& InetAddr ); + void CreateCLReqServerListMes ( const CHostAddress& InetAddr, enum EProtoMode eProtoMode ); void CreateCLSendEmptyMesMes ( const CHostAddress& InetAddr, const CHostAddress& TargetInetAddr ); - void CreateCLEmptyMes ( const CHostAddress& InetAddr ); + void CreateCLEmptyMes ( const CHostAddress& InetAddr, CTcpConnection* pTcpConnection ); void CreateCLDisconnection ( const CHostAddress& InetAddr ); void CreateCLVersionAndOSMes ( const CHostAddress& InetAddr ); void CreateCLReqVersionAndOSMes ( const CHostAddress& InetAddr ); - void CreateCLConnClientsListMes ( const CHostAddress& InetAddr, const CVector& vecChanInfo ); - void CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr ); + void CreateCLConnClientsListMes ( const CHostAddress& InetAddr, const CVector& vecChanInfo, CTcpConnection* pTcpConnection ); + void CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr, enum EProtoMode eProtoMode ); void CreateCLChannelLevelListMes ( const CHostAddress& InetAddr, const CVector& vecLevelList, const int iNumClients ); void CreateCLRegisterServerResp ( const CHostAddress& InetAddr, const ESvrRegResult eResult ); + void CreateCLTcpSupportedMes ( const CHostAddress& InetAddr, const int iID ); + void CreateCLClientIDMes ( const CHostAddress& InetAddr, const int iChanID, enum EProtoMode eProtoMode ); + + static int GetBodyLength ( const CVector& vecbyData ); static bool ParseMessageFrame ( const CVector& vecbyData, const int iNumBytesIn, @@ -186,7 +201,10 @@ class CProtocol : public QObject void ParseMessageBody ( const CVector& vecbyMesBodyData, const int iRecCounter, const int iRecID ); - void ParseConnectionLessMessageBody ( const CVector& vecbyMesBodyData, const int iRecID, const CHostAddress& InetAddr ); + void ParseConnectionLessMessageBody ( const CVector& vecbyMesBodyData, + const int iRecID, + const CHostAddress& InetAddr, + CTcpConnection* pTcpConnection ); static bool IsConnectionLessMessageID ( const int iID ) { return ( iID >= 1000 ) && ( iID < 2000 ); } @@ -265,7 +283,11 @@ class CProtocol : public QObject void CreateAndSendMessage ( const int iID, const CVector& vecData ); - void CreateAndImmSendConLessMessage ( const int iID, const CVector& vecData, const CHostAddress& InetAddr ); + void CreateAndImmSendConLessMessage ( const int iID, + const CVector& vecData, + const CHostAddress& InetAddr, + CTcpConnection* pTcpConnection = nullptr, + enum EProtoMode eProtoMode = PROTO_UDP ); bool EvaluateJitBufMes ( const CVector& vecData ); bool EvaluateReqJitBufMes(); @@ -295,15 +317,17 @@ class CProtocol : public QObject bool EvaluateCLUnregisterServerMes ( const CHostAddress& InetAddr ); bool EvaluateCLServerListMes ( const CHostAddress& InetAddr, const CVector& vecData ); bool EvaluateCLRedServerListMes ( const CHostAddress& InetAddr, const CVector& vecData ); - bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr ); + bool EvaluateCLReqServerListMes ( const CHostAddress& InetAddr, CTcpConnection* pTcpConnection ); bool EvaluateCLSendEmptyMesMes ( const CVector& vecData ); bool EvaluateCLDisconnectionMes ( const CHostAddress& InetAddr ); bool EvaluateCLVersionAndOSMes ( const CHostAddress& InetAddr, const CVector& vecData ); bool EvaluateCLReqVersionAndOSMes ( const CHostAddress& InetAddr ); - bool EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr, const CVector& vecData ); - bool EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr ); + bool EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr, const CVector& vecData, CTcpConnection* pTcpConnection ); + bool EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr, CTcpConnection* pTcpConnection ); bool EvaluateCLChannelLevelListMes ( const CHostAddress& InetAddr, const CVector& vecData ); bool EvaluateCLRegisterServerResp ( const CHostAddress& InetAddr, const CVector& vecData ); + bool EvaluateCLTcpSupportedMes ( const CHostAddress& InetAddr, const CVector& vecData ); + bool EvaluateCLClientIDMes ( const CHostAddress& InetAddr, const CVector& vecData, CTcpConnection* pTcpConnection ); int iOldRecID; int iOldRecCnt; @@ -326,7 +350,7 @@ public slots: signals: // transmitting void MessReadyForSending ( CVector vecMessage ); - void CLMessReadyForSending ( CHostAddress InetAddr, CVector vecMessage ); + void CLMessReadyForSending ( CHostAddress InetAddr, CVector vecMessage, CTcpConnection* pTcpConnection, enum EProtoMode eProtoMode ); // receiving void ChangeJittBufSize ( int iNewJitBufSize ); @@ -362,13 +386,15 @@ public slots: void CLUnregisterServerReceived ( CHostAddress InetAddr ); void CLServerListReceived ( CHostAddress InetAddr, CVector vecServerInfo ); void CLRedServerListReceived ( CHostAddress InetAddr, CVector vecServerInfo ); - void CLReqServerList ( CHostAddress InetAddr ); + void CLReqServerList ( CHostAddress InetAddr, CTcpConnection* pTcpConnection ); void CLSendEmptyMes ( CHostAddress TargetInetAddr ); void CLDisconnection ( CHostAddress InetAddr ); void CLVersionAndOSReceived ( CHostAddress InetAddr, COSUtil::EOpSystemType eOSType, QString strVersion ); void CLReqVersionAndOS ( CHostAddress InetAddr ); - void CLConnClientsListMesReceived ( CHostAddress InetAddr, CVector vecChanInfo ); - void CLReqConnClientsList ( CHostAddress InetAddr ); + void CLConnClientsListMesReceived ( CHostAddress InetAddr, CVector vecChanInfo, CTcpConnection* pTcpConnection ); + void CLReqConnClientsList ( CHostAddress InetAddr, CTcpConnection* pTcpConnection ); void CLChannelLevelListReceived ( CHostAddress InetAddr, CVector vecLevelList ); void CLRegisterServerResp ( CHostAddress InetAddr, ESvrRegResult eStatus ); + void CLTcpSupported ( CHostAddress InetAddr, int iID ); + void CLClientIDReceived ( CHostAddress InetAddr, int iChanID, CTcpConnection* pTcpConnection ); }; diff --git a/src/server.cpp b/src/server.cpp index 67274965bc..86e3e3593b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -66,6 +66,7 @@ CServer::CServer ( const int iNewMaxNumChan, const bool bDisableRecording, const bool bNDelayPan, const bool bNDisableIPv6, + const bool bNEnableTcp, const ELicenceType eNLicenceType ) : bUseDoubleSystemFrameSize ( bNUseDoubleSystemFrameSize ), bUseMultithreading ( bNUseMultithreading ), @@ -74,6 +75,7 @@ CServer::CServer ( const int iNewMaxNumChan, bDisableRaw ( bNDisableRaw ), bIPv6Available ( false ), Socket ( this, iPortNumber, iQosNumber, strServerBindIP, bNDisableIPv6, bIPv6Available ), + TcpServer ( this, strServerBindIP, iPortNumber ), Logging(), iFrameCount ( 0 ), HighPrecisionTimer ( bNUseDoubleSystemFrameSize ), @@ -85,11 +87,13 @@ CServer::CServer ( const int iNewMaxNumChan, strServerPublicIP, strServerListFilter, iNewMaxNumChan, + bNEnableTcp, &ConnLessProtocol ), JamController ( this ), bDisableRecording ( bDisableRecording ), bAutoRunMinimized ( false ), bDelayPan ( bNDelayPan ), + bEnableTcp ( bNEnableTcp ), eLicenceType ( eNLicenceType ), bDisconnectAllClientsOnQuit ( bNDisconnectAllClientsOnQuit ), pSignalHandler ( CSignalHandler::getSingletonP() ) @@ -291,6 +295,8 @@ CServer::CServer ( const int iNewMaxNumChan, QObject::connect ( &ConnLessProtocol, &CProtocol::CLReqConnClientsList, this, &CServer::OnCLReqConnClientsList ); + QObject::connect ( &ConnLessProtocol, &CProtocol::CLClientIDReceived, this, &CServer::OnCLClientIDReceived ); + QObject::connect ( &ServerListManager, &CServerListManager::SvrRegStatusChanged, this, &CServer::SvrRegStatusChanged ); QObject::connect ( &JamController, &recorder::CJamController::RestartRecorder, this, &CServer::RestartRecorder ); @@ -317,6 +323,10 @@ CServer::CServer ( const int iNewMaxNumChan, // start the socket (it is important to start the socket after all // initializations and connections) Socket.Start(); + if ( bEnableTcp ) + { + TcpServer.Start(); + } } template @@ -392,6 +402,12 @@ void CServer::OnNewConnection ( int iChID, int iTotChans, CHostAddress RecHostAd { QMutexLocker locker ( &Mutex ); + // if TCP is enabled, we need to announce this first, before sending Client ID + if ( bEnableTcp ) + { + ConnLessProtocol.CreateCLTcpSupportedMes ( vecChannels[iChID].GetAddress(), PROTMESSID_CLM_CLIENT_ID ); + } + // inform the client about its own ID at the server (note that this // must be the first message to be sent for a new connection) vecChannels[iChID].CreateClientIDMes ( iChID ); @@ -405,7 +421,7 @@ void CServer::OnNewConnection ( int iChID, int iTotChans, CHostAddress RecHostAd // Send an empty channel list in order to force clients to reset their // audio mixer state. This is required to trigger clients to re-send their // gain levels upon reconnecting after server restarts. - vecChannels[iChID].CreateConClientListMes ( CVector ( 0 ) ); + vecChannels[iChID].CreateConClientListMes ( CVector ( 0 ), ConnLessProtocol ); // query support for split messages in the client vecChannels[iChID].CreateReqSplitMessSupportMes(); @@ -480,11 +496,55 @@ void CServer::OnServerFull ( CHostAddress RecHostAddr ) ConnLessProtocol.CreateCLServerFullMes ( RecHostAddr ); } -void CServer::OnSendCLProtMessage ( CHostAddress InetAddr, CVector vecMessage ) +void CServer::OnSendCLProtMessage ( CHostAddress InetAddr, CVector vecMessage, CTcpConnection* pTcpConnection, enum EProtoMode eProtoMode ) { + if ( eProtoMode != PROTO_UDP ) + { + qWarning() << "Server send cannot use TCP client"; + return; + } + // the protocol queries me to call the function to send the message // send it through the network - Socket.SendPacket ( vecMessage, InetAddr ); + if ( pTcpConnection ) + { + // send to the connected socket directly + pTcpConnection->write ( (const char*) &( (CVector) vecMessage )[0], vecMessage.Size() ); + } + else + { + Socket.SendPacket ( vecMessage, InetAddr ); + } +} + +void CServer::OnCLClientIDReceived ( CHostAddress InetAddr, int iChanID, CTcpConnection* pTcpConnection ) +{ + qDebug() << "- client ID" << iChanID << "received from" << InetAddr.toString() << "with TCP connection" << pTcpConnection; + + if ( iChanID < 0 || iChanID >= iMaxNumChannels || !vecChannels[iChanID].IsConnected() ) + { + // ID out of range or channel not connected - reject connection + pTcpConnection->disconnectFromHost(); + qWarning() << "- Jamulus-TCP: rejected invalid client ID"; + return; + } + + CChannel* pChannel = &vecChannels[iChanID]; + + qInfo() << "- Jamulus-TCP: request to link TCP connection with UDP client at" << pChannel->GetAddress().toString(); + + // compare IP addresses, but not port numbers + if ( InetAddr.InetAddr != pChannel->GetAddress().InetAddr ) + { + // IP address mismatch - reject connection + pTcpConnection->disconnectFromHost(); + qWarning() << "- Jamulus-TCP: rejected mismatched IP address"; + return; + } + + // link TCP connection with UDP channel + pTcpConnection->SetChannel ( pChannel ); + pChannel->SetTcpConnection ( pTcpConnection ); } void CServer::OnCLDisconnection ( CHostAddress InetAddr ) @@ -1270,7 +1330,7 @@ void CServer::CreateAndSendChanListForAllConChannels() if ( vecChannels[i].IsConnected() ) { // send message - vecChannels[i].CreateConClientListMes ( vecChanInfo ); + vecChannels[i].CreateConClientListMes ( vecChanInfo, ConnLessProtocol ); } } } @@ -1281,7 +1341,7 @@ void CServer::CreateAndSendChanListForThisChan ( const int iCurChanID ) CVector vecChanInfo ( CreateChannelList() ); // now send connected channels list to the channel with the ID "iCurChanID" - vecChannels[iCurChanID].CreateConClientListMes ( vecChanInfo ); + vecChannels[iCurChanID].CreateConClientListMes ( vecChanInfo, ConnLessProtocol ); } void CServer::CreateAndSendChatTextForAllConChannels ( const int iCurChanID, const QString& strChatText ) @@ -1475,12 +1535,12 @@ void CServer::DumpChannels ( const QString& title ) } } -void CServer::OnProtocolCLMessageReceived ( int iRecID, CVector vecbyMesBodyData, CHostAddress RecHostAddr ) +void CServer::OnProtocolCLMessageReceived ( int iRecID, CVector vecbyMesBodyData, CHostAddress RecHostAddr, CTcpConnection* pTcpConnection ) { QMutexLocker locker ( &Mutex ); // connection less messages are always processed - ConnLessProtocol.ParseConnectionLessMessageBody ( vecbyMesBodyData, iRecID, RecHostAddr ); + ConnLessProtocol.ParseConnectionLessMessageBody ( vecbyMesBodyData, iRecID, RecHostAddr, pTcpConnection ); } void CServer::OnProtocolMessageReceived ( int iRecCounter, int iRecID, CVector vecbyMesBodyData, CHostAddress RecHostAddr ) diff --git a/src/server.h b/src/server.h index 2e6b13e835..19ff17ca29 100644 --- a/src/server.h +++ b/src/server.h @@ -64,6 +64,8 @@ #include "util.h" #include "serverlogging.h" #include "serverlist.h" +#include "tcpserver.h" +#include "tcpconnection.h" #include "recorder/jamcontroller.h" #include "threadpool.h" @@ -126,6 +128,7 @@ class CServer : public QObject, public CServerSlots const bool bDisableRecording, const bool bNDelayPan, const bool bNDisableIPv6, + const bool bNEnableTcp, const ELicenceType eNLicenceType ); virtual ~CServer(); @@ -293,6 +296,7 @@ class CServer : public QObject, public CServerSlots // actual working objects bool bIPv6Available; // must be before Socket - passed by reference to Socket CHighPrioSocket Socket; + CTcpServer TcpServer; // logging CServerLogging Logging; @@ -315,6 +319,9 @@ class CServer : public QObject, public CServerSlots // for delay panning bool bDelayPan; + // enable TCP Server + bool bEnableTcp; + // messaging QString strWelcomeMessage; ELicenceType eLicenceType; @@ -350,9 +357,9 @@ public slots: void OnServerFull ( CHostAddress RecHostAddr ); - void OnSendCLProtMessage ( CHostAddress InetAddr, CVector vecMessage ); + void OnSendCLProtMessage ( CHostAddress InetAddr, CVector vecMessage, CTcpConnection* pTcpConnection, enum EProtoMode eProtoMode ); - void OnProtocolCLMessageReceived ( int iRecID, CVector vecbyMesBodyData, CHostAddress RecHostAddr ); + void OnProtocolCLMessageReceived ( int iRecID, CVector vecbyMesBodyData, CHostAddress RecHostAddr, CTcpConnection* pTcpConnection ); void OnProtocolMessageReceived ( int iRecCounter, int iRecID, CVector vecbyMesBodyData, CHostAddress RecHostAddr ); @@ -368,15 +375,24 @@ public slots: // only send empty message if not a directory if ( !ServerListManager.IsDirectory() ) { - ConnLessProtocol.CreateCLEmptyMes ( TargetInetAddr ); + ConnLessProtocol.CreateCLEmptyMes ( TargetInetAddr, nullptr ); } } - void OnCLReqServerList ( CHostAddress InetAddr ) { ServerListManager.RetrieveAll ( InetAddr ); } + void OnCLReqServerList ( CHostAddress InetAddr, CTcpConnection* pTcpConnection ) { ServerListManager.RetrieveAll ( InetAddr, pTcpConnection ); } void OnCLReqVersionAndOS ( CHostAddress InetAddr ) { ConnLessProtocol.CreateCLVersionAndOSMes ( InetAddr ); } - void OnCLReqConnClientsList ( CHostAddress InetAddr ) { ConnLessProtocol.CreateCLConnClientsListMes ( InetAddr, CreateChannelList() ); } + void OnCLReqConnClientsList ( CHostAddress InetAddr, CTcpConnection* pTcpConnection ) + { + ConnLessProtocol.CreateCLConnClientsListMes ( InetAddr, CreateChannelList(), pTcpConnection ); + + // if TCP is enabled but this request is on UDP, say TCP is supported + if ( bEnableTcp && !pTcpConnection ) + { + ConnLessProtocol.CreateCLTcpSupportedMes ( InetAddr, PROTMESSID_CLM_CONN_CLIENTS_LIST ); + } + } void OnCLRegisterServerReceived ( CHostAddress InetAddr, CHostAddress LInetAddr, CServerCoreInfo ServerInfo ) { @@ -398,6 +414,8 @@ public slots: void OnCLDisconnection ( CHostAddress InetAddr ); + void OnCLClientIDReceived ( CHostAddress InetAddr, int iChanID, CTcpConnection* pTcpConnection ); + void OnAboutToQuit(); void OnHandledSignal ( int sigNum ); diff --git a/src/serverlist.cpp b/src/serverlist.cpp index 90cdff4938..12e2ec8204 100644 --- a/src/serverlist.cpp +++ b/src/serverlist.cpp @@ -150,9 +150,11 @@ CServerListManager::CServerListManager ( CServer* pServer, const QString& strServerListFilter, const QString& strServerPublicIP, const int iNumChannels, + const bool bNEnableTcp, CProtocol* pNConLProt ) : pServer ( pServer ), DirectoryType ( AT_NONE ), + bEnableTcp ( bNEnableTcp ), ServerListFileName ( strServerListFileName ), strDirectoryAddress ( "" ), bIsDirectory ( false ), @@ -543,7 +545,7 @@ void CServerListManager::OnTimerPingServerInList() for ( int iIdx = 1; iIdx < iCurServerListSize; iIdx++ ) { // send empty message to keep NAT port open at registered server - pConnLessProtocol->CreateCLEmptyMes ( ServerList[iIdx].HostAddr ); + pConnLessProtocol->CreateCLEmptyMes ( ServerList[iIdx].HostAddr, nullptr ); } } @@ -685,7 +687,7 @@ void CServerListManager::Remove ( const CHostAddress& InetAddr ) and allow the client connect dialogue instead to use the IP and Port from which the list was received. */ -void CServerListManager::RetrieveAll ( const CHostAddress& InetAddr ) +void CServerListManager::RetrieveAll ( const CHostAddress& InetAddr, CTcpConnection* pTcpConnection ) { QMutexLocker locker ( &Mutex ); @@ -731,7 +733,9 @@ void CServerListManager::RetrieveAll ( const CHostAddress& InetAddr ) } // do not send a "ping" to a server local to the directory (no need) - if ( !serverIsInternal ) + // also only do so if processing a request over UDP, not TCP, + // as the client will always try UDP before TCP. + if ( !serverIsInternal && !pTcpConnection ) { // create "send empty message" for all other registered servers // this causes the server (vecServerInfo[iIdx].HostAddr) @@ -744,8 +748,18 @@ void CServerListManager::RetrieveAll ( const CHostAddress& InetAddr ) // send the server list to the client, since we do not know that the client // has a UDP fragmentation issue, we send both lists, the reduced and the // normal list after each other - pConnLessProtocol->CreateCLRedServerListMes ( InetAddr, vecServerInfo ); - pConnLessProtocol->CreateCLServerListMes ( InetAddr, vecServerInfo ); + if ( !pTcpConnection ) + { + // no need for reduced list if on TCP + pConnLessProtocol->CreateCLRedServerListMes ( InetAddr, vecServerInfo ); + } + pConnLessProtocol->CreateCLServerListMes ( InetAddr, vecServerInfo, pTcpConnection ); + + // if TCP is enabled but this request is on UDP, say TCP is supported + if ( bEnableTcp && !pTcpConnection ) + { + pConnLessProtocol->CreateCLTcpSupportedMes ( InetAddr, PROTMESSID_CLM_SERVER_LIST ); + } } } @@ -939,7 +953,7 @@ void CServerListManager::OnTimerPingServers() { // send empty message to directory to keep NAT port open -> we do // not require any answer from the directory - pConnLessProtocol->CreateCLEmptyMes ( DirectoryAddress ); + pConnLessProtocol->CreateCLEmptyMes ( DirectoryAddress, nullptr ); } } diff --git a/src/serverlist.h b/src/serverlist.h index f18c40678d..857d8aec4f 100644 --- a/src/serverlist.h +++ b/src/serverlist.h @@ -166,6 +166,7 @@ class CServerListManager : public QObject const QString& strServerListFilter, const QString& strServerPublicIP, const int iNumChannels, + const bool bNEnableTcp, CProtocol* pNConLProt ); void SetServerName ( const QString& strNewName ); @@ -193,7 +194,7 @@ class CServerListManager : public QObject void Append ( const CHostAddress& InetAddr, const CHostAddress& LInetAddr, const CServerCoreInfo& ServerInfo, const QString strVersion = "" ); void Remove ( const CHostAddress& InetAddr ); - void RetrieveAll ( const CHostAddress& InetAddr ); + void RetrieveAll ( const CHostAddress& InetAddr, CTcpConnection* pTcpConnection ); void StoreRegistrationResult ( ESvrRegResult eStatus ); @@ -218,6 +219,8 @@ class CServerListManager : public QObject CHostAddress DirectoryAddress; EDirectoryType DirectoryType; + bool bEnableTcp; + CHostAddress ServerPublicIP; CHostAddress ServerPublicIP6; diff --git a/src/socket.h b/src/socket.h index b81ea4d69d..4c95fdfd97 100644 --- a/src/socket.h +++ b/src/socket.h @@ -53,6 +53,7 @@ #include "global.h" #include "protocol.h" #include "util.h" +#include "tcpconnection.h" #ifndef _WIN32 # include # include @@ -138,7 +139,7 @@ class CSocket : public QObject void ProtocolMessageReceived ( int iRecCounter, int iRecID, CVector vecbyMesBodyData, CHostAddress HostAdr ); - void ProtocolCLMessageReceived ( int iRecID, CVector vecbyMesBodyData, CHostAddress HostAdr ); + void ProtocolCLMessageReceived ( int iRecID, CVector vecbyMesBodyData, CHostAddress HostAdr, CTcpConnection* pTcpConnection = nullptr ); }; /* Socket which runs in a separate high priority thread --------------------- */ diff --git a/src/tcpconnection.cpp b/src/tcpconnection.cpp new file mode 100644 index 0000000000..716b035cba --- /dev/null +++ b/src/tcpconnection.cpp @@ -0,0 +1,228 @@ +/******************************************************************************\ + * Copyright (c) 2024-2026 + * + * Author(s): + * Tony Mountifield + * + ****************************************************************************** + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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 . + * +\******************************************************************************/ + +#include "protocol.h" +#include "server.h" +#ifndef SERVER_ONLY +# include "client.h" +#endif +#include "channel.h" + +#ifndef SERVER_ONLY +// TCP connection used by client +CTcpConnection::CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcpAddress, CClient* pClient, CChannel* pChannel, bool bIsSession ) : + pTcpSocket ( pTcpSocket ), + tcpAddress ( tcpAddress ), + pServer ( nullptr ), + pChannel ( pChannel ), + bIsSession ( bIsSession ) +{ + vecbyRecBuf.Init ( MAX_SIZE_BYTES_NETW_BUF ); + iPos = 0; + iPayloadRemain = 0; + + connect ( pTcpSocket, &QTcpSocket::disconnected, this, &CTcpConnection::OnDisconnected ); + connect ( pTcpSocket, &QTcpSocket::readyRead, this, &CTcpConnection::OnReadyRead ); + + connect ( this, &CTcpConnection::ProtocolCLMessageReceived, pChannel, &CChannel::OnProtocolCLMessageReceived ); + + if ( bIsSession ) + { + // set up keepalive CLM_EMPTY_MESSAGE over TCP session connection + connect ( this, &CTcpConnection::CLSendEmptyMes, pClient, &CClient::OnCLSendEmptyMes ); + connect ( &TimerKeepalive, &QTimer::timeout, this, &CTcpConnection::OnTimerKeepalive ); + TimerKeepalive.start ( TCP_KEEPALIVE_INTERVAL_MS ); + } +} +#endif + +// TCP connection used by server +CTcpConnection::CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcpAddress, CServer* pServer ) : + pTcpSocket ( pTcpSocket ), + tcpAddress ( tcpAddress ), + pServer ( pServer ), + pChannel ( nullptr ), + bIsSession ( false ) +{ + vecbyRecBuf.Init ( MAX_SIZE_BYTES_NETW_BUF ); + iPos = 0; + iPayloadRemain = 0; + + connect ( pTcpSocket, &QTcpSocket::disconnected, this, &CTcpConnection::OnDisconnected ); + connect ( pTcpSocket, &QTcpSocket::readyRead, this, &CTcpConnection::OnReadyRead ); + + connect ( this, &CTcpConnection::ProtocolCLMessageReceived, pServer, &CServer::OnProtocolCLMessageReceived ); + + // setup an idle timer on the server side only + connect ( &TimerIdleTimeout, &QTimer::timeout, this, &CTcpConnection::OnTimerIdleTimeout ); + TimerIdleTimeout.setSingleShot ( true ); + TimerIdleTimeout.start ( TCP_IDLE_TIMEOUT_MS ); +} + +void CTcpConnection::OnDisconnected() +{ + qInfo() << "- Jamulus-TCP: disconnected from:" << tcpAddress.toString(); + TimerKeepalive.stop(); + TimerIdleTimeout.stop(); + pTcpSocket->deleteLater(); + if ( pChannel && pChannel->GetTcpConnection() == this ) + { + pChannel->SetTcpConnection ( nullptr ); // unlink from channel + } + deleteLater(); // delete this object in the next event loop +} + +void CTcpConnection::OnReadyRead() +{ + long iBytesAvail = pTcpSocket->bytesAvailable(); + + qDebug() << "- readyRead(), bytesAvailable() =" << iBytesAvail; + + while ( iBytesAvail > 0 ) + { + if ( iPos < MESS_HEADER_LENGTH_BYTE ) + { + // reading message header + long iNumBytesRead = pTcpSocket->read ( (char*) &vecbyRecBuf[iPos], MESS_HEADER_LENGTH_BYTE - iPos ); + if ( iNumBytesRead == -1 ) + { + return; + } + + qDebug() << "-- (hdr) iNumBytesRead =" << iNumBytesRead; + + iPos += iNumBytesRead; + iBytesAvail -= iNumBytesRead; + + if ( iPos >= MESS_HEADER_LENGTH_BYTE ) + { + // now have a complete header + iPayloadRemain = CProtocol::GetBodyLength ( vecbyRecBuf ); + + Q_ASSERT ( iPayloadRemain <= MAX_SIZE_BYTES_NETW_BUF - MESS_HEADER_LENGTH_BYTE ); + + iPayloadRemain -= iPos - MESS_HEADER_LENGTH_BYTE; + } + } + else + { + // reading message body + long iNumBytesRead = pTcpSocket->read ( (char*) &vecbyRecBuf[iPos], iPayloadRemain ); + if ( iNumBytesRead == -1 ) + { + return; + } + + qDebug() << "-- (body) iNumBytesRead =" << iNumBytesRead; + + iPos += iNumBytesRead; + iPayloadRemain -= iNumBytesRead; + iBytesAvail -= iNumBytesRead; + + Q_ASSERT ( iPayloadRemain >= 0 ); + + if ( iPayloadRemain == 0 ) + { + // have a complete payload + qDebug() << "- Jamulus-TCP: received protocol message of length" << iPos; + + // check if this is a protocol message + int iRecCounter; + int iRecID; + CVector vecbyMesBodyData; + + if ( !CProtocol::ParseMessageFrame ( vecbyRecBuf, iPos, vecbyMesBodyData, iRecCounter, iRecID ) ) + { + qDebug() << "- Jamulus-TCP: message parsed OK, ID =" << iRecID; + + // this is a protocol message, check the type of the message + if ( CProtocol::IsConnectionLessMessageID ( iRecID ) ) + { + //### TODO: BEGIN ###// + // a copy of the vector is used -> avoid malloc in real-time routine + emit ProtocolCLMessageReceived ( iRecID, vecbyMesBodyData, tcpAddress, this ); + //### TODO: END ###// + + // disconnect if it's not a client session connection + if ( !pServer && !bIsSession ) + { + pTcpSocket->disconnectFromHost(); + } + } + else + { + //### TODO: BEGIN ###// + // a copy of the vector is used -> avoid malloc in real-time routine + // emit ProtocolMessageReceived ( iRecCounter, iRecID, vecbyMesBodyData, pTcpConnection->tcpAddress, pTcpConnection ); + //### TODO: END ###// + } + } + else + { + qWarning() << "- Jamulus-TCP: failed to parse frame"; + } + + iPos = 0; // ready for next message, if any + } + } + } + + qDebug() << "- end of readyRead(), bytesAvailable() =" << pTcpSocket->bytesAvailable(); + + if ( pServer ) + { + // restart server idle timer allowing for keepalive interval + TimerIdleTimeout.start ( TCP_KEEPALIVE_INTERVAL_MS + TCP_IDLE_TIMEOUT_MS ); + } +} + +void CTcpConnection::OnTimerKeepalive() +{ + // qDebug() << "- Keepalive timer" << this << "to TCP" << tcpAddress.toString(); + emit CLSendEmptyMes ( tcpAddress, this ); +} + +void CTcpConnection::OnTimerIdleTimeout() +{ + // qDebug() << "- ConnTimeout timer" << this << "from TCP" << tcpAddress.toString(); + qWarning() << "- Jamulus-TCP: idle timeout - disconnecting"; + disconnectFromHost(); +} + +qint64 CTcpConnection::write ( const char* data, qint64 maxSize ) +{ + if ( !pTcpSocket ) + { + return -1; + } + + return pTcpSocket->write ( data, maxSize ); +} + +void CTcpConnection::disconnectFromHost() +{ + if ( pTcpSocket ) + { + pTcpSocket->disconnectFromHost(); + } +} diff --git a/src/tcpconnection.h b/src/tcpconnection.h new file mode 100644 index 0000000000..f78c20827b --- /dev/null +++ b/src/tcpconnection.h @@ -0,0 +1,91 @@ +/******************************************************************************\ + * Copyright (c) 2024-2026 + * + * Author(s): + * Tony Mountifield + * + ****************************************************************************** + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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 . + * +\******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "global.h" +#include "util.h" + +// The header files channel.h and server.h require to include this header file +// so we get a cyclic dependency. To solve this issue, prototypes of the +// channel class and server class are defined here. +class CServer; // forward declaration of CServer +class CChannel; // forward declaration of CChannel + +#define TCP_CONNECT_TIMEOUT_MS 3000 +#define TCP_IDLE_TIMEOUT_MS 5000 +#define TCP_KEEPALIVE_INTERVAL_MS 15000 + +/* Classes ********************************************************************/ +class CTcpConnection : public QObject +{ + Q_OBJECT + +public: +#ifndef SERVER_ONLY + CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcpAddress, CClient* pClient, CChannel* pChannel, bool bIsSession ); +#endif + CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcpAddress, CServer* pServer ); + ~CTcpConnection() {} + + void SetChannel ( CChannel* pChan ) { pChannel = pChan; } + CChannel* GetChannel() { return pChannel; } + + qint64 write ( const char* data, qint64 maxSize ); + void disconnectFromHost(); + + bool IsSession() { return bIsSession; } + +private: + QTcpSocket* pTcpSocket; + CHostAddress tcpAddress; + + CServer* pServer; + CChannel* pChannel; + + const bool bIsSession; + + int iPos; + int iPayloadRemain; + CVector vecbyRecBuf; + + QTimer TimerKeepalive; + QTimer TimerIdleTimeout; + +signals: + void ProtocolCLMessageReceived ( int iRecID, CVector vecbyMesBodyData, CHostAddress HostAdr, CTcpConnection* pTcpConnection ); + void CLSendEmptyMes ( CHostAddress InetAddr, CTcpConnection* pTcpConnection ); + +private slots: + void OnDisconnected(); + void OnReadyRead(); + void OnTimerKeepalive(); + void OnTimerIdleTimeout(); +}; diff --git a/src/tcpserver.cpp b/src/tcpserver.cpp new file mode 100644 index 0000000000..22b5ebb8f4 --- /dev/null +++ b/src/tcpserver.cpp @@ -0,0 +1,99 @@ +/******************************************************************************\ + * Copyright (c) 2024-2026 + * + * Author(s): + * Tony Mountifield + * + ****************************************************************************** + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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 . + * +\******************************************************************************/ + +#include "tcpserver.h" + +#include "server.h" + +CTcpServer::CTcpServer ( CServer* pNServP, const QString& strServerBindIP, int iPort ) : + pServer ( pNServP ), + strServerBindIP ( strServerBindIP ), + iPort ( iPort ), + pTcpServer ( new QTcpServer ( this ) ) +{ + connect ( pTcpServer, &QTcpServer::newConnection, this, &CTcpServer::OnNewConnection ); +} + +CTcpServer::~CTcpServer() +{ + if ( pTcpServer->isListening() ) + { + qInfo() << "- stopping Jamulus-TCP server"; + pTcpServer->close(); + } + pTcpServer->deleteLater(); +} + +bool CTcpServer::Start() +{ + if ( iPort < 0 ) + { + return false; + } + + // default to any-address for either both IP protocols or just IPv4 + QHostAddress hostAddress = pServer->IsIPv6Available() ? QHostAddress::Any : QHostAddress::AnyIPv4; + + if ( !pServer->IsIPv6Available() ) + { + if ( !strServerBindIP.isEmpty() ) + { + hostAddress = QHostAddress ( strServerBindIP ); + } + } + + if ( pTcpServer->listen ( hostAddress, iPort ) ) + { + qInfo() << qUtf8Printable ( QString ( "- Jamulus-TCP: server started on port %1" ).arg ( pTcpServer->serverPort() ) ); + return true; + } + qWarning() << qUtf8Printable ( + QString ( "- Jamulus-TCP: unable to start server on port %1: %2" ).arg ( pTcpServer->serverPort() ).arg ( pTcpServer->errorString() ) ); + return false; +} + +void CTcpServer::OnNewConnection() +{ + QTcpSocket* pSocket = pTcpServer->nextPendingConnection(); + if ( !pSocket ) + { + return; + } + + // express IPv4 address as IPv4 + CHostAddress peerAddress ( pSocket->peerAddress(), pSocket->peerPort() ); + + if ( peerAddress.InetAddr.protocol() == QAbstractSocket::IPv6Protocol ) + { + bool ok; + quint32 ip4 = peerAddress.InetAddr.toIPv4Address ( &ok ); + if ( ok ) + { + peerAddress.InetAddr.setAddress ( ip4 ); + } + } + + qDebug() << "- Jamulus-TCP: received connection from:" << peerAddress.toString(); + + new CTcpConnection ( pSocket, peerAddress, pServer ); // will auto-delete on disconnect +} diff --git a/src/tcpserver.h b/src/tcpserver.h new file mode 100644 index 0000000000..a707ed7525 --- /dev/null +++ b/src/tcpserver.h @@ -0,0 +1,62 @@ +/******************************************************************************\ + * Copyright (c) 2024-2026 + * + * Author(s): + * Tony Mountifield + * + ****************************************************************************** + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * 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 . + * +\******************************************************************************/ + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "tcpconnection.h" + +#include "global.h" +#include "util.h" + +// The header file server.h requires to include this header file +// so we get a cyclic dependency. To solve this issue, a prototype of the +// server class is defined here. +class CServer; // forward declaration of CServer + +/* Classes ********************************************************************/ +class CTcpServer : public QObject +{ + Q_OBJECT + +public: + CTcpServer ( CServer* pNServP, const QString& strServerBindIP, int iPort ); + ~CTcpServer(); + + bool Start(); + +private: + CServer* pServer; // for server + const QString strServerBindIP; + const int iPort; + QTcpServer* pTcpServer; + +private slots: + void OnNewConnection(); +}; diff --git a/src/testbench.h b/src/testbench.h index 233acd6351..6554317b5d 100644 --- a/src/testbench.h +++ b/src/testbench.h @@ -240,11 +240,11 @@ public slots: vecServerInfo[0].strCity = GenRandomString(); vecServerInfo[0].strName = GenRandomString(); - Protocol.CreateCLServerListMes ( CurHostAddress, vecServerInfo ); + Protocol.CreateCLServerListMes ( CurHostAddress, vecServerInfo, nullptr ); break; case 20: // PROTMESSID_CLM_REQ_SERVER_LIST - Protocol.CreateCLReqServerListMes ( CurHostAddress ); + Protocol.CreateCLReqServerListMes ( CurHostAddress, PROTO_UDP ); break; case 21: // PROTMESSID_CLM_SEND_EMPTY_MESSAGE @@ -252,7 +252,7 @@ public slots: break; case 22: // PROTMESSID_CLM_EMPTY_MESSAGE - Protocol.CreateCLEmptyMes ( CurHostAddress ); + Protocol.CreateCLEmptyMes ( CurHostAddress, nullptr ); break; case 23: // PROTMESSID_CLM_DISCONNECTION @@ -283,11 +283,11 @@ public slots: vecChanInfo[0].iChanID = GenRandomIntInRange ( -2, 20 ); vecChanInfo[0].strName = GenRandomString(); - Protocol.CreateCLConnClientsListMes ( CurHostAddress, vecChanInfo ); + Protocol.CreateCLConnClientsListMes ( CurHostAddress, vecChanInfo, nullptr ); break; case 29: // PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST - Protocol.CreateCLReqConnClientsListMes ( CurHostAddress ); + Protocol.CreateCLReqConnClientsListMes ( CurHostAddress, PROTO_UDP ); break; case 30: // PROTMESSID_CLM_CHANNEL_LEVEL_LIST