Upstream tarball 20080414
[amule.git] / src / ClientCredits.h
blob8bd60c742f6ea5b29ec9533ccf3c7db814f67d05
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #ifndef CLIENTCREDITS_H
27 #define CLIENTCREDITS_H
29 #include "MD4Hash.h" // Needed for CMD4Hash
31 #define MAXPUBKEYSIZE 80
33 #define CRYPT_CIP_REMOTECLIENT 10
34 #define CRYPT_CIP_LOCALCLIENT 20
35 #define CRYPT_CIP_NONECLIENT 30
37 #ifdef _MSC_VER
38 #pragma pack(1)
39 #endif
40 struct CreditStruct
42 CreditStruct();
44 CMD4Hash key;
45 uint64 uploaded; // uploaded TO him
46 uint64 downloaded; // downloaded from him
47 uint32 nLastSeen;
48 uint16 nReserved3;
49 uint8 nKeySize;
50 byte abySecureIdent[MAXPUBKEYSIZE];
52 #ifdef _MSC_VER
54 #pragma pack()
55 #else
56 __attribute__((__packed__));
57 #endif
59 enum EIdentState{
60 IS_NOTAVAILABLE,
61 IS_IDNEEDED,
62 IS_IDENTIFIED,
63 IS_IDFAILED,
64 IS_IDBADGUY
67 class CClientCredits
70 public:
71 CClientCredits(CreditStruct* in_credits);
72 CClientCredits(const CMD4Hash& key);
73 ~CClientCredits();
75 const CMD4Hash& GetKey() const {return m_pCredits->key;}
76 const byte* GetSecureIdent() const {return m_abyPublicKey;}
77 uint8 GetSecIDKeyLen() const {return m_nPublicKeyLen;}
78 const CreditStruct* GetDataStruct() const {return m_pCredits;}
79 void ClearWaitStartTime();
80 void AddDownloaded(uint32 bytes, uint32 dwForIP, bool cryptoavail);
81 void AddUploaded(uint32 bytes, uint32 dwForIP, bool cryptoavail);
82 uint64 GetUploadedTotal() const;
83 uint64 GetDownloadedTotal() const;
84 float GetScoreRatio(uint32 dwForIP, bool cryptoavail);
85 void SetLastSeen();
86 bool SetSecureIdent(const byte* pachIdent, uint8 nIdentLen); // Public key cannot change, use only if there is not public key yet
87 uint32 m_dwCryptRndChallengeFor;
88 uint32 m_dwCryptRndChallengeFrom;
89 EIdentState GetCurrentIdentState(uint32 dwForIP) const; // can be != m_identState
90 uint32 GetSecureWaitStartTime(uint32 dwForIP);
91 void SetSecWaitStartTime(uint32 dwForIP);
92 void Verified(uint32 dwForIP);
93 EIdentState GetIdentState() const { return m_identState; }
94 void SetIdentState(EIdentState state) { m_identState = state; }
96 private:
97 EIdentState m_identState;
98 void InitalizeIdent();
99 CreditStruct* m_pCredits;
100 byte m_abyPublicKey[80]; // even keys which are not verified will be stored here, and - if verified - copied into the struct
101 uint8 m_nPublicKeyLen;
102 uint32 m_dwIdentIP;
103 uint32 m_dwWaitTime;
104 uint32 m_dwSecureWaitTime;
105 uint32 m_dwUnSecureWaitTime;
106 uint32 m_dwWaitTimeIP; // client IP assigned to the waittime
109 #endif // CLIENTCREDITS_H
110 // File_checked_for_headers