mirror of https://github.com/aria2/aria2
Use SegList<int> instead of IntSequence in PeerListenCommand::bindPort()
parent
d1667ea246
commit
e9b86f2f43
|
@ -53,7 +53,7 @@
|
|||
#include "LogFactory.h"
|
||||
#include "Logger.h"
|
||||
#include "util.h"
|
||||
#include "IntSequence.h"
|
||||
#include "SegList.h"
|
||||
#include "DHTGetPeersCommand.h"
|
||||
#include "DHTPeerAnnounceStorage.h"
|
||||
#include "DHTSetup.h"
|
||||
|
@ -193,12 +193,15 @@ void BtSetup::setup(std::vector<Command*>& commands,
|
|||
bool ret;
|
||||
uint16_t port;
|
||||
if(btReg->getTcpPort()) {
|
||||
IntSequence seq = util::parseIntRange(util::uitos(btReg->getTcpPort()));
|
||||
ret = command->bindPort(port, seq);
|
||||
SegList<int> sgl;
|
||||
int usedPort = btReg->getTcpPort();
|
||||
sgl.add(usedPort, usedPort+1);
|
||||
ret = command->bindPort(port, sgl);
|
||||
} else {
|
||||
IntSequence seq =
|
||||
util::parseIntRange(e->getOption()->get(PREF_LISTEN_PORT));
|
||||
ret = command->bindPort(port, seq);
|
||||
SegList<int> sgl;
|
||||
util::parseIntSegments(sgl, e->getOption()->get(PREF_LISTEN_PORT));
|
||||
sgl.normalize();
|
||||
ret = command->bindPort(port, sgl);
|
||||
}
|
||||
if(ret) {
|
||||
btReg->setTcpPort(port);
|
||||
|
|
|
@ -63,20 +63,19 @@ PeerListenCommand::PeerListenCommand
|
|||
|
||||
PeerListenCommand::~PeerListenCommand() {}
|
||||
|
||||
bool PeerListenCommand::bindPort(uint16_t& port, IntSequence& seq)
|
||||
bool PeerListenCommand::bindPort(uint16_t& port, SegList<int>& sgl)
|
||||
{
|
||||
socket_.reset(new SocketCore());
|
||||
|
||||
std::vector<int32_t> randPorts = seq.flush();
|
||||
std::random_shuffle(randPorts.begin(), randPorts.end(),
|
||||
std::vector<uint16_t> ports;
|
||||
while(sgl.hasNext()) {
|
||||
ports.push_back(sgl.next());
|
||||
}
|
||||
std::random_shuffle(ports.begin(), ports.end(),
|
||||
*SimpleRandomizer::getInstance().get());
|
||||
const int ipv = (family_ == AF_INET) ? 4 : 6;
|
||||
for(std::vector<int32_t>::const_iterator portItr = randPorts.begin(),
|
||||
eoi = randPorts.end(); portItr != eoi; ++portItr) {
|
||||
if(!(0 < (*portItr) && (*portItr) <= 65535)) {
|
||||
continue;
|
||||
}
|
||||
port = (*portItr);
|
||||
for(std::vector<uint16_t>::const_iterator i = ports.begin(),
|
||||
eoi = ports.end(); i != eoi; ++i) {
|
||||
port = *i;
|
||||
try {
|
||||
socket_->bind(A2STR::NIL, port, family_);
|
||||
socket_->beginListen();
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include "Command.h"
|
||||
#include "SharedHandle.h"
|
||||
#include "IntSequence.h"
|
||||
#include "SegList.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
* Binds port. If successful, the binded port number is assinged to port and
|
||||
* returns true, otherwise port is undefined and returns false.
|
||||
*/
|
||||
bool bindPort(uint16_t& port, IntSequence& seq);
|
||||
bool bindPort(uint16_t& port, SegList<int>& seq);
|
||||
|
||||
// Returns binded port
|
||||
uint16_t getPort() const;
|
||||
|
|
Loading…
Reference in New Issue