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
136 MAX_HOSTCACHE = 100, // max. amount of hosts in cache
137 MIN_HOSTS = 3, // min. amount of hosts that should be kept in cache
139 MAX_OUTGOING = 3, // max. number of outgoing servents to use
140 MAX_INCOMING = 6, // max. number of public incoming servents to use
141 MAX_TRYOUT = 10, // max. number of outgoing servents to try connect
142 MIN_CONNECTED = 3, // min. amount of connected hosts that should be kept
150 MAX_PREVIEWTIME = 300, // max. seconds preview per channel available (direct connections)
151 MAX_PREVIEWWAIT = 300, // max. seconds wait between previews
167 Servent *findServent(unsigned int,unsigned short,GnuID &);
168 Servent *findServent(Servent::TYPE);
169 Servent *findServent(Servent::TYPE,Host &,GnuID &);
170 Servent *findOldestServent(Servent::TYPE,bool);
171 Servent *findServentByIndex(int);
172 Servent *findServentByServentID(int);
174 bool writeVariable(Stream &, const String &);
175 Servent *allocServent();
176 unsigned int numUsed(int);
177 unsigned int numStreams(GnuID &, Servent::TYPE,bool);
178 unsigned int numStreams(Servent::TYPE,bool);
179 unsigned int numConnected(int,bool,unsigned int);
180 unsigned int numConnected(int t,int tim = 0)
182 return numConnected(t,false,tim)+numConnected(t,true,tim);
184 unsigned int numConnected();
185 unsigned int numServents();
187 unsigned int totalConnected()
189 //return numConnected(Servent::T_OUTGOING) + numConnected(Servent::T_INCOMING);
190 return numConnected();
192 unsigned int numOutgoing();
193 bool isFiltered(int,Host &h);
194 bool addOutgoing(Host,GnuID &,bool);
195 Servent *findConnection(Servent::TYPE,GnuID &);
198 static THREAD_PROC serverProc(ThreadInfo *);
199 static THREAD_PROC clientProc(ThreadInfo *);
200 static THREAD_PROC trackerProc(ThreadInfo *);
201 static THREAD_PROC idleProc(ThreadInfo *);
203 int broadcast(GnuPacket &,Servent * = NULL);
204 int route(GnuPacket &, GnuID &, Servent * = NULL);
206 XML::Node *createServentXML();
208 void connectBroadcaster();
209 void procConnectArgs(char *,ChanInfo &);
212 void closeConnections(Servent::TYPE);
214 void checkFirewall();
217 void addHost(Host &,ServHost::TYPE,unsigned int);
218 int getNewestServents(Host *,int, Host &);
219 ServHost getOutgoingServent(GnuID &);
220 void deadHost(Host &,ServHost::TYPE);
221 unsigned int numHosts(ServHost::TYPE);
222 void clearHostCache(ServHost::TYPE);
223 bool seenHost(Host &,ServHost::TYPE,unsigned int);
225 void setMaxRelays(int);
226 void setFirewall(FW_STATE);
228 FW_STATE getFirewall() {return firewalled;}
229 void saveSettings(const char *);
230 void loadSettings(const char *);
231 void setPassiveSearch(unsigned int);
232 int findChannel(ChanInfo &);
233 bool getChannel(char *,ChanInfo &,bool);
234 void setFilterDefaults();
236 bool acceptGIV(ClientSocket *);
237 void addVersion(unsigned int);
239 void broadcastRootSettings(bool);
240 int broadcastPushRequest(ChanHit &, Host &, GnuID &, Servent::TYPE);
241 void writeRootAtoms(AtomStream &,bool);
243 int broadcastPacket(ChanPacket &,GnuID &,GnuID &,GnuID &,Servent::TYPE type);
245 void addValidBCID(BCID *);
246 void removeValidBCID(GnuID &);
247 BCID *findValidBCID(GnuID &);
248 BCID *findValidBCID(int);
250 unsigned int getUptime()
252 return sys->getTime()-startTime;
255 bool seenPacket(GnuPacket &);
261 //return numHosts(ServHost::T_SERVENT) < maxTryout;
264 unsigned int numActiveOnPort(int);
265 unsigned int numActive(Servent::TYPE);
267 bool needConnections()
269 return numConnected(Servent::T_PGNU,60) < minGnuIncoming;
274 //return maxTryout ? numUsed(Servent::T_OUTGOING) > maxTryout: false;
279 return numConnected(Servent::T_PGNU) > maxGnuIncoming;
280 // return maxIncoming ? numConnected(Servent::T_INCOMING,false) > maxIncoming : false;
284 return numConnected(Servent::T_PGNU) >= maxGnuIncoming;
285 // return maxIncoming ? numConnected(Servent::T_INCOMING,false) >= maxIncoming : false;
291 // return maxOutgoing ? numUsed(Servent::T_OUTGOING) >= maxOutgoing: false;
296 // return maxOutgoing ? numConnected(Servent::T_OUTGOING) > maxOutgoing : false;
301 return numConnected(Servent::T_CIN)>=maxControl;
307 // return maxOutgoing ? numConnected(Servent::T_OUTGOING) >= maxOutgoing : false;
312 return numStreams(Servent::T_RELAY,false) >= maxRelays;
316 return numStreams(Servent::T_DIRECT,false) >= maxDirect;
319 bool bitrateFull(unsigned int br)
321 return maxBitrateOut ? (BYTES_TO_KBPS(totalOutput(false))+br) > maxBitrateOut : false;
324 unsigned int totalOutput(bool);
325 unsigned int totalInput(bool);
327 static ThreadInfo serverThread,idleThread;
333 ServHost hostCache[MAX_HOSTCACHE];
339 unsigned int maxBitrateOut,maxControl,maxRelays,maxDirect;
340 unsigned int minGnuIncoming,maxGnuIncoming;
341 unsigned int maxServIn;
351 char downloadURL[128];
354 char connectHost[128];
356 unsigned int firewallTimeout;
362 unsigned int lastIncoming;
366 bool autoConnect,autoServe,forceLookup;
369 unsigned int allowServer1,allowServer2;
370 unsigned int startTime;
371 unsigned int tryoutDelay;
372 unsigned int refreshHTML;
373 unsigned int relayBroadcast;
375 unsigned int notifyMask;
380 ServFilter filters[MAX_FILTERS];
384 CookieList cookieList;
388 unsigned int clientVersions[MAX_VERSIONS],clientCounts[MAX_VERSIONS];
394 char modulePath[256]; //JP-EX
395 int enableGetName; //JP-EX
396 int allowConnectPCST; //JP-EX
397 int autoRelayKeep; //JP-EX
398 unsigned int autoMaxRelaySetting; //JP-EX
399 unsigned int autoBumpSkipCount;//JP-EX
400 unsigned int kickPushStartRelays; //JP-EX
401 unsigned int kickPushInterval; //JP-EX
402 unsigned int kickPushTime;
403 bool isCheckPushStream(); //JP-EX
404 void banFirewalledHost(); //JP-EX
405 int kickUnrelayableHost(GnuID &, ChanHit &);
407 bool getModulePath; //JP-EX
408 bool clearPLS; //JP-EX
409 bool writeLogFile; //JP-EX
413 unsigned int kickKeepTime;
417 bool keepDownstreams;
419 bool topmostGui; //
\8dÅ
\91O
\96Ê
420 bool startWithGui; //
\8bN
\93®
\8e\9e\82ÉGUI
422 int maxRelaysIndexTxt; // for PCRaw (relay)
428 // ----------------------------------
429 extern ServMgr *servMgr;