mirror of https://github.com/aria2/aria2
2010-06-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Made protected member variable private. Added accessor funcs. * src/DHTAbstractMessage.cc * src/DHTAbstractMessage.h * src/DHTAnnouncePeerMessage.cc * src/DHTAnnouncePeerMessage.h * src/DHTAnnouncePeerReplyMessage.cc * src/DHTAnnouncePeerReplyMessage.h * src/DHTFindNodeMessage.cc * src/DHTFindNodeMessage.h * src/DHTFindNodeReplyMessage.cc * src/DHTFindNodeReplyMessage.h * src/DHTGetPeersMessage.cc * src/DHTGetPeersMessage.h * src/DHTGetPeersReplyMessage.cc * src/DHTGetPeersReplyMessage.h * src/DHTMessage.h * src/DHTPingMessage.cc * src/DHTPingMessage.h * src/DHTPingReplyMessage.cc * src/DHTPingReplyMessage.h * src/DHTQueryMessage.cc * src/DHTQueryMessage.h * src/DHTResponseMessage.cc * src/DHTResponseMessage.h * src/DHTUnknownMessage.cc * src/DHTUnknownMessage.h * test/MockDHTMessage.hpull/1/head
parent
6fef76979e
commit
f7001132bc
30
ChangeLog
30
ChangeLog
|
@ -1,3 +1,33 @@
|
||||||
|
2010-06-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Made protected member variable private. Added accessor funcs.
|
||||||
|
* src/DHTAbstractMessage.cc
|
||||||
|
* src/DHTAbstractMessage.h
|
||||||
|
* src/DHTAnnouncePeerMessage.cc
|
||||||
|
* src/DHTAnnouncePeerMessage.h
|
||||||
|
* src/DHTAnnouncePeerReplyMessage.cc
|
||||||
|
* src/DHTAnnouncePeerReplyMessage.h
|
||||||
|
* src/DHTFindNodeMessage.cc
|
||||||
|
* src/DHTFindNodeMessage.h
|
||||||
|
* src/DHTFindNodeReplyMessage.cc
|
||||||
|
* src/DHTFindNodeReplyMessage.h
|
||||||
|
* src/DHTGetPeersMessage.cc
|
||||||
|
* src/DHTGetPeersMessage.h
|
||||||
|
* src/DHTGetPeersReplyMessage.cc
|
||||||
|
* src/DHTGetPeersReplyMessage.h
|
||||||
|
* src/DHTMessage.h
|
||||||
|
* src/DHTPingMessage.cc
|
||||||
|
* src/DHTPingMessage.h
|
||||||
|
* src/DHTPingReplyMessage.cc
|
||||||
|
* src/DHTPingReplyMessage.h
|
||||||
|
* src/DHTQueryMessage.cc
|
||||||
|
* src/DHTQueryMessage.h
|
||||||
|
* src/DHTResponseMessage.cc
|
||||||
|
* src/DHTResponseMessage.h
|
||||||
|
* src/DHTUnknownMessage.cc
|
||||||
|
* src/DHTUnknownMessage.h
|
||||||
|
* test/MockDHTMessage.h
|
||||||
|
|
||||||
2010-06-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2010-06-11 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Removed unused member variable uuid and uuidGen
|
Removed unused member variable uuid and uuidGen
|
||||||
|
|
|
@ -56,9 +56,9 @@ DHTAbstractMessage::~DHTAbstractMessage() {}
|
||||||
std::string DHTAbstractMessage::getBencodedMessage()
|
std::string DHTAbstractMessage::getBencodedMessage()
|
||||||
{
|
{
|
||||||
BDE msgDict = BDE::dict();
|
BDE msgDict = BDE::dict();
|
||||||
msgDict[T] = _transactionID;
|
msgDict[T] = getTransactionID();
|
||||||
msgDict[Y] = getType();
|
msgDict[Y] = getType();
|
||||||
msgDict[V] = _version;
|
msgDict[V] = getVersion();
|
||||||
fillMessage(msgDict);
|
fillMessage(msgDict);
|
||||||
return bencode::encode(msgDict);
|
return bencode::encode(msgDict);
|
||||||
}
|
}
|
||||||
|
@ -69,8 +69,8 @@ bool DHTAbstractMessage::send()
|
||||||
ssize_t r = _connection->sendMessage
|
ssize_t r = _connection->sendMessage
|
||||||
(reinterpret_cast<const unsigned char*>(message.c_str()),
|
(reinterpret_cast<const unsigned char*>(message.c_str()),
|
||||||
message.size(),
|
message.size(),
|
||||||
_remoteNode->getIPAddress(),
|
getRemoteNode()->getIPAddress(),
|
||||||
_remoteNode->getPort());
|
getRemoteNode()->getPort());
|
||||||
assert(r >= 0);
|
assert(r >= 0);
|
||||||
return r == static_cast<ssize_t>(message.size());
|
return r == static_cast<ssize_t>(message.size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ class DHTMessageFactory;
|
||||||
class DHTRoutingTable;
|
class DHTRoutingTable;
|
||||||
|
|
||||||
class DHTAbstractMessage:public DHTMessage {
|
class DHTAbstractMessage:public DHTMessage {
|
||||||
protected:
|
private:
|
||||||
WeakHandle<DHTConnection> _connection;
|
WeakHandle<DHTConnection> _connection;
|
||||||
|
|
||||||
WeakHandle<DHTMessageDispatcher> _dispatcher;
|
WeakHandle<DHTMessageDispatcher> _dispatcher;
|
||||||
|
@ -64,18 +64,38 @@ public:
|
||||||
|
|
||||||
virtual bool send();
|
virtual bool send();
|
||||||
|
|
||||||
virtual std::string getType() const = 0;
|
virtual const std::string& getType() const = 0;
|
||||||
|
|
||||||
virtual void fillMessage(BDE& msgDict) = 0;
|
virtual void fillMessage(BDE& msgDict) = 0;
|
||||||
|
|
||||||
std::string getBencodedMessage();
|
std::string getBencodedMessage();
|
||||||
|
|
||||||
|
const WeakHandle<DHTConnection>& getConnection() const
|
||||||
|
{
|
||||||
|
return _connection;
|
||||||
|
}
|
||||||
|
|
||||||
void setConnection(const WeakHandle<DHTConnection>& connection);
|
void setConnection(const WeakHandle<DHTConnection>& connection);
|
||||||
|
|
||||||
|
const WeakHandle<DHTMessageDispatcher>& getMessageDispatcher() const
|
||||||
|
{
|
||||||
|
return _dispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
void setMessageDispatcher(const WeakHandle<DHTMessageDispatcher>& dispatcher);
|
void setMessageDispatcher(const WeakHandle<DHTMessageDispatcher>& dispatcher);
|
||||||
|
|
||||||
|
const WeakHandle<DHTMessageFactory>& getMessageFactory() const
|
||||||
|
{
|
||||||
|
return _factory;
|
||||||
|
}
|
||||||
|
|
||||||
void setMessageFactory(const WeakHandle<DHTMessageFactory>& factory);
|
void setMessageFactory(const WeakHandle<DHTMessageFactory>& factory);
|
||||||
|
|
||||||
|
const WeakHandle<DHTRoutingTable>& getRoutingTable() const
|
||||||
|
{
|
||||||
|
return _routingTable;
|
||||||
|
}
|
||||||
|
|
||||||
void setRoutingTable(const WeakHandle<DHTRoutingTable>& routingTable);
|
void setRoutingTable(const WeakHandle<DHTRoutingTable>& routingTable);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -60,12 +60,13 @@ const std::string DHTAnnouncePeerMessage::PORT("port");
|
||||||
|
|
||||||
const std::string DHTAnnouncePeerMessage::TOKEN("token");
|
const std::string DHTAnnouncePeerMessage::TOKEN("token");
|
||||||
|
|
||||||
DHTAnnouncePeerMessage::DHTAnnouncePeerMessage(const SharedHandle<DHTNode>& localNode,
|
DHTAnnouncePeerMessage::DHTAnnouncePeerMessage
|
||||||
const SharedHandle<DHTNode>& remoteNode,
|
(const SharedHandle<DHTNode>& localNode,
|
||||||
const unsigned char* infoHash,
|
const SharedHandle<DHTNode>& remoteNode,
|
||||||
uint16_t tcpPort,
|
const unsigned char* infoHash,
|
||||||
const std::string& token,
|
uint16_t tcpPort,
|
||||||
const std::string& transactionID):
|
const std::string& token,
|
||||||
|
const std::string& transactionID):
|
||||||
DHTQueryMessage(localNode, remoteNode, transactionID),
|
DHTQueryMessage(localNode, remoteNode, transactionID),
|
||||||
_token(token),
|
_token(token),
|
||||||
_tcpPort(tcpPort)
|
_tcpPort(tcpPort)
|
||||||
|
@ -77,25 +78,26 @@ DHTAnnouncePeerMessage::~DHTAnnouncePeerMessage() {}
|
||||||
|
|
||||||
void DHTAnnouncePeerMessage::doReceivedAction()
|
void DHTAnnouncePeerMessage::doReceivedAction()
|
||||||
{
|
{
|
||||||
_peerAnnounceStorage->addPeerAnnounce(_infoHash, _remoteNode->getIPAddress(),
|
_peerAnnounceStorage->addPeerAnnounce
|
||||||
_tcpPort);
|
(_infoHash, getRemoteNode()->getIPAddress(), _tcpPort);
|
||||||
|
|
||||||
SharedHandle<DHTMessage> reply =
|
SharedHandle<DHTMessage> reply =
|
||||||
_factory->createAnnouncePeerReplyMessage(_remoteNode, _transactionID);
|
getMessageFactory()->createAnnouncePeerReplyMessage
|
||||||
_dispatcher->addMessageToQueue(reply);
|
(getRemoteNode(), getTransactionID());
|
||||||
|
getMessageDispatcher()->addMessageToQueue(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
BDE DHTAnnouncePeerMessage::getArgument()
|
BDE DHTAnnouncePeerMessage::getArgument()
|
||||||
{
|
{
|
||||||
BDE aDict = BDE::dict();
|
BDE aDict = BDE::dict();
|
||||||
aDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
|
aDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
||||||
aDict[INFO_HASH] = BDE(_infoHash, DHT_ID_LENGTH);
|
aDict[INFO_HASH] = BDE(_infoHash, DHT_ID_LENGTH);
|
||||||
aDict[PORT] = _tcpPort;
|
aDict[PORT] = _tcpPort;
|
||||||
aDict[TOKEN] = _token;
|
aDict[TOKEN] = _token;
|
||||||
return aDict;
|
return aDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DHTAnnouncePeerMessage::getMessageType() const
|
const std::string& DHTAnnouncePeerMessage::getMessageType() const
|
||||||
{
|
{
|
||||||
return ANNOUNCE_PEER;
|
return ANNOUNCE_PEER;
|
||||||
}
|
}
|
||||||
|
@ -103,22 +105,24 @@ std::string DHTAnnouncePeerMessage::getMessageType() const
|
||||||
void DHTAnnouncePeerMessage::validate() const
|
void DHTAnnouncePeerMessage::validate() const
|
||||||
{
|
{
|
||||||
if(!_tokenTracker->validateToken(_token, _infoHash,
|
if(!_tokenTracker->validateToken(_token, _infoHash,
|
||||||
_remoteNode->getIPAddress(),
|
getRemoteNode()->getIPAddress(),
|
||||||
_remoteNode->getPort())) {
|
getRemoteNode()->getPort())) {
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(StringFormat("Invalid token=%s from %s:%u",
|
(StringFormat("Invalid token=%s from %s:%u",
|
||||||
util::toHex(_token).c_str(),
|
util::toHex(_token).c_str(),
|
||||||
_remoteNode->getIPAddress().c_str(),
|
getRemoteNode()->getIPAddress().c_str(),
|
||||||
_remoteNode->getPort()).str());
|
getRemoteNode()->getPort()).str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTAnnouncePeerMessage::setPeerAnnounceStorage(const WeakHandle<DHTPeerAnnounceStorage>& storage)
|
void DHTAnnouncePeerMessage::setPeerAnnounceStorage
|
||||||
|
(const WeakHandle<DHTPeerAnnounceStorage>& storage)
|
||||||
{
|
{
|
||||||
_peerAnnounceStorage = storage;
|
_peerAnnounceStorage = storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTAnnouncePeerMessage::setTokenTracker(const WeakHandle<DHTTokenTracker>& tokenTracker)
|
void DHTAnnouncePeerMessage::setTokenTracker
|
||||||
|
(const WeakHandle<DHTTokenTracker>& tokenTracker)
|
||||||
{
|
{
|
||||||
_tokenTracker = tokenTracker;
|
_tokenTracker = tokenTracker;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ public:
|
||||||
|
|
||||||
virtual BDE getArgument();
|
virtual BDE getArgument();
|
||||||
|
|
||||||
virtual std::string getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
virtual void validate() const;
|
virtual void validate() const;
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,10 @@ namespace aria2 {
|
||||||
|
|
||||||
const std::string DHTAnnouncePeerReplyMessage::ANNOUNCE_PEER("announce_peer");
|
const std::string DHTAnnouncePeerReplyMessage::ANNOUNCE_PEER("announce_peer");
|
||||||
|
|
||||||
DHTAnnouncePeerReplyMessage::DHTAnnouncePeerReplyMessage(const SharedHandle<DHTNode>& localNode,
|
DHTAnnouncePeerReplyMessage::DHTAnnouncePeerReplyMessage
|
||||||
const SharedHandle<DHTNode>& remoteNode,
|
(const SharedHandle<DHTNode>& localNode,
|
||||||
const std::string& transactionID):
|
const SharedHandle<DHTNode>& remoteNode,
|
||||||
|
const std::string& transactionID):
|
||||||
DHTResponseMessage(localNode, remoteNode, transactionID) {}
|
DHTResponseMessage(localNode, remoteNode, transactionID) {}
|
||||||
|
|
||||||
DHTAnnouncePeerReplyMessage::~DHTAnnouncePeerReplyMessage() {}
|
DHTAnnouncePeerReplyMessage::~DHTAnnouncePeerReplyMessage() {}
|
||||||
|
@ -52,15 +53,13 @@ void DHTAnnouncePeerReplyMessage::doReceivedAction() {}
|
||||||
BDE DHTAnnouncePeerReplyMessage::getResponse()
|
BDE DHTAnnouncePeerReplyMessage::getResponse()
|
||||||
{
|
{
|
||||||
BDE rDict = BDE::dict();
|
BDE rDict = BDE::dict();
|
||||||
rDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
|
rDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
||||||
return rDict;
|
return rDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DHTAnnouncePeerReplyMessage::getMessageType() const
|
const std::string& DHTAnnouncePeerReplyMessage::getMessageType() const
|
||||||
{
|
{
|
||||||
return ANNOUNCE_PEER;
|
return ANNOUNCE_PEER;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTAnnouncePeerReplyMessage::validate() const {}
|
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -51,9 +51,7 @@ public:
|
||||||
|
|
||||||
virtual BDE getResponse();
|
virtual BDE getResponse();
|
||||||
|
|
||||||
virtual std::string getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
virtual void validate() const;
|
|
||||||
|
|
||||||
static const std::string ANNOUNCE_PEER;
|
static const std::string ANNOUNCE_PEER;
|
||||||
};
|
};
|
||||||
|
|
|
@ -64,27 +64,26 @@ DHTFindNodeMessage::~DHTFindNodeMessage() {}
|
||||||
void DHTFindNodeMessage::doReceivedAction()
|
void DHTFindNodeMessage::doReceivedAction()
|
||||||
{
|
{
|
||||||
std::vector<SharedHandle<DHTNode> > nodes;
|
std::vector<SharedHandle<DHTNode> > nodes;
|
||||||
_routingTable->getClosestKNodes(nodes, _targetNodeID);
|
getRoutingTable()->getClosestKNodes(nodes, _targetNodeID);
|
||||||
SharedHandle<DHTMessage> reply =
|
SharedHandle<DHTMessage> reply =
|
||||||
_factory->createFindNodeReplyMessage(_remoteNode, nodes, _transactionID);
|
getMessageFactory()->createFindNodeReplyMessage
|
||||||
_dispatcher->addMessageToQueue(reply);
|
(getRemoteNode(), nodes, getTransactionID());
|
||||||
|
getMessageDispatcher()->addMessageToQueue(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
BDE DHTFindNodeMessage::getArgument()
|
BDE DHTFindNodeMessage::getArgument()
|
||||||
{
|
{
|
||||||
BDE aDict = BDE::dict();
|
BDE aDict = BDE::dict();
|
||||||
aDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
|
aDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
||||||
aDict[TARGET_NODE] = BDE(_targetNodeID, DHT_ID_LENGTH);
|
aDict[TARGET_NODE] = BDE(_targetNodeID, DHT_ID_LENGTH);
|
||||||
return aDict;
|
return aDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DHTFindNodeMessage::getMessageType() const
|
const std::string& DHTFindNodeMessage::getMessageType() const
|
||||||
{
|
{
|
||||||
return FIND_NODE;
|
return FIND_NODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTFindNodeMessage::validate() const {}
|
|
||||||
|
|
||||||
std::string DHTFindNodeMessage::toStringOptional() const
|
std::string DHTFindNodeMessage::toStringOptional() const
|
||||||
{
|
{
|
||||||
return "targetNodeID="+util::toHex(_targetNodeID, DHT_ID_LENGTH);
|
return "targetNodeID="+util::toHex(_targetNodeID, DHT_ID_LENGTH);
|
||||||
|
|
|
@ -57,9 +57,7 @@ public:
|
||||||
|
|
||||||
virtual BDE getArgument();
|
virtual BDE getArgument();
|
||||||
|
|
||||||
virtual std::string getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
virtual void validate() const;
|
|
||||||
|
|
||||||
const unsigned char* getTargetNodeID() const
|
const unsigned char* getTargetNodeID() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,9 +52,10 @@ const std::string DHTFindNodeReplyMessage::FIND_NODE("find_node");
|
||||||
|
|
||||||
const std::string DHTFindNodeReplyMessage::NODES("nodes");
|
const std::string DHTFindNodeReplyMessage::NODES("nodes");
|
||||||
|
|
||||||
DHTFindNodeReplyMessage::DHTFindNodeReplyMessage(const SharedHandle<DHTNode>& localNode,
|
DHTFindNodeReplyMessage::DHTFindNodeReplyMessage
|
||||||
const SharedHandle<DHTNode>& remoteNode,
|
(const SharedHandle<DHTNode>& localNode,
|
||||||
const std::string& transactionID):
|
const SharedHandle<DHTNode>& remoteNode,
|
||||||
|
const std::string& transactionID):
|
||||||
DHTResponseMessage(localNode, remoteNode, transactionID) {}
|
DHTResponseMessage(localNode, remoteNode, transactionID) {}
|
||||||
|
|
||||||
DHTFindNodeReplyMessage::~DHTFindNodeReplyMessage() {}
|
DHTFindNodeReplyMessage::~DHTFindNodeReplyMessage() {}
|
||||||
|
@ -63,8 +64,8 @@ void DHTFindNodeReplyMessage::doReceivedAction()
|
||||||
{
|
{
|
||||||
for(std::vector<SharedHandle<DHTNode> >::iterator i = _closestKNodes.begin(),
|
for(std::vector<SharedHandle<DHTNode> >::iterator i = _closestKNodes.begin(),
|
||||||
eoi = _closestKNodes.end(); i != eoi; ++i) {
|
eoi = _closestKNodes.end(); i != eoi; ++i) {
|
||||||
if(memcmp((*i)->getID(), _localNode->getID(), DHT_ID_LENGTH) != 0) {
|
if(memcmp((*i)->getID(), getLocalNode()->getID(), DHT_ID_LENGTH) != 0) {
|
||||||
_routingTable->addNode(*i);
|
getRoutingTable()->addNode(*i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,7 +73,7 @@ void DHTFindNodeReplyMessage::doReceivedAction()
|
||||||
BDE DHTFindNodeReplyMessage::getResponse()
|
BDE DHTFindNodeReplyMessage::getResponse()
|
||||||
{
|
{
|
||||||
BDE aDict = BDE::dict();
|
BDE aDict = BDE::dict();
|
||||||
aDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
|
aDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
unsigned char buffer[DHTBucket::K*26];
|
unsigned char buffer[DHTBucket::K*26];
|
||||||
// TODO if _closestKNodes.size() > DHTBucket::K ??
|
// TODO if _closestKNodes.size() > DHTBucket::K ??
|
||||||
|
@ -90,13 +91,11 @@ BDE DHTFindNodeReplyMessage::getResponse()
|
||||||
return aDict;
|
return aDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DHTFindNodeReplyMessage::getMessageType() const
|
const std::string& DHTFindNodeReplyMessage::getMessageType() const
|
||||||
{
|
{
|
||||||
return FIND_NODE;
|
return FIND_NODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTFindNodeReplyMessage::validate() const {}
|
|
||||||
|
|
||||||
void DHTFindNodeReplyMessage::setClosestKNodes
|
void DHTFindNodeReplyMessage::setClosestKNodes
|
||||||
(const std::vector<SharedHandle<DHTNode> >& closestKNodes)
|
(const std::vector<SharedHandle<DHTNode> >& closestKNodes)
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,9 +56,7 @@ public:
|
||||||
|
|
||||||
virtual BDE getResponse();
|
virtual BDE getResponse();
|
||||||
|
|
||||||
virtual std::string getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
virtual void validate() const;
|
|
||||||
|
|
||||||
const std::vector<SharedHandle<DHTNode> >& getClosestKNodes() const
|
const std::vector<SharedHandle<DHTNode> >& getClosestKNodes() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,48 +66,47 @@ DHTGetPeersMessage::~DHTGetPeersMessage() {}
|
||||||
|
|
||||||
void DHTGetPeersMessage::doReceivedAction()
|
void DHTGetPeersMessage::doReceivedAction()
|
||||||
{
|
{
|
||||||
std::string token = _tokenTracker->generateToken(_infoHash,
|
std::string token = _tokenTracker->generateToken
|
||||||
_remoteNode->getIPAddress(),
|
(_infoHash, getRemoteNode()->getIPAddress(), getRemoteNode()->getPort());
|
||||||
_remoteNode->getPort());
|
|
||||||
// Check to see localhost has the contents which has same infohash
|
// Check to see localhost has the contents which has same infohash
|
||||||
std::vector<SharedHandle<Peer> > peers;
|
std::vector<SharedHandle<Peer> > peers;
|
||||||
_peerAnnounceStorage->getPeers(peers, _infoHash);
|
_peerAnnounceStorage->getPeers(peers, _infoHash);
|
||||||
SharedHandle<DHTMessage> reply;
|
SharedHandle<DHTMessage> reply;
|
||||||
if(peers.empty()) {
|
if(peers.empty()) {
|
||||||
std::vector<SharedHandle<DHTNode> > nodes;
|
std::vector<SharedHandle<DHTNode> > nodes;
|
||||||
_routingTable->getClosestKNodes(nodes, _infoHash);
|
getRoutingTable()->getClosestKNodes(nodes, _infoHash);
|
||||||
reply =
|
reply =
|
||||||
_factory->createGetPeersReplyMessage(_remoteNode, nodes, token,
|
getMessageFactory()->createGetPeersReplyMessage
|
||||||
_transactionID);
|
(getRemoteNode(), nodes, token, getTransactionID());
|
||||||
} else {
|
} else {
|
||||||
reply =
|
reply =
|
||||||
_factory->createGetPeersReplyMessage(_remoteNode, peers, token,
|
getMessageFactory()->createGetPeersReplyMessage
|
||||||
_transactionID);
|
(getRemoteNode(), peers, token, getTransactionID());
|
||||||
}
|
}
|
||||||
_dispatcher->addMessageToQueue(reply);
|
getMessageDispatcher()->addMessageToQueue(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
BDE DHTGetPeersMessage::getArgument()
|
BDE DHTGetPeersMessage::getArgument()
|
||||||
{
|
{
|
||||||
BDE aDict = BDE::dict();
|
BDE aDict = BDE::dict();
|
||||||
aDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
|
aDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
||||||
aDict[INFO_HASH] = BDE(_infoHash, DHT_ID_LENGTH);
|
aDict[INFO_HASH] = BDE(_infoHash, DHT_ID_LENGTH);
|
||||||
return aDict;
|
return aDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DHTGetPeersMessage::getMessageType() const
|
const std::string& DHTGetPeersMessage::getMessageType() const
|
||||||
{
|
{
|
||||||
return GET_PEERS;
|
return GET_PEERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTGetPeersMessage::validate() const {}
|
void DHTGetPeersMessage::setPeerAnnounceStorage
|
||||||
|
(const WeakHandle<DHTPeerAnnounceStorage>& storage)
|
||||||
void DHTGetPeersMessage::setPeerAnnounceStorage(const WeakHandle<DHTPeerAnnounceStorage>& storage)
|
|
||||||
{
|
{
|
||||||
_peerAnnounceStorage = storage;
|
_peerAnnounceStorage = storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTGetPeersMessage::setTokenTracker(const WeakHandle<DHTTokenTracker>& tokenTracker)
|
void DHTGetPeersMessage::setTokenTracker
|
||||||
|
(const WeakHandle<DHTTokenTracker>& tokenTracker)
|
||||||
{
|
{
|
||||||
_tokenTracker = tokenTracker;
|
_tokenTracker = tokenTracker;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,17 +65,15 @@ public:
|
||||||
|
|
||||||
virtual BDE getArgument();
|
virtual BDE getArgument();
|
||||||
|
|
||||||
virtual std::string getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
virtual void validate() const;
|
|
||||||
|
|
||||||
const unsigned char* getInfoHash() const
|
const unsigned char* getInfoHash() const
|
||||||
{
|
{
|
||||||
return _infoHash;
|
return _infoHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPeerAnnounceStorage(const WeakHandle<DHTPeerAnnounceStorage>& storage);
|
void setPeerAnnounceStorage
|
||||||
|
(const WeakHandle<DHTPeerAnnounceStorage>& storage);
|
||||||
|
|
||||||
void setTokenTracker(const WeakHandle<DHTTokenTracker>& tokenTracker);
|
void setTokenTracker(const WeakHandle<DHTTokenTracker>& tokenTracker);
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ void DHTGetPeersReplyMessage::doReceivedAction()
|
||||||
BDE DHTGetPeersReplyMessage::getResponse()
|
BDE DHTGetPeersReplyMessage::getResponse()
|
||||||
{
|
{
|
||||||
BDE rDict = BDE::dict();
|
BDE rDict = BDE::dict();
|
||||||
rDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
|
rDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
||||||
rDict[TOKEN] = _token;
|
rDict[TOKEN] = _token;
|
||||||
if(_values.empty()) {
|
if(_values.empty()) {
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
@ -128,13 +128,11 @@ BDE DHTGetPeersReplyMessage::getResponse()
|
||||||
return rDict;
|
return rDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DHTGetPeersReplyMessage::getMessageType() const
|
const std::string& DHTGetPeersReplyMessage::getMessageType() const
|
||||||
{
|
{
|
||||||
return GET_PEERS;
|
return GET_PEERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTGetPeersReplyMessage::validate() const {}
|
|
||||||
|
|
||||||
std::string DHTGetPeersReplyMessage::toStringOptional() const
|
std::string DHTGetPeersReplyMessage::toStringOptional() const
|
||||||
{
|
{
|
||||||
return strconcat("token=", util::toHex(_token),
|
return strconcat("token=", util::toHex(_token),
|
||||||
|
|
|
@ -66,9 +66,7 @@ public:
|
||||||
|
|
||||||
virtual BDE getResponse();
|
virtual BDE getResponse();
|
||||||
|
|
||||||
virtual std::string getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
virtual void validate() const;
|
|
||||||
|
|
||||||
const std::vector<SharedHandle<DHTNode> >& getClosestKNodes() const
|
const std::vector<SharedHandle<DHTNode> >& getClosestKNodes() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace aria2 {
|
||||||
class DHTNode;
|
class DHTNode;
|
||||||
|
|
||||||
class DHTMessage {
|
class DHTMessage {
|
||||||
protected:
|
private:
|
||||||
SharedHandle<DHTNode> _localNode;
|
SharedHandle<DHTNode> _localNode;
|
||||||
|
|
||||||
SharedHandle<DHTNode> _remoteNode;
|
SharedHandle<DHTNode> _remoteNode;
|
||||||
|
@ -85,12 +85,17 @@ public:
|
||||||
|
|
||||||
virtual bool isReply() const = 0;
|
virtual bool isReply() const = 0;
|
||||||
|
|
||||||
virtual void validate() const = 0;
|
virtual void validate() const {}
|
||||||
|
|
||||||
virtual std::string getMessageType() const = 0;
|
virtual const std::string& getMessageType() const = 0;
|
||||||
|
|
||||||
virtual std::string toString() const = 0;
|
virtual std::string toString() const = 0;
|
||||||
|
|
||||||
|
const std::string& getVersion() const
|
||||||
|
{
|
||||||
|
return _version;
|
||||||
|
}
|
||||||
|
|
||||||
void setVersion(const std::string& version)
|
void setVersion(const std::string& version)
|
||||||
{
|
{
|
||||||
_version = version;
|
_version = version;
|
||||||
|
|
|
@ -54,22 +54,22 @@ DHTPingMessage::~DHTPingMessage() {}
|
||||||
void DHTPingMessage::doReceivedAction()
|
void DHTPingMessage::doReceivedAction()
|
||||||
{
|
{
|
||||||
// send back ping reply
|
// send back ping reply
|
||||||
SharedHandle<DHTMessage> reply = _factory->createPingReplyMessage(_remoteNode, _localNode->getID(), _transactionID);
|
SharedHandle<DHTMessage> reply =
|
||||||
_dispatcher->addMessageToQueue(reply);
|
getMessageFactory()->createPingReplyMessage
|
||||||
|
(getRemoteNode(), getLocalNode()->getID(), getTransactionID());
|
||||||
|
getMessageDispatcher()->addMessageToQueue(reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
BDE DHTPingMessage::getArgument()
|
BDE DHTPingMessage::getArgument()
|
||||||
{
|
{
|
||||||
BDE aDict = BDE::dict();
|
BDE aDict = BDE::dict();
|
||||||
aDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
|
aDict[DHTMessage::ID] = BDE(getLocalNode()->getID(), DHT_ID_LENGTH);
|
||||||
return aDict;
|
return aDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DHTPingMessage::getMessageType() const
|
const std::string& DHTPingMessage::getMessageType() const
|
||||||
{
|
{
|
||||||
return PING;
|
return PING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTPingMessage::validate() const {}
|
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -52,9 +52,7 @@ public:
|
||||||
|
|
||||||
virtual BDE getArgument();
|
virtual BDE getArgument();
|
||||||
|
|
||||||
virtual std::string getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
virtual void validate() const;
|
|
||||||
|
|
||||||
static const std::string PING;
|
static const std::string PING;
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,11 +63,9 @@ BDE DHTPingReplyMessage::getResponse()
|
||||||
return rDict;
|
return rDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DHTPingReplyMessage::getMessageType() const
|
const std::string& DHTPingReplyMessage::getMessageType() const
|
||||||
{
|
{
|
||||||
return PING;
|
return PING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTPingReplyMessage::validate() const {}
|
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -55,9 +55,7 @@ public:
|
||||||
|
|
||||||
virtual BDE getResponse();
|
virtual BDE getResponse();
|
||||||
|
|
||||||
virtual std::string getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
virtual void validate() const;
|
|
||||||
|
|
||||||
const unsigned char* getRemoteID()
|
const unsigned char* getRemoteID()
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,7 +51,7 @@ DHTQueryMessage::DHTQueryMessage(const SharedHandle<DHTNode>& localNode,
|
||||||
|
|
||||||
DHTQueryMessage::~DHTQueryMessage() {}
|
DHTQueryMessage::~DHTQueryMessage() {}
|
||||||
|
|
||||||
std::string DHTQueryMessage::getType() const
|
const std::string& DHTQueryMessage::getType() const
|
||||||
{
|
{
|
||||||
return Q;
|
return Q;
|
||||||
}
|
}
|
||||||
|
@ -71,14 +71,14 @@ std::string DHTQueryMessage::toString() const
|
||||||
{
|
{
|
||||||
std::string s = strconcat
|
std::string s = strconcat
|
||||||
("dht query ", getMessageType(),
|
("dht query ", getMessageType(),
|
||||||
" TransactionID=", util::toHex(_transactionID),
|
" TransactionID=", util::toHex(getTransactionID()),
|
||||||
" Remote:", _remoteNode->getIPAddress(),
|
" Remote:", getRemoteNode()->getIPAddress(),
|
||||||
":", util::uitos(_remoteNode->getPort()),
|
":", util::uitos(getRemoteNode()->getPort()),
|
||||||
", id=", util::toHex(_remoteNode->getID(), DHT_ID_LENGTH),
|
", id=", util::toHex(getRemoteNode()->getID(), DHT_ID_LENGTH),
|
||||||
", ");
|
", ");
|
||||||
if(!_version.empty()) {
|
if(!getVersion().empty()) {
|
||||||
s += "v=";
|
s += "v=";
|
||||||
s += util::torrentPercentEncode(_version);
|
s += util::torrentPercentEncode(getVersion());
|
||||||
s += ", ";
|
s += ", ";
|
||||||
}
|
}
|
||||||
s += toStringOptional();
|
s += toStringOptional();
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
|
|
||||||
virtual ~DHTQueryMessage();
|
virtual ~DHTQueryMessage();
|
||||||
|
|
||||||
virtual std::string getType() const;
|
virtual const std::string& getType() const;
|
||||||
|
|
||||||
virtual void fillMessage(BDE& msgDict);
|
virtual void fillMessage(BDE& msgDict);
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ DHTResponseMessage::DHTResponseMessage(const SharedHandle<DHTNode>& localNode,
|
||||||
|
|
||||||
DHTResponseMessage::~DHTResponseMessage() {}
|
DHTResponseMessage::~DHTResponseMessage() {}
|
||||||
|
|
||||||
std::string DHTResponseMessage::getType() const
|
const std::string& DHTResponseMessage::getType() const
|
||||||
{
|
{
|
||||||
return R;
|
return R;
|
||||||
}
|
}
|
||||||
|
@ -68,14 +68,14 @@ std::string DHTResponseMessage::toString() const
|
||||||
{
|
{
|
||||||
std::string s = strconcat
|
std::string s = strconcat
|
||||||
("dht response ", getMessageType(),
|
("dht response ", getMessageType(),
|
||||||
" TransactionID=", util::toHex(_transactionID),
|
" TransactionID=", util::toHex(getTransactionID()),
|
||||||
" Remote:", _remoteNode->getIPAddress(),
|
" Remote:", getRemoteNode()->getIPAddress(),
|
||||||
":", util::uitos(_remoteNode->getPort()),
|
":", util::uitos(getRemoteNode()->getPort()),
|
||||||
", id=", util::toHex(_remoteNode->getID(), DHT_ID_LENGTH),
|
", id=", util::toHex(getRemoteNode()->getID(), DHT_ID_LENGTH),
|
||||||
", ");
|
", ");
|
||||||
if(!_version.empty()) {
|
if(!getVersion().empty()) {
|
||||||
s += "v=";
|
s += "v=";
|
||||||
s += util::torrentPercentEncode(_version);
|
s += util::torrentPercentEncode(getVersion());
|
||||||
s += ", ";
|
s += ", ";
|
||||||
}
|
}
|
||||||
s += toStringOptional();
|
s += toStringOptional();
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
|
|
||||||
virtual ~DHTResponseMessage();
|
virtual ~DHTResponseMessage();
|
||||||
|
|
||||||
virtual std::string getType() const;
|
virtual const std::string& getType() const;
|
||||||
|
|
||||||
virtual void fillMessage(BDE& msgDict);
|
virtual void fillMessage(BDE& msgDict);
|
||||||
|
|
||||||
|
|
|
@ -77,9 +77,7 @@ bool DHTUnknownMessage::isReply() const
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DHTUnknownMessage::validate() const {}
|
const std::string& DHTUnknownMessage::getMessageType() const
|
||||||
|
|
||||||
std::string DHTUnknownMessage::getMessageType() const
|
|
||||||
{
|
{
|
||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,10 +62,8 @@ public:
|
||||||
// always return false
|
// always return false
|
||||||
virtual bool isReply() const;
|
virtual bool isReply() const;
|
||||||
|
|
||||||
virtual void validate() const;
|
|
||||||
|
|
||||||
// returns "unknown"
|
// returns "unknown"
|
||||||
virtual std::string getMessageType() const;
|
virtual const std::string& getMessageType() const;
|
||||||
|
|
||||||
// show some sample bytes
|
// show some sample bytes
|
||||||
virtual std::string toString() const;
|
virtual std::string toString() const;
|
||||||
|
|
|
@ -38,11 +38,9 @@ public:
|
||||||
|
|
||||||
void setReply(bool f) { _isReply = f; }
|
void setReply(bool f) { _isReply = f; }
|
||||||
|
|
||||||
virtual std::string getMessageType() const { return _messageType; }
|
virtual const std::string& getMessageType() const { return _messageType; }
|
||||||
|
|
||||||
virtual std::string toString() const { return "MockDHTMessage"; }
|
virtual std::string toString() const { return "MockDHTMessage"; }
|
||||||
|
|
||||||
virtual void validate() const {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
Loading…
Reference in New Issue