-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBandWidthControl.h
204 lines (169 loc) · 6.97 KB
/
BandWidthControl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//this file is part of eMule Xtreme-Mod (http://www.xtreme-mod.net)
//Copyright (C)2002-2007 Xtreme-Mod ([email protected])
//emule Xtreme is a modification of eMule
//Copyright (C)2002-2007 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
//
//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.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
//
// Author: Xman / Maella
//
#pragma once
#include "Types.h"
#include "Log.h"
#include "opcodes.h"
#include <Iphlpapi.h>
#include <afxtempl.h>
// This class has two purposes:
//
// Collect all statistics relevant to the upload/download bandwidth
// Provide an interface to the LAN adapter (Ethernet, slip, etc...)
class CBandWidthControl
{
public:
CBandWidthControl();
~CBandWidthControl();
// Update the history list. Must be called every cycle
void Process();
// Actualize current datarate values (Data+Control)
// Remark: the overhead for the IP/TCP/UDP headers is not included
//Add width Header:
/**/ void AddeMuleOutUDPOverall(uint32 octets);
/**/ void AddeMuleOutTCPOverall(uint32 octets);
/**/ void AddeMuleInUDPOverall(uint32 octets);
/**/ void AddeMuleInTCPOverall(uint32 octets);
//Add without Header (already included)
/**/ void AddeMuleOutOverallNoHeader(uint32 octets);
/**/ void AddeMuleOut(uint32 octets);
/**/ void AddeMuleIn(uint32 octets);
/**/ void AddeMuleSYNACK();
//calculating obfuscation
/**/ void AddeMuleOutObfuscationTCP(uint32 octets);
/**/ void AddeMuleOutObfuscation(uint32 octets);
/**/ void AddeMuleOutObfuscationUDP(uint32 octets);
void AddeMuleInObfuscation(uint32 octets); //only main-thread!!
/**/ uint64 GeteMuleOutObfuscation() const;
uint64 GeteMuleInObfuscation() const; //only main-thread!!
// Accessors, used for the control of the bandwidth (=> slope)
/**/ uint64 GeteMuleOut() const;
/**/ uint64 GeteMuleIn() const;
/**/ uint64 GeteMuleOutOverall() const;
/**/ uint64 GeteMuleInOverall() const;
/**/ uint64 GetNetworkOut() const;
/**/ uint64 GetNetworkIn() const;
/**/ uint32 GetStartTick() const;
//Xman show complete internettraffic
//used for statistic
uint64 GetSessionNetworkOut() const;
uint64 GetSessionNetworkIn() const;
//Xman end
// Retrieve datarates for barline + upload slot management + Graphic
void GetDatarates(UINT samples,
uint32& eMuleIn, uint32& eMuleInOverall,
uint32& eMuleOut, uint32& eMuleOutOverall,
uint32& networkIn, uint32& networkOut) const;
// Retrieve datarates Graphic
void GetFullHistoryDatarates(uint32& eMuleInHistory, uint32& eMuleOutHistory,
uint32& eMuleInSession, uint32& eMuleOutSession) const;
// Check if the NAFC is available on this computer
bool IsNAFCAvailable() const {return (m_fGetIfEntry != NULL);}
// Full NAFC bandwidth control
float GetMaxDownload() const {return m_maxDownloadLimit;}
float GetMaxUpload() const {return m_maxUploadLimit;}
//Xman 1:3 Ratio (use this instead of GetMaxDownload()
//Xman GlobalMaxHarlimit for fairness
// ==> Enforce Ratio [Stulle] - Stulle
/*
float GetMaxDownloadEx(bool force);
*/
float GetMaxDownloadEx(uint8 force, uint8 &uReason, uint8 &uRatio);
// <== Enforce Ratio [Stulle] - Stulle
float GetForcedDownloadlimit() const {return m_maxforcedDownloadlimit;}
//Xman new adapter selection
void checkAdapterIndex(uint32 highid);
void SetWasNAFCLastActive(bool in) {wasNAFCLastActive=in;}
bool GetwasNAFCLastActive() {return wasNAFCLastActive;}
void SetBoundIP(uint32 boundip) {boundIP=boundip;}
#ifdef PRINT_STATISTIC
void PrintStatistic();
#endif
private:
// Adapter access
DWORD getAdapterIndex();
DWORD m_currentAdapterIndex;
DWORD m_lastAdapterIndex;
//Xman new adapter selection
bool wasNAFCLastActive;
uint32 boundIP;
// Type definition
#pragma pack(1)
struct Statistic {
Statistic() {}
Statistic(const Statistic& ref, uint32 time)
: eMuleOutOctets(ref.eMuleOutOctets),
eMuleInOctets(ref.eMuleInOctets),
eMuleOutOverallOctets(ref.eMuleOutOverallOctets),
eMuleInOverallOctets(ref.eMuleInOverallOctets),
networkOutOctets(ref.networkOutOctets),
networkInOctets(ref.networkInOctets),
timeStamp(time) {}
uint64 eMuleOutOctets; // Data
uint64 eMuleInOctets;
uint64 eMuleOutOverallOctets; // Data+Control
uint64 eMuleInOverallOctets;
uint64 networkOutOctets; // DataFlow of the network Adapter
uint64 networkInOctets;
uint32 timeStamp; // Use a time stamp to compensate the inaccuracy of the timer (based on enkeyDEV(Ottavio84))
};
#pragma pack()
typedef CList<Statistic> StatisticHistory; // Use MS container for its memory management
StatisticHistory m_statisticHistory; // History for the graphic
/**/ Statistic m_statistic; // Current value
float m_maxDownloadLimit; // Used for auto U/D limits
float m_maxUploadLimit;
//Xman GlobalMaxHarlimit for fairness
float m_maxforcedDownloadlimit;
//Xman thread save
mutable CCriticalSection m_statisticLocker;
// Keep last result to detect an overflow
DWORD m_networkOutOctets;
DWORD m_networkInOctets;
//calculating obfuscation
uint64 m_obfuscation_InOctets;
uint64 m_obfuscation_OutOctets;
bool m_errorTraced;
// Dynamic access to the iphlpapi.dll
typedef DWORD (WINAPI *GETNUMBEROFINTERFACES)(PDWORD pdwNumIf);
typedef DWORD (WINAPI *GETIFTABLE)(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder);
typedef DWORD (WINAPI *GETIPADDRTABLE)(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder);
typedef DWORD (WINAPI *GETIFENTRY)(PMIB_IFROW pIfRow);
HINSTANCE m_hIphlpapi;
GETIFTABLE m_fGetIfTable;
GETIPADDRTABLE m_fGetIpAddrTable;
GETIFENTRY m_fGetIfEntry;
GETNUMBEROFINTERFACES m_fGetNumberOfInterfaces;
private:
// Don't allow canonical behavior
CBandWidthControl(const CBandWidthControl&);
CBandWidthControl& operator=(const CBandWidthControl&);
// ==> Enforce Ratio [Stulle] - Stulle
float m_maxforcedDownloadlimitEnforced;
float m_fMaxDownloadEqualUploadLimit;
uint8 m_uNAFCRatio;
public:
float GetForcedDownloadlimitEnforced() const {return m_maxforcedDownloadlimitEnforced;}
float GetMaxDownloadEqualUploadLimit() const {return m_fMaxDownloadEqualUploadLimit;}
// <== Enforce Ratio [Stulle] - Stulle
};