mirror of https://github.com/aria2/aria2
2009-01-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Choose port for BitTorrent/DHT randomly from the specified range. * src/DHTConnectionImpl.cc * src/PeerListenCommand.ccpull/1/head
parent
e5c4b24454
commit
dbc8f687c1
|
@ -1,3 +1,9 @@
|
||||||
|
2009-01-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Choose port for BitTorrent/DHT randomly from the specified range.
|
||||||
|
* src/DHTConnectionImpl.cc
|
||||||
|
* src/PeerListenCommand.cc
|
||||||
|
|
||||||
2009-01-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-01-31 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Send HTTP Authorization header only if it is requested by the
|
Send HTTP Authorization header only if it is requested by the
|
||||||
|
|
|
@ -35,12 +35,15 @@
|
||||||
#include "DHTConnectionImpl.h"
|
#include "DHTConnectionImpl.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <deque>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "LogFactory.h"
|
#include "LogFactory.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "RecoverableException.h"
|
#include "RecoverableException.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
|
#include "SimpleRandomizer.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -51,12 +54,16 @@ DHTConnectionImpl::~DHTConnectionImpl() {}
|
||||||
|
|
||||||
bool DHTConnectionImpl::bind(uint16_t& port, IntSequence& ports)
|
bool DHTConnectionImpl::bind(uint16_t& port, IntSequence& ports)
|
||||||
{
|
{
|
||||||
while(ports.hasNext()) {
|
std::deque<int32_t> randPorts = ports.flush();
|
||||||
int sport = ports.next();
|
std::random_shuffle(randPorts.begin(), randPorts.end(),
|
||||||
if(!(0 < sport && 0 <= UINT16_MAX)) {
|
*SimpleRandomizer::getInstance().get());
|
||||||
|
|
||||||
|
for(std::deque<int32_t>::const_iterator portItr = randPorts.begin();
|
||||||
|
portItr != randPorts.end(); ++portItr) {
|
||||||
|
if(!(0 < (*portItr) && (*portItr) <= UINT16_MAX)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
port = sport;
|
port = (*portItr);
|
||||||
if(bind(port)) {
|
if(bind(port)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,8 @@
|
||||||
#include "PeerListenCommand.h"
|
#include "PeerListenCommand.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <deque>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "DownloadEngine.h"
|
#include "DownloadEngine.h"
|
||||||
#include "Peer.h"
|
#include "Peer.h"
|
||||||
|
@ -44,6 +46,7 @@
|
||||||
#include "ReceiverMSEHandshakeCommand.h"
|
#include "ReceiverMSEHandshakeCommand.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include "Socket.h"
|
#include "Socket.h"
|
||||||
|
#include "SimpleRandomizer.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -67,12 +70,17 @@ PeerListenCommand::~PeerListenCommand()
|
||||||
bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq)
|
bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq)
|
||||||
{
|
{
|
||||||
socket.reset(new SocketCore());
|
socket.reset(new SocketCore());
|
||||||
while(seq.hasNext()) {
|
|
||||||
int sport = seq.next();
|
std::deque<int32_t> randPorts = seq.flush();
|
||||||
if(!(0 < sport && sport <= UINT16_MAX)) {
|
std::random_shuffle(randPorts.begin(), randPorts.end(),
|
||||||
|
*SimpleRandomizer::getInstance().get());
|
||||||
|
|
||||||
|
for(std::deque<int32_t>::const_iterator portItr = randPorts.begin();
|
||||||
|
portItr != randPorts.end(); ++portItr) {
|
||||||
|
if(!(0 < (*portItr) && (*portItr) <= UINT16_MAX)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
port = sport;
|
port = (*portItr);
|
||||||
try {
|
try {
|
||||||
socket->bind(port);
|
socket->bind(port);
|
||||||
socket->beginListen();
|
socket->beginListen();
|
||||||
|
|
Loading…
Reference in New Issue