Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ int main ( int argc, char** argv )
QString strServerListFilter = "";
QString strWelcomeMessage = "";
QString strClientName = "";
QString strNotifyServer = "";

#if !defined( HEADLESS ) && defined( _WIN32 )
if ( AttachConsole ( ATTACH_PARENT_PROCESS ) )
Expand Down Expand Up @@ -462,6 +463,16 @@ int main ( int argc, char** argv )
continue;
}

// Notification Server xxx.xxx.xxx.xxx:ppp-----------------------------
if ( GetStringArgument ( argc, argv, i, "--notifyserver", "--notifyserver", strArgument ) )
{

strNotifyServer = strArgument;
qInfo() << qUtf8Printable ( QString ( "- notify server: %1" ).arg ( strNotifyServer ) );
CommandLineOptions << "--notifyserver";
continue;
}

// Client Name ---------------------------------------------------------
if ( GetStringArgument ( argc,
argv,
Expand Down Expand Up @@ -852,6 +863,7 @@ int main ( int argc, char** argv )
iPortNumber,
iQosNumber,
strHTMLStatusFileName,
strNotifyServer,
strCentralServer,
strServerListFileName,
strServerInfo,
Expand Down Expand Up @@ -985,6 +997,11 @@ QString UsageArguments ( char** argv )
" -w, --welcomemessage welcome message to display on connect\n"
" (string or filename)\n"
" -z, --startminimized start minimizied\n"
" --serverpublicip specify your public IP address when\n"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've managed to duplicate the help text some how.

" running a slave and your own directory server\n"
" behind the same NAT\n"
" --serverbindip specify the IP address the server will bind to\n"
" --notifyserver specify server to receive UDP notifications IP:PORT\n"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest grabbing the short option -N and inserting this in the right order in the help text (alphabetical by short option, then any closely related options without short options).

"\n"
"Client only:\n"
" -c, --connect connect to given server address on startup\n"
Expand Down
32 changes: 32 additions & 0 deletions src/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,10 @@ if ( rand() < ( RAND_MAX / 2 ) ) return false;
case PROTMESSID_CLM_REGISTER_SERVER_RESP:
EvaluateCLRegisterServerResp ( InetAddr, vecbyMesBodyData );
break;

case PROTMESSID_CLM_REQ_SERVER_STATUS:
EvaluateCLReqServerStatus ( InetAddr );
break;
}
}

Expand Down Expand Up @@ -1716,6 +1720,28 @@ void CProtocol::CreateCLPingWithNumClientsMes ( const CHostAddress& InetAddr, co
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS, vecData, InetAddr );
}

/**
* Send json encoded server status
*/

void CProtocol::CreateCLServerStatusMes ( const CHostAddress& InetAddr, const QString strServerStatus )
{
int iPos = 0; // init position pointer

// convert server info to utf-8
const QByteArray strUTF8ServerStatus = strServerStatus.toUtf8();

const int iEntrLen = 2 + strUTF8ServerStatus.size();

// build data vector
CVector<uint8_t> vecData ( iEntrLen );

// Server status
PutStringUTF8OnStream ( vecData, iPos, strUTF8ServerStatus );

CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_STATUS, vecData, InetAddr );
}

bool CProtocol::EvaluateCLPingWithNumClientsMes ( const CHostAddress& InetAddr, const CVector<uint8_t>& vecData )
{
int iPos = 0; // init position pointer
Expand Down Expand Up @@ -2492,6 +2518,12 @@ bool CProtocol::EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr )
return false; // no error
}

bool CProtocol::EvaluateCLReqServerStatus ( const CHostAddress& InetAddr )
{
emit CLReqServerStatus ( InetAddr );
return false;
}

void CProtocol::CreateCLChannelLevelListMes ( const CHostAddress& InetAddr, const CVector<uint16_t>& vecLevelList, const int iNumClients )
{
// This must be a multiple of bytes at four bits per client
Expand Down
6 changes: 6 additions & 0 deletions src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@
#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_REQ_SERVER_STATUS 1020 // request server status
#define PROTMESSID_CLM_SERVER_STATUS 1021 // server status response

// special IDs
#define PROTMESSID_SPECIAL_SPLIT_MESSAGE 2001 // a container for split messages

Expand Down Expand Up @@ -153,6 +156,7 @@ void CreateReqChannelLevelListMes();
void CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr );
void CreateCLChannelLevelListMes ( const CHostAddress& InetAddr, const CVector<uint16_t>& vecLevelList, const int iNumClients );
void CreateCLRegisterServerResp ( const CHostAddress& InetAddr, const ESvrRegResult eResult );
void CreateCLServerStatusMes ( const CHostAddress& InetAddr, const QString strServerStatus );

static bool ParseMessageFrame ( const CVector<uint8_t>& vecbyData,
const int iNumBytesIn,
Expand Down Expand Up @@ -265,6 +269,7 @@ void CreateReqChannelLevelListMes();
bool EvaluateCLReqVersionAndOSMes ( const CHostAddress& InetAddr );
bool EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr, const CVector<uint8_t>& vecData );
bool EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr );
bool EvaluateCLReqServerStatus ( const CHostAddress& InetAddr );
bool EvaluateCLChannelLevelListMes ( const CHostAddress& InetAddr, const CVector<uint8_t>& vecData );
bool EvaluateCLRegisterServerResp ( const CHostAddress& InetAddr, const CVector<uint8_t>& vecData );

Expand Down Expand Up @@ -331,6 +336,7 @@ public slots:
void CLReqVersionAndOS ( CHostAddress InetAddr );
void CLConnClientsListMesReceived ( CHostAddress InetAddr, CVector<CChannelInfo> vecChanInfo );
void CLReqConnClientsList ( CHostAddress InetAddr );
void CLReqServerStatus ( CHostAddress InetAddr );
void CLChannelLevelListReceived ( CHostAddress InetAddr, CVector<uint16_t> vecLevelList );
void CLRegisterServerResp ( CHostAddress InetAddr, ESvrRegResult eStatus );
};
105 changes: 105 additions & 0 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ CServer::CServer ( const int iNewMaxNumChan,
const quint16 iPortNumber,
const quint16 iQosNumber,
const QString& strHTMLStatusFileName,
const QString& strNotifyServer,
const QString& strCentralServer,
const QString& strServerListFileName,
const QString& strServerInfo,
Expand All @@ -241,6 +242,8 @@ CServer::CServer ( const int iNewMaxNumChan,
iFrameCount ( 0 ),
bWriteStatusHTMLFile ( false ),
strServerHTMLFileListName ( strHTMLStatusFileName ),
bNotifyServer ( false ),
strNotifyServerAddr ( strNotifyServer ),
HighPrecisionTimer ( bNUseDoubleSystemFrameSize ),
ServerListManager ( iPortNumber,
strCentralServer,
Expand Down Expand Up @@ -386,6 +389,25 @@ CServer::CServer ( const int iNewMaxNumChan,
WriteHTMLChannelList();
}

// Notify Server Setup
if ( !strNotifyServerAddr.isEmpty() )
{

// No IPv6 here
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?


if ( NetworkUtil::ParseNetworkAddress ( strNotifyServerAddr, addrNotifyServer, false ) )
{
qInfo() << "-Server notifications sent to:" << addrNotifyServer.toString();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-Server
Missing space.

bNotifyServer = true;
OnCLReqServerStatus ( addrNotifyServer );
}
else
{
qInfo() << "- ** Could not parse notify server **";
bNotifyServer = false; // default is already false - here just for clarity...
}
}

// manage welcome message: if the welcome message is a valid link to a local
// file, the content of that file is used as the welcome message (#361)
SetWelcomeMessage ( strNewWelcomeMessage ); // first use given text, may be overwritten
Expand Down Expand Up @@ -465,6 +487,8 @@ CServer::CServer ( const int iNewMaxNumChan,

QObject::connect ( &ConnLessProtocol, &CProtocol::CLReqConnClientsList, this, &CServer::OnCLReqConnClientsList );

QObject::connect ( &ConnLessProtocol, &CProtocol::CLReqServerStatus, this, &CServer::OnCLReqServerStatus );

QObject::connect ( &ServerListManager, &CServerListManager::SvrRegStatusChanged, this, &CServer::SvrRegStatusChanged );

QObject::connect ( &JamController, &recorder::CJamController::RestartRecorder, this, &CServer::RestartRecorder );
Expand Down Expand Up @@ -562,6 +586,28 @@ void CServer::SendProtMessage ( int iChID, CVector<uint8_t> vecMessage )
Socket.SendPacket ( vecMessage, vecChannels[iChID].GetAddress() );
}

void CServer::OnCLReqServerStatus ( CHostAddress InetAddr )
{
QString strServerStatus;

// If not enabled, bail
if ( !bNotifyServer )
return;

// Only process if the InetAddr is the same as that
// specified in the command line argument.

if ( !( InetAddr == addrNotifyServer ) )
{
qInfo() << "** Denied server status message request from" << InetAddr.toString() << "only allowed to" << addrNotifyServer.toString();
return;
}

BuildServerStatusJson ( strServerStatus );

ConnLessProtocol.CreateCLServerStatusMes ( InetAddr, strServerStatus );
}

void CServer::OnNewConnection ( int iChID, CHostAddress RecHostAddr )
{
QMutexLocker locker ( &Mutex );
Expand Down Expand Up @@ -1403,6 +1449,9 @@ void CServer::CreateAndSendChanListForAllConChannels()
}
}

// Send Server Status to the designated host, if specified.
OnCLReqServerStatus ( addrNotifyServer );

// create status HTML file if enabled
if ( bWriteStatusHTMLFile )
{
Expand Down Expand Up @@ -1457,6 +1506,8 @@ void CServer::CreateAndSendRecorderStateForAllConChannels()
vecChannels[i].CreateRecorderStateMes ( eRecorderState );
}
}

OnCLReqServerStatus ( addrNotifyServer );
}

void CServer::CreateOtherMuteStateChanged ( const int iCurChanID, const int iOtherChanID, const bool bIsMuted )
Expand Down Expand Up @@ -1702,6 +1753,60 @@ void CServer::SetWelcomeMessage ( const QString& strNWelcMess )
strWelcomeMessage = strWelcomeMessage.left ( MAX_LEN_CHAT_TEXT );
}

/**
* Build a server status json string that can be used to either
* write to a disk-based status file, or sent via CL message.
*/

void CServer::BuildServerStatusJson ( QString& strServerStatus )
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the maximum size of this JSON object?

{

CHostAddress InetAddr;
CChannelCoreInfo ci;

ERecorderState eRecorderState = JamController.GetRecorderState();

int ccount = GetNumberOfConnectedClients();

QJsonObject jobject;
QJsonArray jclients;

jobject["cc"] = ccount;
jobject["rs"] = eRecorderState;
jobject["ts"] = QDateTime::currentSecsSinceEpoch();
jobject["svnm"] = ServerListManager.GetServerName();
jobject["svct"] = ServerListManager.GetServerCity();
jobject["svcn"] = ServerListManager.GetServerCountry();

if ( ccount > 0 )
{
// write entry for each connected client
for ( int i = 0; i < iMaxNumChannels; i++ )
{
if ( vecChannels[i].IsConnected() )
{
InetAddr = vecChannels[i].GetAddress();
ci = vecChannels[i].GetChanInfo();

QJsonObject temp;
temp["ip"] = InetAddr.toString();
temp["in"] = ci.iInstrument;
temp["sk"] = ci.eSkillLevel;
temp["cn"] = ci.eCountry;
temp["ct"] = ci.strCity;
temp["nm"] = vecChannels[i].GetName();

jclients.push_back ( QJsonValue ( temp ) );
}
}
}

jobject["cl"] = jclients;

QJsonDocument jdoc ( jobject );
strServerStatus = jdoc.toJson ( QJsonDocument::Compact );
}

void CServer::WriteHTMLChannelList()
{
// prepare file and stream
Expand Down
15 changes: 15 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
#include <QHostAddress>
#include <QFileInfo>
#include <QtConcurrent>

#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>

#include <algorithm>
#ifdef USE_OPUS_SHARED_LIB
# include "opus/opus_custom.h"
Expand Down Expand Up @@ -158,6 +163,7 @@ class CServer : public QObject, public CServerSlots<MAX_NUM_CHANNELS>
const quint16 iPortNumber,
const quint16 iQosNumber,
const QString& strHTMLStatusFileName,
const QString& strNotifyServer,
const QString& strCentralServer,
const QString& strServerListFileName,
const QString& strServerInfo,
Expand Down Expand Up @@ -291,6 +297,8 @@ class CServer : public QObject, public CServerSlots<MAX_NUM_CHANNELS>

virtual void customEvent ( QEvent* pEvent );

void BuildServerStatusJson ( QString& strServerStatus );

// if server mode is normal or double system frame size
bool bUseDoubleSystemFrameSize;
int iServerFrameSizeSamples;
Expand Down Expand Up @@ -364,6 +372,11 @@ class CServer : public QObject, public CServerSlots<MAX_NUM_CHANNELS>
bool bWriteStatusHTMLFile;
QString strServerHTMLFileListName;

// Notify Server
bool bNotifyServer;
CHostAddress addrNotifyServer;
QString strNotifyServerAddr;

CHighPrecisionTimer HighPrecisionTimer;

// server list
Expand Down Expand Up @@ -446,6 +459,8 @@ public slots:

void OnCLReqConnClientsList ( CHostAddress InetAddr ) { ConnLessProtocol.CreateCLConnClientsListMes ( InetAddr, CreateChannelList() ); }

void OnCLReqServerStatus ( CHostAddress InetAddr );

void OnCLRegisterServerReceived ( CHostAddress InetAddr, CHostAddress LInetAddr, CServerCoreInfo ServerInfo )
{
ServerListManager.CentralServerRegisterServer ( InetAddr, LInetAddr, ServerInfo );
Expand Down
1 change: 1 addition & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ CAboutDlg::CAboutDlg ( QWidget* parent ) : CBaseDlg ( parent )
"<p>Dau Huy Ngoc (<a href=\"https://github.com/ngocdh\">ngocdh</a>)</p>"
"<p>Jiri Popek (<a href=\"https://github.com/jardous\">jardous</a>)</p>"
"<p>Gary Wang (<a href=\"https://github.com/BLumia\">BLumia</a>)</p>"
"<p>Rob-NY (<a href=\"https://github.com/Rob-NY\">Rob-NY</a>)</p>"
"<br>" +
tr ( "For details on the contributions check out the " ) +
"<a href=\"https://github.com/jamulussoftware/jamulus/graphs/contributors\">" + tr ( "Github Contributors list" ) +
Expand Down