OSDN Git Service

WebGUIのレスポンスが悪かったのを修正
[peercast-im/PeerCastIM.git] / c: / Git / PeerCast.root / PeerCast / core / common / servmgr.h
1 // ------------------------------------------------
2 // File : servmgr.h
3 // Date: 4-apr-2002
4 // Author: giles
5 // Desc: 
6 //
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.
13
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 // ------------------------------------------------
19
20 #ifndef _SERVMGR_H
21 #define _SERVMGR_H
22
23 #include "servent.h"
24
25 // ----------------------------------
26
27 const int MIN_YP_RETRY = 20;
28 const int MIN_TRACKER_RETRY = 10;
29 const int MIN_RELAY_RETRY = 5;
30
31 // ----------------------------------
32 class BCID
33 {
34 public:
35         BCID()
36         :next(0),valid(true)
37         {}
38
39         bool    writeVariable(Stream &, const String &);
40
41         GnuID   id;
42         String  name,email,url;
43         bool    valid;
44         BCID    *next;
45 };
46
47
48 // ----------------------------------
49 class ServHost
50 {
51 public:
52         enum TYPE
53         {
54                 T_NONE,
55                 T_STREAM,
56                 T_CHANNEL,
57                 T_SERVENT,
58                 T_TRACKER
59         };
60
61         ServHost() {init();}
62         void init()
63         {
64                 host.init();
65                 time = 0;
66                 type = T_NONE;
67         }
68         void init(Host &h, TYPE tp, unsigned int tim)
69         {
70                 init();
71                 host = h;
72                 type = tp;
73                 if (tim)
74                         time = tim;
75                 else
76                         time = sys->getTime();
77         }
78
79         static const char *getTypeStr(TYPE);
80         static TYPE getTypeFromStr(const char *);
81
82         TYPE type;
83         Host host;
84         unsigned int time;
85 };
86 // ----------------------------------
87 class ServFilter 
88 {
89 public:
90         enum 
91         {
92                 F_PRIVATE  = 0x01,
93                 F_BAN      = 0x02,
94                 F_NETWORK  = 0x04,
95                 F_DIRECT   = 0x08
96         };
97
98         ServFilter() {init();}
99         void    init()
100         {
101                 flags = 0;
102                 host.init();
103         }
104
105         bool    writeVariable(Stream &, const String &);
106
107         Host host;
108         unsigned int flags;
109 };
110
111 // ----------------------------------
112 // ServMgr keeps track of Servents
113 class ServMgr
114 {
115
116
117
118 public:
119
120         enum NOTIFY_TYPE
121         {
122                 NT_UPGRADE                      = 0x0001,
123                 NT_PEERCAST                     = 0x0002,
124                 NT_BROADCASTERS         = 0x0004,
125                 NT_TRACKINFO            = 0x0008,
126                 NT_APPLAUSE                     = 0x0010 //JP-MOD
127         };
128
129         enum FW_STATE
130         {
131                 FW_OFF,
132                 FW_ON,
133                 FW_UNKNOWN
134         };
135         enum {
136
137                 MAX_HOSTCACHE = 100,            // max. amount of hosts in cache
138                 MIN_HOSTS       = 3,                    // min. amount of hosts that should be kept in cache
139
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
144
145                 MIN_RELAYS = 1,
146
147                 MAX_FILTERS = 50,
148
149                 MAX_VERSIONS = 16,
150
151                 MAX_PREVIEWTIME = 300,          // max. seconds preview per channel available (direct connections)
152                 MAX_PREVIEWWAIT = 300,          // max. seconds wait between previews 
153
154         };
155
156         enum AUTH_TYPE
157         {
158                 AUTH_COOKIE,
159                 AUTH_HTTPBASIC
160         };
161
162         
163
164         ServMgr();
165
166         bool    start();
167
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);
174
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)
182         {
183                 return numConnected(t,false,tim)+numConnected(t,true,tim);
184         }
185         unsigned int            numConnected();
186         unsigned int            numServents();
187
188         unsigned int            totalConnected()
189         {
190                 //return numConnected(Servent::T_OUTGOING) + numConnected(Servent::T_INCOMING);
191                 return numConnected();
192         }
193         unsigned int            numOutgoing();
194         bool    isFiltered(int,Host &h);
195         bool    addOutgoing(Host,GnuID &,bool);
196         Servent *findConnection(Servent::TYPE,GnuID &);
197
198
199         static  THREAD_PROC             serverProc(ThreadInfo *);
200         static  THREAD_PROC             clientProc(ThreadInfo *);
201         static  THREAD_PROC             trackerProc(ThreadInfo *);
202         static  THREAD_PROC             idleProc(ThreadInfo *);
203
204         int             broadcast(GnuPacket &,Servent * = NULL);
205         int             route(GnuPacket &, GnuID &, Servent * = NULL);
206
207         XML::Node *createServentXML();
208
209         void            connectBroadcaster();
210         void            procConnectArgs(char *,ChanInfo &);
211
212         void            quit();
213         void            closeConnections(Servent::TYPE);
214
215         void            checkFirewall();
216
217         // host cache
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);
225
226         void    setMaxRelays(int);
227         void    setFirewall(FW_STATE);
228         bool    checkForceIP();
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();
236
237         bool    acceptGIV(ClientSocket *);
238         void    addVersion(unsigned int);
239
240         void broadcastRootSettings(bool);
241         int broadcastPushRequest(ChanHit &, Host &, GnuID &, Servent::TYPE);
242         void writeRootAtoms(AtomStream &,bool);
243
244         int     broadcastPacket(ChanPacket &,GnuID &,GnuID &,GnuID &,Servent::TYPE type);
245
246         void    addValidBCID(BCID *);
247         void    removeValidBCID(GnuID &);
248         BCID    *findValidBCID(GnuID &);
249         BCID    *findValidBCID(int);
250
251         unsigned int getUptime()
252         {
253                 return sys->getTime()-startTime;
254         }
255
256         bool    seenPacket(GnuPacket &);
257
258
259         bool    needHosts()
260         {
261                 return false;
262                 //return numHosts(ServHost::T_SERVENT) < maxTryout;
263         }
264
265         unsigned int            numActiveOnPort(int);
266         unsigned int            numActive(Servent::TYPE);
267
268         bool    needConnections() 
269         {
270                 return numConnected(Servent::T_PGNU,60) < minGnuIncoming;
271         }
272         bool    tryFull() 
273         {
274                 return false;
275                 //return maxTryout ? numUsed(Servent::T_OUTGOING) > maxTryout: false;
276         }
277
278         bool    pubInOver() 
279         {
280                 return numConnected(Servent::T_PGNU) > maxGnuIncoming;
281 //              return maxIncoming ? numConnected(Servent::T_INCOMING,false) > maxIncoming : false;
282         }
283         bool    pubInFull() 
284         {
285                 return numConnected(Servent::T_PGNU) >= maxGnuIncoming;
286 //              return maxIncoming ? numConnected(Servent::T_INCOMING,false) >= maxIncoming : false;
287         }
288
289         bool    outUsedFull() 
290         {
291                 return false;
292 //              return maxOutgoing ? numUsed(Servent::T_OUTGOING) >= maxOutgoing: false;
293         }
294         bool    outOver() 
295         {
296                 return false;
297 //              return maxOutgoing ? numConnected(Servent::T_OUTGOING) > maxOutgoing : false;
298         }
299
300         bool    controlInFull()
301         {
302                 return numConnected(Servent::T_CIN)>=maxControl;
303         }
304
305         bool    outFull() 
306         {
307                 return false;
308 //              return maxOutgoing ? numConnected(Servent::T_OUTGOING) >= maxOutgoing : false;
309         }
310
311         bool    relaysFull() 
312         {
313                 return numStreams(Servent::T_RELAY,false) >= maxRelays;
314         }
315         bool    directFull() 
316         {
317                 return numStreams(Servent::T_DIRECT,false) >= maxDirect;
318         }
319
320         bool    bitrateFull(unsigned int br) 
321         {
322                 return maxBitrateOut ? (BYTES_TO_KBPS(totalOutput(false))+br) > maxBitrateOut  : false;
323         }
324
325         unsigned int            totalOutput(bool);
326         unsigned int            totalInput(bool);
327
328         static ThreadInfo serverThread,idleThread;
329
330
331         Servent *servents;
332         WLock   lock;
333
334         ServHost        hostCache[MAX_HOSTCACHE];
335
336         char    password[64];
337
338         bool    allowGnutella;
339
340         unsigned int            maxBitrateOut,maxControl,maxRelays,maxDirect;
341         unsigned int            minGnuIncoming,maxGnuIncoming;
342         unsigned int            maxServIn;
343
344         bool    isDisabled;
345         bool    isRoot;
346         int             totalStreams;
347
348         Host    serverHost;
349         String  rootHost;
350         String  rootHost2;
351
352         char    downloadURL[128];
353         String  rootMsg;
354         String  forceIP;
355         char    connectHost[128];
356         GnuID   networkID;
357         unsigned int            firewallTimeout;
358         int             showLog;
359         int             shutdownTimer;
360         bool    pauseLog;
361         bool    forceNormal;
362         bool    useFlowControl;
363         unsigned int lastIncoming;
364
365         bool    restartServer;
366         bool    allowDirect;
367         bool    autoConnect,autoServe,forceLookup;
368         int             queryTTL;
369
370         unsigned int            allowServer1,allowServer2;
371         unsigned int            startTime;
372         unsigned int            tryoutDelay;
373         unsigned int            refreshHTML;
374         unsigned int            relayBroadcast;
375
376         unsigned int notifyMask;
377
378         BCID            *validBCID;
379         GnuID           sessionID;
380
381         ServFilter      filters[MAX_FILTERS];
382         int     numFilters;
383
384
385         CookieList      cookieList;
386         AUTH_TYPE       authType;
387
388         char    htmlPath[128];
389         unsigned int    clientVersions[MAX_VERSIONS],clientCounts[MAX_VERSIONS];
390         int     numVersions;
391
392         int serventNum;
393         String chanLog;
394
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 &);
407
408         bool    getModulePath; //JP-EX
409         bool    clearPLS; //JP-EX
410         bool    writeLogFile; //JP-EX
411
412         bool    autoPort0Kick;
413         bool    allowOnlyVP;
414         unsigned int kickKeepTime;
415         bool    vpDebug;
416         bool    saveIniChannel;
417         bool    saveGuiPos;
418         bool    keepDownstreams;
419
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¢
424
425         int versionDNS; // DNS\82©\82ç\8eæ\93¾\82µ\82½\8dÅ\90V\83o\81[\83W\83\87\83\93\82Ì\94Ô\8d\86
426
427         int maxRelaysIndexTxt;  // for PCRaw (relay)
428
429 #ifdef WIN32 //JP-MOD
430         bool    guiSimpleChannelList;
431         bool    guiSimpleConnectionList;
432         bool    guiTopMost;
433
434         int             guiChanListDisplays;
435         int             guiConnListDisplays;
436         bool    guiTitleModify;
437         String  guiTitleModifyNormal;
438         String  guiTitleModifyMinimized;
439
440         bool    guiAntennaNotifyIcon;
441
442         bool    ppClapSound;
443         String  ppClapSoundPath;
444 #endif
445
446         int             disableAutoBumpIfDirect;
447         int             asxDetailedMode;
448
449         enum PPBCSTFLAG //JP-MOD
450         {
451                 bcstNone                = 0x00000000,
452                 bcstClap                = 0x00000001
453         };
454
455         // PCP broadcast flood
456         GnuID lastPCPFromID;
457         time_t lastPCPBcstTime;
458
459 private:
460         FW_STATE        firewalled;
461 };
462
463 // ----------------------------------
464 extern ServMgr *servMgr;
465
466
467 #endif