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>
|
||||
|
||||
Send HTTP Authorization header only if it is requested by the
|
||||
|
|
|
@ -35,12 +35,15 @@
|
|||
#include "DHTConnectionImpl.h"
|
||||
|
||||
#include <utility>
|
||||
#include <deque>
|
||||
#include <algorithm>
|
||||
|
||||
#include "LogFactory.h"
|
||||
#include "Logger.h"
|
||||
#include "RecoverableException.h"
|
||||
#include "Util.h"
|
||||
#include "Socket.h"
|
||||
#include "SimpleRandomizer.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -51,12 +54,16 @@ DHTConnectionImpl::~DHTConnectionImpl() {}
|
|||
|
||||
bool DHTConnectionImpl::bind(uint16_t& port, IntSequence& ports)
|
||||
{
|
||||
while(ports.hasNext()) {
|
||||
int sport = ports.next();
|
||||
if(!(0 < sport && 0 <= UINT16_MAX)) {
|
||||
std::deque<int32_t> randPorts = ports.flush();
|
||||
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;
|
||||
}
|
||||
port = sport;
|
||||
port = (*portItr);
|
||||
if(bind(port)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include "PeerListenCommand.h"
|
||||
|
||||
#include <utility>
|
||||
#include <deque>
|
||||
#include <algorithm>
|
||||
|
||||
#include "DownloadEngine.h"
|
||||
#include "Peer.h"
|
||||
|
@ -44,6 +46,7 @@
|
|||
#include "ReceiverMSEHandshakeCommand.h"
|
||||
#include "Logger.h"
|
||||
#include "Socket.h"
|
||||
#include "SimpleRandomizer.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -67,12 +70,17 @@ PeerListenCommand::~PeerListenCommand()
|
|||
bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq)
|
||||
{
|
||||
socket.reset(new SocketCore());
|
||||
while(seq.hasNext()) {
|
||||
int sport = seq.next();
|
||||
if(!(0 < sport && sport <= UINT16_MAX)) {
|
||||
|
||||
std::deque<int32_t> randPorts = seq.flush();
|
||||
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;
|
||||
}
|
||||
port = sport;
|
||||
port = (*portItr);
|
||||
try {
|
||||
socket->bind(port);
|
||||
socket->beginListen();
|
||||
|
|
Loading…
Reference in New Issue