Skip to content

Commit 031ce5c

Browse files
committed
Request server list via TCP if required
1 parent fb6150c commit 031ce5c

File tree

6 files changed

+44
-29
lines changed

6 files changed

+44
-29
lines changed

src/client.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,15 @@ void CClient::OnSendCLProtMessage ( CHostAddress InetAddr, CVector<uint8_t> vecM
276276

277277
connect ( pSocket, &QTcpSocket::connected, this, [this, pSocket, InetAddr, vecMessage]() {
278278
// connection succeeded, give it to a CTcpConnection
279-
CTcpConnection* pTcpConnection = new CTcpConnection ( pSocket, InetAddr, nullptr ); // client connection, will self-delete on disconnect
279+
CTcpConnection* pTcpConnection =
280+
new CTcpConnection ( pSocket, InetAddr, nullptr, &Channel ); // client connection, will self-delete on disconnect
280281

281282
pTcpConnection->write ( (const char*) &( (CVector<uint8_t>) vecMessage )[0], vecMessage.Size() );
282283

283-
// the CTcpConnection object will pass the reply back up to CProtocol
284+
// the CTcpConnection object will pass the reply back up to CClient::Channel
284285
} );
286+
287+
pSocket->connectToHost ( InetAddr.InetAddr, InetAddr.iPort );
285288
}
286289
else
287290
{

src/connectdlg.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,18 @@ void CConnectDlg::SetServerList ( const CHostAddress& InetAddr, const CVector<CS
544544
TimerPing.start ( PING_UPDATE_TIME_SERVER_LIST_MS );
545545
}
546546

547-
void CConnectDlg::SetTcpSupported ( const CHostAddress& InetAddr ) { Q_UNUSED ( InetAddr ); }
547+
void CConnectDlg::SetTcpSupported ( const CHostAddress& InetAddr )
548+
{
549+
qDebug() << "- TCP supported at server" << InetAddr.toString();
550+
551+
// if we haven't received the serverlist, it must have got lost due to fragmentation
552+
// retry using TCP instead
553+
if ( !bServerListReceived )
554+
{
555+
// send the request for the server list
556+
emit ReqServerListQuery ( InetAddr, true ); // TCP
557+
}
558+
}
548559

549560
void CConnectDlg::SetConnClientsList ( const CHostAddress& InetAddr, const CVector<CChannelInfo>& vecChanInfo )
550561
{

src/tcpconnection.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,35 @@
2828
#include "server.h"
2929
#include "channel.h"
3030

31-
CTcpConnection::CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcpAddress, CServer* pServer ) :
31+
CTcpConnection::CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcpAddress, CServer* pServer, CChannel* pChannel ) :
3232
pTcpSocket ( pTcpSocket ),
3333
tcpAddress ( tcpAddress ),
34-
pServer ( pServer )
34+
pServer ( pServer ),
35+
pChannel ( pChannel )
3536
{
3637
vecbyRecBuf.Init ( MAX_SIZE_BYTES_NETW_BUF );
3738
iPos = 0;
3839
iPayloadRemain = 0;
3940

4041
connect ( pTcpSocket, &QTcpSocket::disconnected, this, &CTcpConnection::OnDisconnected );
4142
connect ( pTcpSocket, &QTcpSocket::readyRead, this, &CTcpConnection::OnReadyRead );
43+
4244
if ( pServer )
4345
{
4446
connect ( this, &CTcpConnection::ProtocolCLMessageReceived, pServer, &CServer::OnProtocolCLMessageReceived );
4547
}
48+
49+
if ( pChannel )
50+
{
51+
connect ( this, &CTcpConnection::ProtocolCLMessageReceived, pChannel, &CChannel::OnProtocolCLMessageReceived );
52+
}
4653
}
4754

4855
void CTcpConnection::OnDisconnected()
4956
{
50-
qDebug() << "- Jamulus-TCP: disconnected from:" << tcpAddress.InetAddr.toString();
57+
qDebug() << "- Jamulus-TCP: disconnected from:" << tcpAddress.toString();
5158
pTcpSocket->deleteLater();
52-
delete this;
59+
deleteLater(); // delete this object in the next event loop
5360
}
5461

5562
void CTcpConnection::OnReadyRead()
@@ -124,7 +131,7 @@ void CTcpConnection::OnReadyRead()
124131
//### TODO: END ###//
125132

126133
// disconnect if we are a client
127-
if ( !pServer )
134+
if ( pChannel )
128135
{
129136
pTcpSocket->disconnectFromHost();
130137
}

src/tcpconnection.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@
3535
#include "util.h"
3636

3737
// The header files channel.h and server.h require to include this header file
38-
// so we get a cyclic dependency. To solve this issue, a prototype of the
39-
// channel class and server class is defined here.
40-
class CServer; // forward declaration of CServer
41-
// class CChannel; // forward declaration of CChannel
38+
// so we get a cyclic dependency. To solve this issue, prototypes of the
39+
// channel class and server class are defined here.
40+
class CServer; // forward declaration of CServer
41+
class CChannel; // forward declaration of CChannel
4242

4343
/* Classes ********************************************************************/
4444
class CTcpConnection : public QObject
4545
{
4646
Q_OBJECT
4747

4848
public:
49-
CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcpAddress, CServer* pServer = nullptr );
49+
CTcpConnection ( QTcpSocket* pTcpSocket, const CHostAddress& tcpAddress, CServer* pServer, CChannel* pChannel );
5050
~CTcpConnection() {}
5151

5252
qint64 write ( const char* data, qint64 maxSize );
@@ -56,15 +56,17 @@ class CTcpConnection : public QObject
5656
CHostAddress tcpAddress;
5757
CHostAddress udpAddress;
5858

59-
CServer* pServer;
59+
CServer* pServer;
60+
CChannel* pChannel;
61+
6062
int iPos;
6163
int iPayloadRemain;
6264
CVector<uint8_t> vecbyRecBuf;
6365

6466
signals:
6567
void ProtocolCLMessageReceived ( int iRecID, CVector<uint8_t> vecbyMesBodyData, CHostAddress HostAdr, CTcpConnection* pTcpConnection );
6668

67-
protected slots:
69+
private slots:
6870
void OnDisconnected();
6971
void OnReadyRead();
7072
};

src/tcpserver.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@
2323
\******************************************************************************/
2424

2525
#include "tcpserver.h"
26-
//#include "tcpconnection.h"
2726

28-
#include "protocol.h"
2927
#include "server.h"
30-
//#include "channel.h"
3128

3229
CTcpServer::CTcpServer ( CServer* pNServP, const QString& strServerBindIP, int iPort, bool bEnableIPv6 ) :
3330
pServer ( pNServP ),
@@ -98,7 +95,7 @@ void CTcpServer::OnNewConnection()
9895
}
9996
}
10097

101-
qDebug() << "- Jamulus-TCP: received connection from:" << peerAddress.InetAddr.toString();
98+
qDebug() << "- Jamulus-TCP: received connection from:" << peerAddress.toString();
10299

103-
new CTcpConnection ( pSocket, peerAddress, pServer ); // will auto-delete on disconnect
100+
new CTcpConnection ( pSocket, peerAddress, pServer, nullptr ); // will auto-delete on disconnect
104101
}

src/tcpserver.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@
3636
#include "global.h"
3737
#include "util.h"
3838

39-
// The header files channel.h and server.h require to include this header file
39+
// The header file server.h requires to include this header file
4040
// so we get a cyclic dependency. To solve this issue, a prototype of the
41-
// channel class and server class is defined here.
41+
// server class is defined here.
4242
class CServer; // forward declaration of CServer
43-
// class CChannel; // forward declaration of CChannel
44-
// class CTcpConnection; // forward declaration of CTcpConnection
4543

4644
/* Classes ********************************************************************/
4745
class CTcpServer : public QObject
@@ -50,7 +48,7 @@ class CTcpServer : public QObject
5048

5149
public:
5250
CTcpServer ( CServer* pNServP, const QString& strServerBindIP, int iPort, bool bEnableIPv6 );
53-
virtual ~CTcpServer();
51+
~CTcpServer();
5452

5553
bool Start();
5654

@@ -61,9 +59,6 @@ class CTcpServer : public QObject
6159
const bool bEnableIPv6;
6260
QTcpServer* pTcpServer;
6361

64-
// signals:
65-
// void ProtocolCLMessageReceived ( int iRecID, CVector<uint8_t> vecbyMesBodyData, CHostAddress HostAdr, CTcpConnection* pTcpConnection );
66-
67-
protected slots:
62+
private slots:
6863
void OnNewConnection();
6964
};

0 commit comments

Comments
 (0)