~ubuntu-branches/ubuntu/precise/amule-adunanza/precise

« back to all changes in this revision

Viewing changes to src/kademlia/net/PacketTracking.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-02-18 21:16:23 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100218211623-gptwe60zx1knfkmu
Tags: 2010.1+2.2.6-0ubuntu1
* New upstream release (LP: #524697)
  - Drop manpages_spelling_fixes.diff fixed by upstream
  - Drop cryptopp-reference.diff fixed by upstream
  - Bump Standards-Version no changes required
  - Update install files (amule -> amuleadunanza)
  - debian/rules: amule.xpm -> amuleadunanza.xpm
  - Add README.Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
2
// This file is part of the aMule Project.
3
3
//
4
 
// Copyright (c) 2008 Dévai Tamás ( gonosztopi@amule.org )
5
 
// Copyright (c) 2008 aMule Team ( admin@amule.org / http://www.amule.org )
 
4
// Copyright (c) 2008-2009 Dévai Tamás ( gonosztopi@amule.org )
 
5
// Copyright (c) 2008-2009 aMule Team ( admin@amule.org / http://www.amule.org )
6
6
// Copyright (c) 2002-2008 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
7
7
//
8
8
// Any parts of this program derived from the xMule, lMule or eMule project,
35
35
#include <protocol/kad/Client2Client/UDP.h>
36
36
#include <protocol/kad2/Client2Client/UDP.h>
37
37
 
 
38
// ADUNANZA BEGIN
 
39
#if defined (ENABLE_ADUNSLU2)
 
40
#include "../../Preferences.h"    // Needed for thePrefs::GetPFlags
 
41
#endif
 
42
// ADUNANZA END
38
43
 
39
44
using namespace Kademlia;
40
45
 
51
56
{
52
57
        // this tracklist tacks _outgoing_ request packets, to make sure incoming answer packets were requested
53
58
        // only track packets which we actually check for later
 
59
// ADUNANZA BEGIN
 
60
#if defined(ENABLE_ADUNSLU2)
 
61
        if (!thePrefs::GetPFlags(FL_CLIENTTRACKING_DISABLE)) {
 
62
#endif
 
63
// ADUNANZA END
54
64
        if (!IsTrackedOutListRequestPacket(opcode)) {
55
65
                return;
56
66
        }
64
74
                        break;
65
75
                }
66
76
        }
 
77
// ADUNANZA BEGIN
 
78
#if defined(ENABLE_ADUNSLU2)
 
79
        }
 
80
#endif
 
81
// ADUNANZA END
67
82
}
68
83
 
69
84
bool CPacketTracking::IsTrackedOutListRequestPacket(uint8_t opcode) throw()
94
109
 
95
110
bool CPacketTracking::IsOnOutTrackList(uint32_t ip, uint8_t opcode, bool dontRemove)
96
111
{
 
112
// ADUNANZA BEGIN
 
113
#if defined(ENABLE_ADUNSLU2)
 
114
        if (thePrefs::GetPFlags(FL_PACKETTRACKING_DISABLE)) 
 
115
                return true;
 
116
        else {
 
117
#endif
 
118
// ADUNANZA END
97
119
#ifdef __DEBUG__
98
120
        if (!IsTrackedOutListRequestPacket(opcode)) {
99
121
                wxFAIL; // code error / bug
109
131
                }
110
132
        }
111
133
        return false;
 
134
 
 
135
// ADUNANZA BEGIN
 
136
#if defined(ENABLE_ADUNSLU2)
 
137
        }
 
138
#endif
 
139
// ADUNANZA END
112
140
}
113
141
 
114
142
bool CPacketTracking::InTrackListIsAllowedPacket(uint32_t ip, uint8_t opcode, bool /*bValidSenderkey*/)
121
149
        // timelimits are chosen by estimating the max. frequency of such packets on normal operation (+ buffer)
122
150
        // (those limits are not meant to be fine to be used by normal usage, but only supposed to be a flood detection)
123
151
 
 
152
// ADUNANZA BEGIN
 
153
#if defined(ENABLE_ADUNSLU2)
 
154
        if (thePrefs::GetPFlags(FL_PACKETTRACKING_DISABLE)) 
 
155
                return true;
 
156
        else {
 
157
#endif
 
158
// ADUNANZA END
 
159
 
124
160
        uint32_t allowedPacketsPerMinute;
125
161
        const uint8_t dbgOrgOpcode = opcode;
126
162
 
254
290
        trackEntry->m_lastExpire = std::max(trackEntry->m_lastExpire, currentTick + SEC2MS(secondsPerPacket));
255
291
        trackEntry->m_trackedRequests.push_back(curTrackedRequest);
256
292
        return true;
 
293
 
 
294
// ADUNANZA BEGIN
 
295
#if defined(ENABLE_ADUNSLU2)
 
296
        }
 
297
#endif
 
298
// ADUNANZA END
257
299
}
258
300
 
259
301
void CPacketTracking::InTrackListCleanup()
273
315
 
274
316
void CPacketTracking::AddLegacyChallenge(const CUInt128& contactID, const CUInt128& challengeID, uint32_t ip, uint8_t opcode)
275
317
{
 
318
// ADUNANZA BEGIN
 
319
#if defined(ENABLE_ADUNSLU2)
 
320
        if (!thePrefs::GetPFlags(FL_LEGACYCHALLENGE_DISABLE)) { 
 
321
#endif
 
322
// ADUNANZA END
 
323
 
276
324
        uint32_t now = ::GetTickCount();
277
325
        TrackChallenge_Struct sTrack = { ip, now, opcode, contactID, challengeID };
278
326
        listChallengeRequests.push_front(sTrack);
284
332
                        break;
285
333
                }
286
334
        }
 
335
 
 
336
// ADUNANZA BEGIN
 
337
#if defined(ENABLE_ADUNSLU2)
 
338
        }
 
339
#endif
 
340
// ADUNANZA END
287
341
}
288
342
 
289
343
bool CPacketTracking::IsLegacyChallenge(const CUInt128& challengeID, uint32_t ip, uint8_t opcode, CUInt128& contactID)