Upstream tarball 20080902
[amule.git] / src / utils / fileview / KadFiles.cpp
blob9d3a0a43d9f8a23f0bd909a7b8c703e26fb419de
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2008 Dévai Tamás ( gonosztopi@amule.org )
5 // Copyright (c) 2004-2008 aMule Team ( admin@amule.org / http://www.amule.org )
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 #include "KadFiles.h"
27 #include "Print.h"
28 #include "../../SafeFile.h"
30 void DecodePreferencesKadDat(const CFileDataIO& file)
32 cout << "IP : " << CKadIP(file.ReadUInt32()) << '\n';
33 cout << "(unused): " << file.ReadUInt16() << '\n';
34 cout << "ClientID: " << file.ReadUInt128() << '\n';
37 void DecodeLoadIndexDat(const CFileDataIO& file)
39 cout << "Version : " << file.ReadUInt32();
40 cout << "\n(savetime): " << CTimeT(file.ReadUInt32());
41 uint32_t numLoad = file.ReadUInt32();
42 cout << "\nnumLoad : " << numLoad << '\n';
43 for (uint32_t i = 0; i < numLoad; i++) {
44 cout << "\t{ " << file.ReadUInt128();
45 cout << ", " << CTimeT(file.ReadUInt32()) << " }\n";
49 void DecodeKeyIndexDat(const CFileDataIO& file)
51 uint32_t version;
52 uint32_t numKeys;
53 uint32_t numSource;
54 uint32_t numName;
55 uint8_t tagCount;
57 cout << "Version : " << (version = file.ReadUInt32());
58 cout << "\nSaveTime: " << CTimeT(file.ReadUInt32());
59 cout << "\nID : " << file.ReadUInt128();
60 cout << "\nnumKeys : " << (numKeys = file.ReadUInt32()) << '\n';
61 for (uint32_t ik = 0; ik < numKeys; ik++) {
62 cout << "\tKeyID : " << file.ReadUInt128();
63 cout << "\n\tnumSource: " << (numSource = file.ReadUInt32()) << '\n';
64 for (uint32_t is = 0; is < numSource; is++) {
65 cout << "\t\tSourceID: " << file.ReadUInt128();
66 cout << "\n\t\tnumName : " << (numName = file.ReadUInt32()) << '\n';
67 for (uint32_t iN = 0; iN < numName; iN++) {
68 cout << "\t\t\tLifeTime : " << CTimeT(file.ReadUInt32()) << '\n';
69 if (version >= 3) {
70 uint32_t count;
71 cout << "\t\t\tnameCount: " << (count = file.ReadUInt32()) << '\n';
72 for (uint32_t i = 0; i < count; i++) {
73 cout << "\t\t\t\t{ " << MakePrintableString(file.ReadString(true, 2));
74 cout << ", " << file.ReadUInt32() << " }\n";
76 cout << "\t\t\tipCount : " << (count = file.ReadUInt32()) << '\n';
77 for (uint32_t i = 0; i < count; i++) {
78 cout << "\t\t\t\t{ " << CKadIP(file.ReadUInt32());
79 cout << ", " << CTimeT(file.ReadUInt32()) << " }\n";
82 cout << "\t\t\ttagCount : " << (tagCount = file.ReadUInt8()) << '\n';
83 for (uint32_t it = 0; it < tagCount; it++) {
84 CTag *tag = file.ReadTag();
85 cout << "\t\t\t\t" << *tag << '\n';
86 delete tag;
93 void DecodeSourceIndexDat(const CFileDataIO& file)
95 uint32_t numKeys;
96 uint32_t numSource;
97 uint32_t numName;
98 uint8_t tagCount;
100 cout << "Version : " << file.ReadUInt32();
101 cout << "\nSaveTime: " << CTimeT(file.ReadUInt32());
102 cout << "\nnumKeys : " << (numKeys = file.ReadUInt32()) << '\n';
103 for (uint32_t ik = 0; ik < numKeys; ik++) {
104 cout << "\tKeyID : " << file.ReadUInt128();
105 cout << "\n\tnumSource: " << (numSource = file.ReadUInt32()) << '\n';
106 for (uint32_t is = 0; is < numSource; is++) {
107 cout << "\t\tSourceID: " << file.ReadUInt128();
108 cout << "\n\t\tnumName : " << (numName = file.ReadUInt32()) << '\n';
109 for (uint32_t iN = 0; iN < numName; iN++) {
110 cout << "\t\t\tLifeTime: " << CTimeT(file.ReadUInt32());
111 cout << "\n\t\t\ttagCount: " << (tagCount = file.ReadUInt8()) << '\n';
112 for (uint32_t it = 0; it < tagCount; it++) {
113 CTag *tag = file.ReadTag();
114 cout << "\t\t\t\t" << *tag << '\n';
115 delete tag;
122 void DecodeNodesDat(const CFileDataIO& file)
124 uint32_t numContacts = file.ReadUInt32();
125 uint32_t fileVersion = 0;
127 cout << "NumContacts #1 : " << numContacts << '\n';
128 if (numContacts == 0) {
129 cout << "FileVersion : " << (fileVersion = file.ReadUInt32()) << '\n';
130 if (fileVersion == 3) {
131 cout << "BootstrapEdition: " << file.ReadUInt32() << '\n';
133 if (fileVersion >= 1 && fileVersion <= 3) {
134 cout << "NumContacts #2 : " << (numContacts = file.ReadUInt32()) << '\n';
137 for (uint32_t i = 0; i < numContacts; i++) {
138 cout << wxString::Format(wxT("#%u\tID : "), i) << file.ReadUInt128();
139 cout << "\n\tIP : " << CKadIP(file.ReadUInt32());
140 cout << "\n\tUDP Port : " << file.ReadUInt16();
141 cout << "\n\tTCP Port : " << file.ReadUInt16();
142 if (fileVersion >= 1) {
143 cout << "\n\tVersion : ";
144 } else {
145 cout << "\n\tType : ";
147 cout << (unsigned)file.ReadUInt8();
148 if (fileVersion >= 2) {
149 cout << "\n\tUDP Key : { " << hex(file.ReadUInt32());
150 cout << ", " << CKadIP(file.ReadUInt32());
151 cout << " }\n\tVerified : " << (file.ReadUInt8() != 0 ? "true" : "false");
153 cout << '\n';