2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
|
|
|
* aria2 - The high speed download utility
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* 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
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "DHTRoutingTableDeserializer.h"
|
2009-02-11 16:33:45 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
2009-02-12 14:17:13 +00:00
|
|
|
#include <cassert>
|
2011-08-05 11:17:19 +00:00
|
|
|
#include <cstdio>
|
2009-02-11 16:33:45 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
#include "DHTNode.h"
|
|
|
|
#include "DHTConstants.h"
|
2009-09-29 14:52:42 +00:00
|
|
|
#include "bittorrent_helper.h"
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
#include "DlAbortEx.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Logger.h"
|
2008-03-03 15:41:58 +00:00
|
|
|
#include "a2netcompat.h"
|
2010-11-20 09:36:14 +00:00
|
|
|
#include "fmt.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2009-02-11 16:33:45 +00:00
|
|
|
#include "array_fun.h"
|
2011-08-05 13:23:53 +00:00
|
|
|
#include "LogFactory.h"
|
2011-08-06 12:35:39 +00:00
|
|
|
#include "BufferedFile.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
|
2010-08-07 14:15:21 +00:00
|
|
|
DHTRoutingTableDeserializer::DHTRoutingTableDeserializer(int family):
|
|
|
|
family_(family) {}
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
|
|
|
|
DHTRoutingTableDeserializer::~DHTRoutingTableDeserializer() {}
|
|
|
|
|
2011-08-06 12:35:39 +00:00
|
|
|
#define READ_CHECK(fp, ptr, count) \
|
|
|
|
if(fp.read((ptr), (count)) != (count)) { \
|
|
|
|
throw DL_ABORT_EX("Failed to load DHT routing table."); \
|
2011-08-05 11:17:19 +00:00
|
|
|
}
|
|
|
|
|
2010-10-30 16:02:15 +00:00
|
|
|
namespace {
|
2011-08-06 12:35:39 +00:00
|
|
|
void readBytes(BufferedFile& fp,
|
|
|
|
unsigned char* buf, size_t buflen,
|
|
|
|
size_t readlen)
|
2009-02-12 14:17:13 +00:00
|
|
|
{
|
|
|
|
assert(readlen <= buflen);
|
2011-08-06 12:35:39 +00:00
|
|
|
READ_CHECK(fp, buf, readlen);
|
2009-02-12 14:17:13 +00:00
|
|
|
}
|
2010-10-30 16:02:15 +00:00
|
|
|
} // namespace
|
2009-02-12 14:17:13 +00:00
|
|
|
|
2011-08-05 11:17:19 +00:00
|
|
|
void DHTRoutingTableDeserializer::deserialize(const std::string& filename)
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
{
|
2011-08-05 13:23:53 +00:00
|
|
|
A2_LOG_INFO(fmt("Loading DHT routing table from %s.",
|
2011-08-08 12:46:10 +00:00
|
|
|
filename.c_str()));
|
2012-09-25 14:44:41 +00:00
|
|
|
BufferedFile fp(filename.c_str(), BufferedFile::READ);
|
2011-08-05 11:17:19 +00:00
|
|
|
if(!fp) {
|
2011-08-05 13:23:53 +00:00
|
|
|
throw DL_ABORT_EX(fmt("Failed to load DHT routing table from %s",
|
2011-08-08 12:46:10 +00:00
|
|
|
filename.c_str()));
|
2011-08-05 11:17:19 +00:00
|
|
|
}
|
2009-07-22 12:54:35 +00:00
|
|
|
char header[8];
|
|
|
|
memset(header, 0, sizeof(header));
|
|
|
|
// magic
|
2010-10-10 03:08:30 +00:00
|
|
|
header[0] = 0xa1u;
|
|
|
|
header[1] = 0xa2u;
|
2009-07-22 12:54:35 +00:00
|
|
|
// format ID
|
2010-10-10 03:08:30 +00:00
|
|
|
header[2] = 0x02u;
|
2009-07-22 12:54:35 +00:00
|
|
|
// version
|
|
|
|
header[6] = 0;
|
2010-10-10 03:08:30 +00:00
|
|
|
header[7] = 0x03u;
|
2009-07-22 12:54:35 +00:00
|
|
|
|
|
|
|
char headerCompat[8];
|
|
|
|
memset(headerCompat, 0, sizeof(headerCompat));
|
|
|
|
// magic
|
2010-10-10 03:08:30 +00:00
|
|
|
headerCompat[0] = 0xa1u;
|
|
|
|
headerCompat[1] = 0xa2u;
|
2009-07-22 12:54:35 +00:00
|
|
|
// format ID
|
2010-10-10 03:08:30 +00:00
|
|
|
headerCompat[2] = 0x02u;
|
2009-07-22 12:54:35 +00:00
|
|
|
// version
|
|
|
|
headerCompat[6] = 0;
|
2010-10-10 03:08:30 +00:00
|
|
|
headerCompat[7] = 0x02u;
|
2009-07-22 12:54:35 +00:00
|
|
|
|
2010-08-07 14:15:21 +00:00
|
|
|
char zero[18];
|
2009-07-22 12:54:35 +00:00
|
|
|
memset(zero, 0, sizeof(zero));
|
|
|
|
|
|
|
|
int version;
|
|
|
|
|
|
|
|
// If you change the code to read more than the size of buf, then
|
|
|
|
// expand the buf size here.
|
|
|
|
array_wrapper<unsigned char, 255> buf;
|
|
|
|
|
|
|
|
// header
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), 8);
|
2009-07-22 12:54:35 +00:00
|
|
|
if(memcmp(header, buf, 8) == 0) {
|
|
|
|
version = 3;
|
|
|
|
} else if(memcmp(headerCompat, buf, 8) == 0) {
|
|
|
|
version = 2;
|
|
|
|
} else {
|
|
|
|
throw DL_ABORT_EX
|
2011-08-05 13:23:53 +00:00
|
|
|
(fmt("Failed to load DHT routing table from %s. cause:%s",
|
2011-08-08 12:46:10 +00:00
|
|
|
filename.c_str(),
|
2010-11-20 09:36:14 +00:00
|
|
|
"bad header"));
|
2009-07-22 12:54:35 +00:00
|
|
|
}
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2009-07-22 12:54:35 +00:00
|
|
|
uint32_t temp32;
|
|
|
|
uint64_t temp64;
|
|
|
|
// time
|
|
|
|
if(version == 2) {
|
2011-08-06 12:35:39 +00:00
|
|
|
READ_CHECK(fp, &temp32, sizeof(temp32));
|
2010-06-21 13:51:56 +00:00
|
|
|
serializedTime_.setTimeInSec(ntohl(temp32));
|
2009-07-22 12:54:35 +00:00
|
|
|
// 4bytes reserved
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), 4);
|
2009-07-22 12:54:35 +00:00
|
|
|
} else {
|
2011-08-06 12:35:39 +00:00
|
|
|
READ_CHECK(fp, &temp64, sizeof(temp64));
|
2010-06-21 13:51:56 +00:00
|
|
|
serializedTime_.setTimeInSec(ntoh64(temp64));
|
2009-07-22 12:54:35 +00:00
|
|
|
}
|
2012-10-01 14:52:22 +00:00
|
|
|
|
2009-07-22 12:54:35 +00:00
|
|
|
// localnode
|
|
|
|
// 8bytes reserved
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), 8);
|
2009-07-22 12:54:35 +00:00
|
|
|
// localnode ID
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), DHT_ID_LENGTH);
|
2009-07-22 12:54:35 +00:00
|
|
|
SharedHandle<DHTNode> localNode(new DHTNode(buf));
|
|
|
|
// 4bytes reserved
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), 4);
|
2009-07-22 12:54:35 +00:00
|
|
|
|
|
|
|
// number of nodes
|
2011-08-06 12:35:39 +00:00
|
|
|
READ_CHECK(fp, &temp32, sizeof(temp32));
|
2009-07-22 12:54:35 +00:00
|
|
|
uint32_t numNodes = ntohl(temp32);
|
|
|
|
// 4bytes reserved
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), 4);
|
2009-07-22 12:54:35 +00:00
|
|
|
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<DHTNode> > nodes;
|
2009-07-22 12:54:35 +00:00
|
|
|
// nodes
|
2010-08-07 14:15:21 +00:00
|
|
|
const int compactlen = bittorrent::getCompactLength(family_);
|
2009-07-22 12:54:35 +00:00
|
|
|
for(size_t i = 0; i < numNodes; ++i) {
|
|
|
|
// 1byte compact peer info length
|
|
|
|
uint8_t peerInfoLen;
|
2011-08-06 12:35:39 +00:00
|
|
|
READ_CHECK(fp, &peerInfoLen, sizeof(peerInfoLen));
|
2010-08-07 14:15:21 +00:00
|
|
|
if(peerInfoLen != compactlen) {
|
2009-07-22 12:54:35 +00:00
|
|
|
// skip this entry
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), 7+48);
|
2009-07-22 12:54:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// 7bytes reserved
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), 7);
|
2010-08-07 14:15:21 +00:00
|
|
|
// compactlen bytes compact peer info
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), compactlen);
|
2010-08-07 14:15:21 +00:00
|
|
|
if(memcmp(zero, buf, compactlen) == 0) {
|
2009-07-22 12:54:35 +00:00
|
|
|
// skip this entry
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), 48-compactlen);
|
2009-07-22 12:54:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-08-03 11:44:24 +00:00
|
|
|
std::pair<std::string, uint16_t> peer =
|
2010-08-07 14:15:21 +00:00
|
|
|
bittorrent::unpackcompact(buf, family_);
|
2009-07-22 12:54:35 +00:00
|
|
|
if(peer.first.empty()) {
|
|
|
|
// skip this entry
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), 48-compactlen);
|
2009-07-22 12:54:35 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-08-07 14:15:21 +00:00
|
|
|
// 24-compactlen bytes reserved
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), 24-compactlen);
|
2009-11-11 13:06:19 +00:00
|
|
|
// node ID
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), DHT_ID_LENGTH);
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
|
2009-07-22 12:54:35 +00:00
|
|
|
SharedHandle<DHTNode> node(new DHTNode(buf));
|
|
|
|
node->setIPAddress(peer.first);
|
|
|
|
node->setPort(peer.second);
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
// 4bytes reserved
|
2011-08-06 12:35:39 +00:00
|
|
|
readBytes(fp, buf, buf.size(), 4);
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
|
2009-07-22 12:54:35 +00:00
|
|
|
nodes.push_back(node);
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
localNode_ = localNode;
|
|
|
|
nodes_ = nodes;
|
2011-08-05 13:23:53 +00:00
|
|
|
A2_LOG_INFO("DHT routing table was loaded successfully");
|
2008-02-01 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added DHT functionality, compatible with mainline.
DHT is disabled by default. To enable it, give --enable-dht to
aria2c.
You may need to specify entry point to DHT network using
--dht-entry-point. DHT uses UDP port to listen incoming message.
Use --dht-listen-port to specify port number. Make sure that
your
firewall configuration can pass through UDP traffic to the port.
The routing table is saved in $HOME/.aria2/dht.dat.
* src/DHT*
* src/BNode.{h, cc}
* src/PeerInteractionCommand.cc: enable DHT functionality for a
particular torrent.
* src/Data.cc: Rewritten ctor.
* src/OptionHandlerFactory.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/DefaultBtInteractive.cc: Send port message if dht is
enabled.
* src/RequestGroup.cc: Initialize DHT functionality. When
download
ends, remove BtContext from DHTPeerAnnounceStorage.
* src/BtPortMessage.{h, cc}: Rewritten.
* src/message.h
* src/OptionHandlerImpl.cc
* src/option_processing.cc: Added --enable-dht,
--dht-listen-port,
--dht-entry-point.
* src/Dictionary.{h, cc} (remove): New function.
* src/prefs.h
* src/DefaultBtMessageFactory.h
* src/BtHandshakeMessage.cc
* src/ActivePeerConnectionCommand.cc
* src/SocketCore.{h, cc}: Added datagram socket support.
* src/DefaultBtMessageFactory.cc
* src/BtSetup.cc: Add BtContext to DHTPeerAnnounceStorage here.
Create DHT commands.
* src/BtMessageFactory.h
* src/PeerMessageUtil.{h, cc}
2008-02-01 17:36:33 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|