summaryrefslogtreecommitdiff
path: root/src/DHTMessageFactoryImpl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/DHTMessageFactoryImpl.cc')
-rw-r--r--src/DHTMessageFactoryImpl.cc112
1 files changed, 56 insertions, 56 deletions
diff --git a/src/DHTMessageFactoryImpl.cc b/src/DHTMessageFactoryImpl.cc
index bf95ff1a..27ebf211 100644
--- a/src/DHTMessageFactoryImpl.cc
+++ b/src/DHTMessageFactoryImpl.cc
@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
@@ -83,7 +83,7 @@ DHTMessageFactoryImpl::getRemoteNode(const unsigned char* id, const std::string&
}
static const BDE& getDictionary(const BDE& dict,
- const std::string& key)
+ const std::string& key)
{
const BDE& d = dict[key];
if(d.isDict()) {
@@ -95,7 +95,7 @@ static const BDE& getDictionary(const BDE& dict,
}
static const BDE& getString(const BDE& dict,
- const std::string& key)
+ const std::string& key)
{
const BDE& c = dict[key];
if(c.isString()) {
@@ -107,7 +107,7 @@ static const BDE& getString(const BDE& dict,
}
static const BDE& getInteger(const BDE& dict,
- const std::string& key)
+ const std::string& key)
{
const BDE& c = dict[key];
if(c.isInteger()) {
@@ -126,7 +126,7 @@ static const BDE& getString(const BDE& list, size_t index)
} else {
throw DL_ABORT_EX
(StringFormat("Malformed DHT message. element[%u] is not String.",
- index).str());
+ index).str());
}
}
@@ -138,12 +138,12 @@ static const BDE& getInteger(const BDE& list, size_t index)
} else {
throw DL_ABORT_EX
(StringFormat("Malformed DHT message. element[%u] is not Integer.",
- index).str());
+ index).str());
}
}
static const BDE& getList(const BDE& dict,
- const std::string& key)
+ const std::string& key)
{
const BDE& l = dict[key];
if(l.isList()) {
@@ -159,8 +159,8 @@ void DHTMessageFactoryImpl::validateID(const BDE& id) const
if(id.s().size() != DHT_ID_LENGTH) {
throw DL_ABORT_EX
(StringFormat("Malformed DHT message. Invalid ID length."
- " Expected:%d, Actual:%d",
- DHT_ID_LENGTH, id.s().size()).str());
+ " Expected:%d, Actual:%d",
+ DHT_ID_LENGTH, id.s().size()).str());
}
}
@@ -170,7 +170,7 @@ void DHTMessageFactoryImpl::validatePort(const BDE& i) const
if(!(0 < port && port < UINT16_MAX)) {
throw DL_ABORT_EX
(StringFormat("Malformed DHT message. Invalid port=%s",
- util::itos(port).c_str()).str());
+ util::itos(port).c_str()).str());
}
}
@@ -196,13 +196,13 @@ SharedHandle<DHTMessage> DHTMessageFactoryImpl::createQueryMessage
getString(aDict, DHTFindNodeMessage::TARGET_NODE);
validateID(targetNodeID);
return createFindNodeMessage(remoteNode, targetNodeID.uc(),
- transactionID.s());
+ transactionID.s());
} else if(messageType.s() == DHTGetPeersMessage::GET_PEERS) {
const BDE& infoHash =
getString(aDict, DHTGetPeersMessage::INFO_HASH);
validateID(infoHash);
return createGetPeersMessage(remoteNode,
- infoHash.uc(), transactionID.s());
+ infoHash.uc(), transactionID.s());
} else if(messageType.s() == DHTAnnouncePeerMessage::ANNOUNCE_PEER) {
const BDE& infoHash =
getString(aDict, DHTAnnouncePeerMessage::INFO_HASH);
@@ -211,20 +211,20 @@ SharedHandle<DHTMessage> DHTMessageFactoryImpl::createQueryMessage
validatePort(port);
const BDE& token = getString(aDict, DHTAnnouncePeerMessage::TOKEN);
return createAnnouncePeerMessage(remoteNode, infoHash.uc(),
- static_cast<uint16_t>(port.i()),
- token.s(), transactionID.s());
+ static_cast<uint16_t>(port.i()),
+ token.s(), transactionID.s());
} else {
throw DL_ABORT_EX
(StringFormat("Unsupported message type: %s",
- messageType.s().c_str()).str());
+ messageType.s().c_str()).str());
}
}
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createResponseMessage(const std::string& messageType,
- const BDE& dict,
- const std::string& ipaddr,
- uint16_t port)
+ const BDE& dict,
+ const std::string& ipaddr,
+ uint16_t port)
{
const BDE& transactionID = getString(dict, DHTMessage::T);
const BDE& y = getString(dict, DHTMessage::Y);
@@ -233,8 +233,8 @@ DHTMessageFactoryImpl::createResponseMessage(const std::string& messageType,
const BDE& e = getList(dict, DHTUnknownMessage::E);
if(e.size() == 2) {
_logger->info("Received Error DHT message. code=%s, msg=%s",
- util::itos(getInteger(e, 0).i()).c_str(),
- util::urlencode(getString(e, 1).s()).c_str());
+ util::itos(getInteger(e, 0).i()).c_str(),
+ util::urlencode(getString(e, 1).s()).c_str());
} else {
_logger->debug("e doesn't have 2 elements.");
}
@@ -242,7 +242,7 @@ DHTMessageFactoryImpl::createResponseMessage(const std::string& messageType,
} else if(y.s() != DHTResponseMessage::R) {
throw DL_ABORT_EX
(StringFormat("Malformed DHT message. y != r: y=%s",
- util::urlencode(y.s()).c_str()).str());
+ util::urlencode(y.s()).c_str()).str());
}
const BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
const BDE& id = getString(rDict, DHTMessage::ID);
@@ -257,14 +257,14 @@ DHTMessageFactoryImpl::createResponseMessage(const std::string& messageType,
const BDE& valuesList = rDict[DHTGetPeersReplyMessage::VALUES];
if(valuesList.isList()) {
return createGetPeersReplyMessageWithValues(remoteNode, dict,
- transactionID.s());
+ transactionID.s());
} else {
const BDE& nodes = rDict[DHTGetPeersReplyMessage::NODES];
if(nodes.isString()) {
- return createGetPeersReplyMessageWithNodes(remoteNode, dict,
- transactionID.s());
+ return createGetPeersReplyMessageWithNodes(remoteNode, dict,
+ transactionID.s());
} else {
- throw DL_ABORT_EX("Malformed DHT message: missing nodes/values");
+ throw DL_ABORT_EX("Malformed DHT message: missing nodes/values");
}
}
} else if(messageType == DHTAnnouncePeerReplyMessage::ANNOUNCE_PEER) {
@@ -293,8 +293,8 @@ SharedHandle<DHTMessage> DHTMessageFactoryImpl::createPingMessage(const SharedHa
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createPingReplyMessage(const SharedHandle<DHTNode>& remoteNode,
- const unsigned char* id,
- const std::string& transactionID)
+ const unsigned char* id,
+ const std::string& transactionID)
{
SharedHandle<DHTPingReplyMessage> m(new DHTPingReplyMessage(_localNode, remoteNode, id, transactionID));
setCommonProperty(m);
@@ -303,8 +303,8 @@ DHTMessageFactoryImpl::createPingReplyMessage(const SharedHandle<DHTNode>& remot
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createFindNodeMessage(const SharedHandle<DHTNode>& remoteNode,
- const unsigned char* targetNodeID,
- const std::string& transactionID)
+ const unsigned char* targetNodeID,
+ const std::string& transactionID)
{
SharedHandle<DHTFindNodeMessage> m(new DHTFindNodeMessage(_localNode, remoteNode, targetNodeID, transactionID));
setCommonProperty(m);
@@ -313,8 +313,8 @@ DHTMessageFactoryImpl::createFindNodeMessage(const SharedHandle<DHTNode>& remote
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createFindNodeReplyMessage(const SharedHandle<DHTNode>& remoteNode,
- const std::deque<SharedHandle<DHTNode> >& closestKNodes,
- const std::string& transactionID)
+ const std::deque<SharedHandle<DHTNode> >& closestKNodes,
+ const std::string& transactionID)
{
SharedHandle<DHTFindNodeReplyMessage> m(new DHTFindNodeReplyMessage(_localNode, remoteNode, transactionID));
m->setClosestKNodes(closestKNodes);
@@ -351,21 +351,21 @@ DHTMessageFactoryImpl::createFindNodeReplyMessage
{
const BDE& nodesData =
getString(getDictionary(dict, DHTResponseMessage::R),
- DHTFindNodeReplyMessage::NODES);
+ DHTFindNodeReplyMessage::NODES);
std::deque<SharedHandle<DHTNode> > nodes = extractNodes(nodesData.uc(),
- nodesData.s().size());
+ nodesData.s().size());
return createFindNodeReplyMessage(remoteNode, nodes, transactionID);
}
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createGetPeersMessage(const SharedHandle<DHTNode>& remoteNode,
- const unsigned char* infoHash,
- const std::string& transactionID)
+ const unsigned char* infoHash,
+ const std::string& transactionID)
{
SharedHandle<DHTGetPeersMessage> m(new DHTGetPeersMessage(_localNode,
- remoteNode,
- infoHash,
- transactionID));
+ remoteNode,
+ infoHash,
+ transactionID));
m->setPeerAnnounceStorage(_peerAnnounceStorage);
m->setTokenTracker(_tokenTracker);
setCommonProperty(m);
@@ -380,19 +380,19 @@ DHTMessageFactoryImpl::createGetPeersReplyMessageWithNodes
{
const BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
const BDE& nodesData = getString(rDict,
- DHTGetPeersReplyMessage::NODES);
+ DHTGetPeersReplyMessage::NODES);
std::deque<SharedHandle<DHTNode> > nodes = extractNodes(nodesData.uc(),
- nodesData.s().size());
+ nodesData.s().size());
const BDE& token = getString(rDict, DHTGetPeersReplyMessage::TOKEN);
return createGetPeersReplyMessage(remoteNode, nodes, token.s(),
- transactionID);
+ transactionID);
}
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createGetPeersReplyMessage(const SharedHandle<DHTNode>& remoteNode,
- const std::deque<SharedHandle<DHTNode> >& closestKNodes,
- const std::string& token,
- const std::string& transactionID)
+ const std::deque<SharedHandle<DHTNode> >& closestKNodes,
+ const std::string& token,
+ const std::string& transactionID)
{
SharedHandle<DHTGetPeersReplyMessage> m
(new DHTGetPeersReplyMessage(_localNode, remoteNode, token, transactionID));
@@ -409,28 +409,28 @@ DHTMessageFactoryImpl::createGetPeersReplyMessageWithValues
{
const BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
const BDE& valuesList = getList(rDict,
- DHTGetPeersReplyMessage::VALUES);
+ DHTGetPeersReplyMessage::VALUES);
std::deque<SharedHandle<Peer> > peers;
for(BDE::List::const_iterator i = valuesList.listBegin();
i != valuesList.listEnd(); ++i) {
const BDE& data = *i;
if(data.isString() && data.s().size() == 6) {
std::pair<std::string, uint16_t> addr =
- bittorrent::unpackcompact(data.uc());
+ bittorrent::unpackcompact(data.uc());
PeerHandle peer(new Peer(addr.first, addr.second));
peers.push_back(peer);
}
}
const BDE& token = getString(rDict, DHTGetPeersReplyMessage::TOKEN);
return createGetPeersReplyMessage(remoteNode, peers, token.s(),
- transactionID);
+ transactionID);
}
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createGetPeersReplyMessage(const SharedHandle<DHTNode>& remoteNode,
- const std::deque<SharedHandle<Peer> >& values,
- const std::string& token,
- const std::string& transactionID)
+ const std::deque<SharedHandle<Peer> >& values,
+ const std::string& token,
+ const std::string& transactionID)
{
SharedHandle<DHTGetPeersReplyMessage> m(new DHTGetPeersReplyMessage(_localNode, remoteNode, token, transactionID));
m->setValues(values);
@@ -440,10 +440,10 @@ DHTMessageFactoryImpl::createGetPeersReplyMessage(const SharedHandle<DHTNode>& r
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createAnnouncePeerMessage(const SharedHandle<DHTNode>& remoteNode,
- const unsigned char* infoHash,
- uint16_t tcpPort,
- const std::string& token,
- const std::string& transactionID)
+ const unsigned char* infoHash,
+ uint16_t tcpPort,
+ const std::string& token,
+ const std::string& transactionID)
{
SharedHandle<DHTAnnouncePeerMessage> m
(new DHTAnnouncePeerMessage(_localNode, remoteNode, infoHash, tcpPort, token, transactionID));
@@ -455,7 +455,7 @@ DHTMessageFactoryImpl::createAnnouncePeerMessage(const SharedHandle<DHTNode>& re
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createAnnouncePeerReplyMessage(const SharedHandle<DHTNode>& remoteNode,
- const std::string& transactionID)
+ const std::string& transactionID)
{
SharedHandle<DHTAnnouncePeerReplyMessage> m
(new DHTAnnouncePeerReplyMessage(_localNode, remoteNode, transactionID));
@@ -465,7 +465,7 @@ DHTMessageFactoryImpl::createAnnouncePeerReplyMessage(const SharedHandle<DHTNode
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createUnknownMessage(const unsigned char* data, size_t length,
- const std::string& ipaddr, uint16_t port)
+ const std::string& ipaddr, uint16_t port)
{
SharedHandle<DHTUnknownMessage> m