1 // ------------------------------------------------
7 // (c) 2002 peercast.org
8 // ------------------------------------------------
9 // This program is free software; you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation; either version 2 of the License, or
12 // (at your option) any later version.
14 // This program is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 // ------------------------------------------------
25 // ----------------------------------
27 const int MIN_YP_RETRY = 20;
28 const int MIN_TRACKER_RETRY = 10;
29 const int MIN_RELAY_RETRY = 5;
31 // ----------------------------------
39 bool writeVariable(Stream &, const String &);
42 String name,email,url;
48 // ----------------------------------
68 void init(Host &h, TYPE tp, unsigned int tim)
76 time = sys->getTime();
79 static const char *getTypeStr(TYPE);
80 static TYPE getTypeFromStr(const char *);
86 // ----------------------------------
98 ServFilter() {init();}
105 bool writeVariable(Stream &, const String &);
111 // ----------------------------------
112 // ServMgr keeps track of Servents
123 NT_PEERCAST = 0x0002,
124 NT_BROADCASTERS = 0x0004,
125 NT_TRACKINFO = 0x0008,
126 NT_APPLAUSE = 0x0010 //JP-MOD
137 MAX_HOSTCACHE = 100, // max. amount of hosts in cache
138 MIN_HOSTS = 3, // min. amount of hosts that should be kept in cache
140 MAX_OUTGOING = 3, // max. number of outgoing servents to use
141 MAX_INCOMING = 6, // max. number of public incoming servents to use
142 MAX_TRYOUT = 10, // max. number of outgoing servents to try connect
143 MIN_CONNECTED = 3, // min. amount of connected hosts that should be kept
151 MAX_PREVIEWTIME = 300, // max. seconds preview per channel available (direct connections)
152 MAX_PREVIEWWAIT = 300, // max. seconds wait between previews
168 Servent *findServent(unsigned int,unsigned short,GnuID &);
169 Servent *findServent(Servent::TYPE);
170 Servent *findServent(Servent::TYPE,Host &,GnuID &);
171 Servent *findOldestServent(Servent::TYPE,bool);
172 Servent *findServentByIndex(int);
173 Servent *findServentByServentID(int);
175 bool writeVariable(Stream &, const String &);
176 Servent *allocServent();
177 unsigned int numUsed(int);
178 unsigned int numStreams(GnuID &, Servent::TYPE,bool);
179 unsigned int numStreams(Servent::TYPE,bool);
180 unsigned int numConnected(int,bool,unsigned int);
181 unsigned int numConnected(int t,int tim = 0)
183 return numConnected(t,false,tim)+numConnected(t,true,tim);
185 unsigned int numConnected();
186 unsigned int numServents();
188 unsigned int totalConnected()
190 //return numConnected(Servent::T_OUTGOING) + numConnected(Servent::T_INCOMING);
191 return numConnected();
193 unsigned int numOutgoing();
194 bool isFiltered(int,Host &h);
195 bool addOutgoing(Host,GnuID &,bool);
196 Servent *findConnection(Servent::TYPE,GnuID &);
199 static THREAD_PROC serverProc(ThreadInfo *);
200 static THREAD_PROC clientProc(ThreadInfo *);
201 static THREAD_PROC trackerProc(ThreadInfo *);
202 static THREAD_PROC idleProc(ThreadInfo *);
204 int broadcast(GnuPacket &,Servent * = NULL);
205 int route(GnuPacket &, GnuID &, Servent * = NULL);
207 XML::Node *createServentXML();
209 void connectBroadcaster();
210 void procConnectArgs(char *,ChanInfo &);
213 void closeConnections(Servent::TYPE);
215 void checkFirewall();
218 void addHost(Host &,ServHost::TYPE,unsigned int);
219 int getNewestServents(Host *,int, Host &);
220 ServHost getOutgoingServent(GnuID &);
221 void deadHost(Host &,ServHost::TYPE);
222 unsigned int numHosts(ServHost::TYPE);
223 void clearHostCache(ServHost::TYPE);
224 bool seenHost(Host &,ServHost::TYPE,unsigned int);
226 void setMaxRelays(int);
227 void setFirewall(FW_STATE);
229 FW_STATE getFirewall() {return firewalled;}
230 void saveSettings(const char *);
231 void loadSettings(const char *);
232 void setPassiveSearch(unsigned int);
233 int findChannel(ChanInfo &);
234 bool getChannel(char *,ChanInfo &,bool);
235 void setFilterDefaults();
237 bool acceptGIV(ClientSocket *);
238 void addVersion(unsigned int);
240 void broadcastRootSettings(bool);
241 int broadcastPushRequest(ChanHit &, Host &, GnuID &, Servent::TYPE);
242 void writeRootAtoms(AtomStream &,bool);
244 int broadcastPacket(ChanPacket &,GnuID &,GnuID &,GnuID &,Servent::TYPE type);
246 void addValidBCID(BCID *);
247 void removeValidBCID(GnuID &);
248 BCID *findValidBCID(GnuID &);
249 BCID *findValidBCID(int);
251 unsigned int getUptime()
253 return sys->getTime()-startTime;
256 bool seenPacket(GnuPacket &);
262 //return numHosts(ServHost::T_SERVENT) < maxTryout;
265 unsigned int numActiveOnPort(int);
266 unsigned int numActive(Servent::TYPE);
268 bool needConnections()
270 return numConnected(Servent::T_PGNU,60) < minGnuIncoming;
275 //return maxTryout ? numUsed(Servent::T_OUTGOING) > maxTryout: false;
280 return numConnected(Servent::T_PGNU) > maxGnuIncoming;
281 // return maxIncoming ? numConnected(Servent::T_INCOMING,false) > maxIncoming : false;
285 return numConnected(Servent::T_PGNU) >= maxGnuIncoming;
286 // return maxIncoming ? numConnected(Servent::T_INCOMING,false) >= maxIncoming : false;
292 // return maxOutgoing ? numUsed(Servent::T_OUTGOING) >= maxOutgoing: false;
297 // return maxOutgoing ? numConnected(Servent::T_OUTGOING) > maxOutgoing : false;
302 return numConnected(Servent::T_CIN)>=maxControl;
308 // return maxOutgoing ? numConnected(Servent::T_OUTGOING) >= maxOutgoing : false;
313 return numStreams(Servent::T_RELAY,false) >= maxRelays;
317 return numStreams(Servent::T_DIRECT,false) >= maxDirect;
320 bool bitrateFull(unsigned int br)
322 return maxBitrateOut ? (BYTES_TO_KBPS(totalOutput(false))+br) > maxBitrateOut : false;
325 unsigned int totalOutput(bool);
326 unsigned int totalInput(bool);
328 static ThreadInfo serverThread,idleThread;
334 ServHost hostCache[MAX_HOSTCACHE];
340 unsigned int maxBitrateOut,maxControl,maxRelays,maxDirect;
341 unsigned int minGnuIncoming,maxGnuIncoming;
342 unsigned int maxServIn;
352 char downloadURL[128];
355 char connectHost[128];
357 unsigned int firewallTimeout;
363 unsigned int lastIncoming;
367 bool autoConnect,autoServe,forceLookup;
370 unsigned int allowServer1,allowServer2;
371 unsigned int startTime;
372 unsigned int tryoutDelay;
373 unsigned int refreshHTML;
374 unsigned int relayBroadcast;
376 unsigned int notifyMask;
381 ServFilter filters[MAX_FILTERS];
385 CookieList cookieList;
389 unsigned int clientVersions[MAX_VERSIONS],clientCounts[MAX_VERSIONS];
395 char modulePath[256]; //JP-EX
396 int enableGetName; //JP-EX
397 int allowConnectPCST; //JP-EX
398 int autoRelayKeep; //JP-EX
399 unsigned int autoMaxRelaySetting; //JP-EX
400 unsigned int autoBumpSkipCount;//JP-EX
401 unsigned int kickPushStartRelays; //JP-EX
402 unsigned int kickPushInterval; //JP-EX
403 unsigned int kickPushTime;
404 bool isCheckPushStream(); //JP-EX
405 void banFirewalledHost(); //JP-EX
406 int kickUnrelayableHost(GnuID &, ChanHit &);
408 bool getModulePath; //JP-EX
409 bool clearPLS; //JP-EX
410 bool writeLogFile; //JP-EX
414 unsigned int kickKeepTime;
418 bool keepDownstreams;
420 bool topmostGui; //
\8dÅ
\91O
\96Ê
421 bool startWithGui; //
\8bN
\93®
\8e\9e\82ÉGUI
422 bool preventSS; //
\83X
\83N
\83\8a\81[
\83\93\83Z
\81[
\83o
\81[
\82ð
\97}
\8e~
423 bool noVersionCheck; // bcstAtom
\82É
\82æ
\82é
\83o
\81[
\83W
\83\87\83\93\83`
\83F
\83b
\83N
\82ð
\8ds
\82í
\82È
\82¢
425 int versionDNS; // DNS
\82©
\82ç
\8eæ
\93¾
\82µ
\82½
\8dÅ
\90V
\83o
\81[
\83W
\83\87\83\93\82Ì
\94Ô
\8d\86
427 int maxRelaysIndexTxt; // for PCRaw (relay)
429 #ifdef WIN32 //JP-MOD
430 bool guiSimpleChannelList;
431 bool guiSimpleConnectionList;
434 int guiChanListDisplays;
435 int guiConnListDisplays;
437 String guiTitleModifyNormal;
438 String guiTitleModifyMinimized;
440 bool guiAntennaNotifyIcon;
443 String ppClapSoundPath;
446 int disableAutoBumpIfDirect;
449 enum PPBCSTFLAG //JP-MOD
451 bcstNone = 0x00000000,
452 bcstClap = 0x00000001
455 // PCP broadcast flood
457 time_t lastPCPBcstTime;
463 // ----------------------------------
464 extern ServMgr *servMgr;