mirror of
https://github.com/aria2/aria2.git
synced 2025-02-08 06:56:33 +00:00
2008-08-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Bump up version number of dht.dat file to 3. In version 3 format, time is stored in 64bit, network byte order. New build can load old format(version 2) but it saves the file in new format. It means once you used new build, your dht.dat becomes incompatible with older build. * src/DHTRoutingTableDeserializer.cc * src/DHTRoutingTableSerializer.cc * test/DHTRoutingTableSerializerTest.cc
This commit is contained in:
parent
d9668e2c23
commit
15101a89a0
16
ChangeLog
16
ChangeLog
@ -1,3 +1,19 @@
|
||||
2008-08-25 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Bump up version number of dht.dat file to 3. In version 3 format, time
|
||||
is stored in 64bit, network byte order.
|
||||
New build can load old format(version 2) but it saves the file in new
|
||||
format. It means once you used new build, your dht.dat becomes
|
||||
incompatible with older build.
|
||||
* src/DHTRoutingTableDeserializer.cc
|
||||
* src/DHTRoutingTableSerializer.cc
|
||||
* test/DHTRoutingTableSerializerTest.cc
|
||||
|
||||
2008-08-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Added load-v0001.aria2 and load-nonBt-v0001.aria2 to EXTRA_DIST.
|
||||
* test/Makefile.am
|
||||
|
||||
2008-08-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Bump up version number of .aria2 control file to 0001.
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "Logger.h"
|
||||
#include "a2netcompat.h"
|
||||
#include "StringFormat.h"
|
||||
#include "Util.h"
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <istream>
|
||||
@ -73,24 +74,45 @@ void DHTRoutingTableDeserializer::deserialize(std::istream& in)
|
||||
header[2] = 0x02;
|
||||
// version
|
||||
header[6] = 0;
|
||||
header[7] = 0x02;
|
||||
header[7] = 0x03;
|
||||
|
||||
char headerCompat[8];
|
||||
memset(headerCompat, 0, sizeof(headerCompat));
|
||||
// magic
|
||||
headerCompat[0] = 0xa1;
|
||||
headerCompat[1] = 0xa2;
|
||||
// format ID
|
||||
headerCompat[2] = 0x02;
|
||||
// version
|
||||
headerCompat[6] = 0;
|
||||
headerCompat[7] = 0x02;
|
||||
|
||||
char zero[8];
|
||||
memset(zero, 0, sizeof(zero));
|
||||
|
||||
int version;
|
||||
char buf[26];
|
||||
// header
|
||||
in.read(buf, 8);
|
||||
if(memcmp(header, buf, 8) != 0) {
|
||||
if(memcmp(header, buf, 8) == 0) {
|
||||
version = 3;
|
||||
} else if(memcmp(headerCompat, buf, 8) == 0) {
|
||||
version = 2;
|
||||
} else {
|
||||
throw DlAbortEx
|
||||
(StringFormat("Failed to load DHT routing table. cause:%s",
|
||||
"bad header").str());
|
||||
}
|
||||
// time
|
||||
in.read(buf, 4);
|
||||
_serializedTime.setTimeInSec(ntohl(*reinterpret_cast<uint32_t*>(buf)));
|
||||
// 4bytes reserved
|
||||
in.read(buf, 4);
|
||||
if(version == 2) {
|
||||
in.read(buf, 4);
|
||||
_serializedTime.setTimeInSec(ntohl(*reinterpret_cast<uint32_t*>(buf)));
|
||||
// 4bytes reserved
|
||||
in.read(buf, 4);
|
||||
} else {
|
||||
in.read(buf, 8);
|
||||
_serializedTime.setTimeInSec(ntoh64(*reinterpret_cast<uint64_t*>(buf)));
|
||||
}
|
||||
|
||||
// localnode
|
||||
// 8bytes reserved
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "Logger.h"
|
||||
#include "a2netcompat.h"
|
||||
#include "StringFormat.h"
|
||||
#include "Util.h"
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <ostream>
|
||||
@ -71,17 +72,15 @@ void DHTRoutingTableSerializer::serialize(std::ostream& o)
|
||||
header[2] = 0x02;
|
||||
// version
|
||||
header[6] = 0;
|
||||
header[7] = 0x02;
|
||||
header[7] = 0x03;
|
||||
|
||||
char zero[16];
|
||||
memset(zero, 0, sizeof(zero));
|
||||
try {
|
||||
o.write(header, 8);
|
||||
// write save date
|
||||
uint32_t ntime = htonl(Time().getTime());
|
||||
o.write(reinterpret_cast<const char*>(&ntime), sizeof(uint32_t));
|
||||
// 4bytes reserved
|
||||
o.write(zero, 4);
|
||||
uint64_t ntime = hton64(Time().getTime());
|
||||
o.write(reinterpret_cast<const char*>(&ntime), sizeof(ntime));
|
||||
|
||||
// localnode
|
||||
// 8bytes reserved
|
||||
|
@ -66,15 +66,12 @@ void DHTRoutingTableSerializerTest::testSerialize()
|
||||
CPPUNIT_ASSERT((char)0x00 == buf[5]);
|
||||
// version
|
||||
CPPUNIT_ASSERT((char)0x00 == buf[6]);
|
||||
CPPUNIT_ASSERT((char)0x02 == buf[7]);
|
||||
CPPUNIT_ASSERT((char)0x03 == buf[7]);
|
||||
|
||||
// time
|
||||
ss.read(buf, 4);
|
||||
time_t time = ntohl(*reinterpret_cast<uint32_t*>(buf));
|
||||
ss.read(buf, 8);
|
||||
time_t time = ntoh64(*reinterpret_cast<uint64_t*>(buf));
|
||||
std::cerr << time << std::endl;
|
||||
// 4bytes reserved
|
||||
ss.read(buf, 4);
|
||||
CPPUNIT_ASSERT(memcmp(zero, buf, 4) == 0);
|
||||
|
||||
// localnode
|
||||
// 8bytes reserved
|
||||
|
Loading…
x
Reference in New Issue
Block a user