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