/[svn]/vendor/pxys2-2.1.0/pxyscand/src/PXScanManager.h
ViewVC logotype

Contents of /vendor/pxys2-2.1.0/pxyscand/src/PXScanManager.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3253 - (show annotations)
Wed Apr 2 20:46:18 2014 UTC (6 years, 11 months ago) by michael
File MIME type: text/x-csrc
File size: 3565 byte(s)
- Imported pxys2-2.1.0

1 // Copyright (C) 2003 Stephane Thiell
2 //
3 // This file is part of pxyscand (from pxys)
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // $Id: PXScanManager.h,v 1.2 2006/09/10 22:09:30 spale Exp $
20 //
21 #ifndef INCLUDED_PXSCANMANAGER_H_
22 #define INCLUDED_PXSCANMANAGER_H_
23
24 #include <deque>
25 #include <queue>
26 #include <vector>
27 #include <fstream>
28 #include <cstdlib>
29
30 #include "PXConfig.h"
31 #include "PXMutex.h"
32 #include "PXRepeater.h"
33
34 #include <peak/peak.h>
35
36 using std::queue;
37 using std::deque;
38 using std::ofstream;
39 using std::vector;
40
41 class PXConfig;
42 class PXScan;
43
44 typedef PXScan * PXScanPtr;
45
46 struct PXModuleInfo
47 {
48 PXModuleInfo(const char *inShortName, uint16_t inPort,
49 uint32_t *inConnCountPtr, uint32_t *inProxyCountPtr)
50 {
51 shortName = peak_strdup(inShortName);
52 port = inPort;
53 connCountPtr = inConnCountPtr;
54 proxyCountPtr = inProxyCountPtr;
55 }
56 ~PXModuleInfo() { peak_deallocate(shortName); }
57
58 char *shortName;
59 uint16_t port;
60 uint32_t *connCountPtr;
61 uint32_t *proxyCountPtr;
62 };
63
64 class PXScanManager : public PXRepeater
65 {
66 public:
67 PXScanManager(PXConfig *inConfig);
68 virtual ~PXScanManager();
69
70 void Rehash();
71 size_t GetModuleInfoCount() const { return mMInfo.size(); }
72 void UseModule(PXModuleInfo *inNewMInfo) { mMInfo.push_back(inNewMInfo); }
73 const PXModuleInfo *GetMInfo(int idx) const { return mMInfo[idx]; }
74
75 bool AddScan(PXScan *inScan);
76 void ScanCompleted(PXScan *inScan);
77
78 in_addr GetTargetAddress() const { return mScanTarget.address; }
79 uint16_t GetTargetPort() const { return (uint16_t)mScanTarget.port; }
80 char *GetTargetSecret() const { return mScanTarget.secret; }
81 time_t GetLastTargetCheck() const { return mLastTargetCheck; }
82
83 ofstream& GetFAgent() { return mFAgent; }
84
85 // Status readers (not sync):
86
87 // Current number of IPs being scanned.
88 int GetIPScanCount() const { return mIPScanCount; }
89 // Max simultaneous scannable IPs
90 int GetIPScanMax() const { return sNeededFDs ? mRunScanMax/sNeededFDs : 0; }
91 // Current "allocated" socket scans (overestimation).
92 int GetRunScanCount() const { return mRunScanCount; }
93 // Max socket scans (from config)
94 int GetRunScanMax() const { return mRunScanMax; }
95
96 size_t GetScanQSize() const { return mScanQ.size(); }
97
98 PXConfig *mConfig;
99
100 protected:
101 void TargetCheck();
102 void TargetCheckNext();
103 void RepeaterFire();
104 void TCEvent(peak_stream s, int type);
105
106 static void TCEventCallback(peak_stream s, int type, void *context);
107
108 ofstream mFAgent;
109 vector<PXConfigScannerTarget> mScanTargets;
110 vector<PXConfigScannerTarget>::const_iterator mScanTargetIterator;
111 PXConfigScannerTarget mScanTarget;
112 time_t mLastTargetCheck;
113 int mIPScanCount, mRunScanMax, mRunScanCount;
114 queue<PXScanPtr> mScanQ;
115 PXMutex mMutex;
116 vector<PXModuleInfo*> mMInfo;
117 static int sNeededFDs;
118 };
119
120 #endif // INCLUDED_PXSCANMANAGER_H_

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28