From e5d868fe2098f10f1cc31c3ddd763093678cb38f Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Wed, 23 Mar 2011 20:09:51 +0000 Subject: [PATCH] initial work for server list implementation --- llcon.pro | 60 ++++++++-------- src/protocol.h | 18 ++++- src/serverlist.cpp | 26 +++++++ src/serverlist.h | 165 +++++++++++++++++++++++++++++++++++++++++++ src/socket.cpp | 4 +- windows/llcon.vcproj | 8 +++ 6 files changed, 249 insertions(+), 32 deletions(-) create mode 100755 src/serverlist.cpp create mode 100755 src/serverlist.h diff --git a/llcon.pro b/llcon.pro index 026b7d5c..8290eaf6 100755 --- a/llcon.pro +++ b/llcon.pro @@ -48,25 +48,26 @@ FORMS += src/llconclientdlgbase.ui \ src/chatdlgbase.ui \ src/aboutdlgbase.ui -HEADERS += src/buffer.h \ - src/global.h \ - src/socket.h \ +HEADERS += src/audiomixerboard.h \ + src/buffer.h \ src/channel.h \ - src/util.h \ + src/chatdlg.h \ src/client.h \ - src/server.h \ - src/settings.h \ - src/protocol.h \ + src/clientsettingsdlg.h \ + src/global.h \ + src/llconclientdlg.h \ + src/llconserverdlg.h \ src/multicolorled.h \ src/multicolorledbar.h \ - src/audiomixerboard.h \ + src/protocol.h \ + src/server.h \ + src/serverlist.h \ src/serverlogging.h \ - src/testbench.h \ + src/settings.h \ + src/socket.h \ src/soundbase.h \ - src/llconserverdlg.h \ - src/chatdlg.h \ - src/llconclientdlg.h \ - src/clientsettingsdlg.h \ + src/testbench.h \ + src/util.h \ libs/celt/celt.h \ libs/celt/celt_types.h \ libs/celt/celt_header.h \ @@ -99,24 +100,25 @@ HEADERS += src/buffer.h \ libs/celt/stack_alloc.h \ libs/celt/vq.h -SOURCES += src/buffer.cpp \ - src/main.cpp \ - src/socket.cpp \ +SOURCES += src/audiomixerboard.cpp \ + src/buffer.cpp \ src/channel.cpp \ - src/util.cpp \ - src/llconclientdlg.cpp \ - src/clientsettingsdlg.cpp \ - src/llconserverdlg.cpp \ src/chatdlg.cpp \ src/client.cpp \ - src/server.cpp \ - src/settings.cpp \ - src/protocol.cpp \ + src/clientsettingsdlg.cpp \ + src/llconclientdlg.cpp \ + src/llconserverdlg.cpp \ + src/main.cpp \ src/multicolorled.cpp \ src/multicolorledbar.cpp \ - src/audiomixerboard.cpp \ + src/protocol.cpp \ + src/server.cpp \ + src/serverlist.cpp \ src/serverlogging.cpp \ + src/settings.cpp \ + src/socket.cpp \ src/soundbase.cpp \ + src/util.cpp \ libs/celt/bands.c \ libs/celt/celt.c \ libs/celt/cwrs.c \ @@ -139,12 +141,12 @@ SOURCES += src/buffer.cpp \ libs/celt/vq.c DISTFILES += AUTHORS \ - COPYING \ - NEWS \ - TODO \ - README \ - INSTALL \ ChangeLog \ + COPYING \ + INSTALL \ + NEWS \ + README \ + TODO \ libs\celt\AUTHORS \ libs\celt\ChangeLog \ libs\celt\COPYING \ diff --git a/src/protocol.h b/src/protocol.h index 52b1676c..f9468e55 100755 --- a/src/protocol.h +++ b/src/protocol.h @@ -43,7 +43,7 @@ #define PROTMESSID_NET_BLSI_FACTOR 12 // OLD (not used anymore) #define PROTMESSID_CHANNEL_GAIN 13 // set channel gain for mix #define PROTMESSID_CONN_CLIENTS_LIST 14 // connected client list -#define PROTMESSID_SERVER_FULL 15 // server full message +#define PROTMESSID_SERVER_FULL 15 // OLD (not used anymore) #define PROTMESSID_REQ_CONN_CLIENTS_LIST 16 // request connected client list #define PROTMESSID_CHANNEL_NAME 17 // set channel name for fader tag #define PROTMESSID_CHAT_TEXT 18 // contains a chat text @@ -53,6 +53,22 @@ #define PROTMESSID_DISCONNECTION 22 // disconnection #define PROTMESSID_REQ_CHANNEL_NAME 23 // request channel name for fader tag +// message IDs of connection less messages (CLM) -> start at 1000 + +// TODO implementation of the messages... + +#define PROTMESSID_CLM_PING_MS 1001 // for measuring ping time +#define PROTMESSID_CLM_SERVER_FULL 1002 // server full message +#define PROTMESSID_CLM_SERVER_LIST 1003 // server list +#define PROTMESSID_CLM_REQ_SERVER_LIST 1004 // request server list +#define PROTMESSID_CLM_SEND_EMPTY_MESSAGE 1005 // an empty message shall be send +#define PROTMESSID_CLM_EMPTY_MESSAGE 1006 // empty message +#define PROTMESSID_CLM_REGISTER_SERVER 1007 // register server +#define PROTMESSID_CLM_UNREGISTER_SERVER 1008 // unregister server + + + + // lengths of message as defined in protocol.cpp file #define MESS_HEADER_LENGTH_BYTE 7 // TAG (2), ID (2), cnt (1), length (2) #define MESS_LEN_WITHOUT_DATA_BYTE ( MESS_HEADER_LENGTH_BYTE + 2 /* CRC (2) */ ) diff --git a/src/serverlist.cpp b/src/serverlist.cpp new file mode 100755 index 00000000..cf126d94 --- /dev/null +++ b/src/serverlist.cpp @@ -0,0 +1,26 @@ +/******************************************************************************\ + * Copyright (c) 2004-2011 + * + * Author(s): + * Volker Fischer + * + ****************************************************************************** + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 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 General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * +\******************************************************************************/ + +#include "serverlist.h" + diff --git a/src/serverlist.h b/src/serverlist.h new file mode 100755 index 00000000..bacf99b1 --- /dev/null +++ b/src/serverlist.h @@ -0,0 +1,165 @@ +/******************************************************************************\ + * Copyright (c) 2004-2011 + * + * Author(s): + * Volker Fischer + * + ****************************************************************************** + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 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 General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * +\******************************************************************************/ + +#if !defined ( SERVERLIST_HOIJH8OUWEF_WFEIOBU_3_43445KJIUHF1912__INCLUDED_ ) +#define SERVERLIST_HOIJH8OUWEF_WFEIOBU_3_43445KJIUHF1912__INCLUDED_ + +#include +#include +#include "global.h" + + +/* +MAIN POINTS: + +- Currently, if you want to run a private server, you have to open the + firewall of your computer at the correct ports and introduce a port + forwarding at your router to get it work. Using a central server would + simplify the process. The user who wants to run a llcon server just + registers his server a the central server and a mechanism implemented + in the protocol opens the firewall similar to STUN. + +- Having private llcon servers will increase the probability that a server + is in the required minimum range of 1000 km of the clients position. + +- The problem is that private servers are not reliable, they can be turned + off at any time. + +- The private server owner maybe only wants to enable his friends to use + the server but if it is registered at the central server, everybody sees + the new server. Maybe an authentication mechanism might be implemented for + this purpose. + +REQUIREMENTS: + +- The client sets the URL of the central llcon server and can get a list of + all currently activated and registered private llcon servers. If the user + clicks on the server of his choice, he gets connected to this server. + +- The server list must be available in both cases: if the client is connected + to the central server or not. + +- The server list contains the name of the server, an optional topic, an + optional location, the number of connected users and a ping time which is + updated as long as the server list is visible (similar to the ping measurement + in the general settings dialog). Additional information may be also present + in the list like reliability of the server, etc. + +- If a user starts the server for the first time, he gets automatically asked + if he wants to register his server at the central server. His choice will be + stored in an ini-file. + +CONNECTION PROCESS: + +* The private server contacts the central server and registers through some + protocol mechanism. + +* If a client requests the server list from the central server, the central + server sends the IP address of the client to each registered private servers + so that they can immediately send a "firewall opening" UDP packet to this IP + address. If the client now sends ping messages to each of the private servers + in the list, the firewalls and routers are prepared for receiving UDP packets + from this IP address and will tunnel it through. Note: this mechanism will not + work in a private network. + +* The central server polls all registered private servers in regular intervals + to make sure they are still present. If a private server is shut down, it + sends a shutdown message to the central server. + +CONSEQUENCES: + +- A new connection type is required: connection without transferring audio data, + just protocol. + +- It must be possible to maintain the regular and new connection at the same + time. + +- It has to be checked for how long a firewall is opened after the "firewall + opening" UDP packet was send. Maybe this message has to be repeated in regular + intervals (but not too long since maybe the client does not even want to connect + to this particular private server). +*/ + +/* Classes ********************************************************************/ +class CServerListProperties +{ +public: + CServerListProperties() : + strName ( "" ), + strTopic ( "" ), + eCountry ( QLocale::AnyCountry ), + strCity ( "" ), + iNumClients ( 0 ), + iMaxNumClients ( 0 ), + bPermanentOnline ( false ) {} + + virtual ~CServerListProperties() {} + +protected: + // name of the server + QString strName; + + // topic of the current jam session or server + QString strTopic; + + // country in which the server is located + QLocale::Country eCountry; + + // city in which the server is located + QString strCity; + + // current number of connected clients + int iNumClients; + + // maximum number of clients which can connect to the server at the same + // time + int iMaxNumClients; + + // is the server permanently online or not (flag) + bool bPermanentOnline; +}; + + +class CServerList : public QList +{ +public: + CServerList() {} + virtual ~CServerList() {} + +protected: + +}; + + +class CServerListManager +{ +public: + CServerListManager() {} + virtual ~CServerListManager() {} + +protected: + +}; + +#endif /* !defined ( SERVERLIST_HOIJH8OUWEF_WFEIOBU_3_43445KJIUHF1912__INCLUDED_ ) */ diff --git a/src/socket.cpp b/src/socket.cpp index 99430fe1..a91601e7 100755 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -99,7 +99,7 @@ void CSocket::OnDataReceived() if ( bIsClient ) { - // client + // client: // check if packet comes from the server we want to connect if ( !( pChannel->GetAddress() == RecHostAddr ) ) { @@ -124,7 +124,7 @@ void CSocket::OnDataReceived() } else { - // server + // server: if ( pServer->PutData ( vecbyRecBuf, iNumBytesRead, RecHostAddr ) ) { // this was an audio packet, start server diff --git a/windows/llcon.vcproj b/windows/llcon.vcproj index 4c52b687..b73dcafd 100755 --- a/windows/llcon.vcproj +++ b/windows/llcon.vcproj @@ -666,6 +666,10 @@ /> + + @@ -1510,6 +1514,10 @@ RelativePath="..\src\server.h" > + +