📄 servmgr.h
字号:
// ------------------------------------------------// File : servmgr.h// Date: 4-apr-2002// Author: giles// Desc: //// (c) 2002 peercast.org// ------------------------------------------------// 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.// ------------------------------------------------#ifndef _SERVMGR_H#define _SERVMGR_H#include "servent.h"// ----------------------------------class ServFilter {public: enum { F_PRIVATE = 0x01, F_BAN = 0x02, F_ALLOW = 0x04 }; ServFilter() {init();} void init() { flags = 0; host.init(); } Host host; unsigned int flags;};// ----------------------------------// ServMgr keeps track of Serventsclass ServMgr{public: enum NOTIFY_TYPE { NT_UPGRADE = 0x0001, NT_PEERCAST = 0x0002, NT_BROADCASTERS = 0x0004, NT_TRACKINFO = 0x0008 }; enum FW_STATE { FW_OFF, FW_ON, FW_UNKNOWN }; enum { MAX_BITRATE = 128, // max. Kbits/s output MAX_HOSTCACHE = 100, // max. amount of hosts in cache MIN_HOSTS = 3, // min. amount of hosts that should be kept in cache MAX_SERVENTS = 32, // max. number of available servents MAX_OUTGOING = 3, // max. number of outgoing servents to use MAX_INCOMING = 5, // max. number of incoming servents to use MAX_TRYOUT = 10, // max. number of outgoing servents to try connect MIN_CONNECTED = 3, // min. amount of connected hosts that should be kept MAX_FILTERS = 64, MAX_VERSIONS = 16 }; enum AUTH_TYPE { AUTH_COOKIE, AUTH_HTTPBASIC }; ServMgr(); bool start(); Servent *findServent(unsigned int,unsigned short); Servent *findServent(Servent::TYPE); Servent *allocServent(); unsigned int numUsed(int); unsigned int numConnected(int); unsigned int totalConnected() { return numConnected(Servent::T_OUTGOING) + numConnected(Servent::T_INCOMING); } unsigned int numStreams(bool); unsigned int numOutgoing(); bool isFiltered(int,Host &h); static THREAD_PROC serverProc(ThreadInfo *); static THREAD_PROC clientProc(ThreadInfo *); static THREAD_PROC idleProc(ThreadInfo *); int broadcast(GnuPacket &,Servent * = NULL); int route(GnuPacket &, GnuID &, Servent * = NULL); void addHost(Host &,bool = false); Host getHost(); int getNewestHosts(Host *,int, Host &); void deadHost(Host &); unsigned int numHosts(); void setFirewall(FW_STATE); FW_STATE getFirewall() {return firewalled;} void saveSettings(const char *); void loadSettings(const char *); void setPassiveSearch(unsigned int); int findChannel(ChanInfo &); void setFilterDefaults(); void clearHostCache(); void addVersion(unsigned int); unsigned int getUptime() { return sys->getTime()-startTime; } bool seenPacket(GnuPacket &); bool isReplyID(GnuID &id) { return replyIDs.contains(id); } void addReplyID(GnuID &id) { replyIDs.addGnuID(id); } bool needHosts() { return numHosts() < maxTryout; } bool needConnections() { return totalConnected() < minConnected; } bool tryFull() { return maxTryout ? numUsed(Servent::T_OUTGOING) > maxTryout: false; } bool inOver() { return maxIncoming ? numConnected(Servent::T_INCOMING) > maxIncoming : false; } bool inFull() { return maxIncoming ? numConnected(Servent::T_INCOMING) >= maxIncoming : false; } bool outOver() { return maxOutgoing ? numConnected(Servent::T_OUTGOING) > maxOutgoing : false; } bool outFull() { return maxOutgoing ? numConnected(Servent::T_OUTGOING) >= maxOutgoing : false; } bool streamFull() { return maxStreams ? numStreams(false) >= maxStreams : false; } bool bitrateFull(unsigned int br) { return maxBitrate ? (BYTES_TO_KBPS(totalOutput(false))+br) > maxBitrate : false; } unsigned int totalOutput(bool); Servent servents[MAX_SERVENTS]; WLock lock; Host hostCache[MAX_HOSTCACHE]; unsigned int readHostPtr,writeHostPtr; char password[64]; bool allowGnutella; unsigned int maxBitrate,maxIncoming,maxOutgoing,maxStreams,maxTryout,minConnected; bool isRoot; int totalStreams; Host serverHost; char downloadURL[128]; String rootMsg; char forceIP[64]; char connectHost[128]; String network; unsigned int firewallTimeout; int showLog; int shutdownTimer; bool pauseLog; bool forceNormal; bool restartServer; bool allowDirect; bool autoConnect,autoServe,forceLookup; unsigned int allowServer1,allowServer2; unsigned int startTime; unsigned int tryoutDelay; unsigned int refreshHTML; unsigned int relayBroadcast; unsigned int serventBandwidth; unsigned int notifyMask; GnuIDList replyIDs; GnuID sessionID; ServFilter filters[MAX_FILTERS]; int numFilters; CookieList cookieList; AUTH_TYPE authType; unsigned int clientVersions[MAX_VERSIONS],clientCounts[MAX_VERSIONS]; int numVersions;private: FW_STATE firewalled;};// ----------------------------------extern ServMgr *servMgr;#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -