summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-04-27 11:45:22 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-04-27 11:45:22 +0000
commit49b4cfbfcdf615dc01d748179c6b67e78bd5362e (patch)
tree607214c9048ae8ba51e38a6c5daa1b99e376d218 /src
parentd58742ad21407362db34d508ceef8b7b21088bb1 (diff)
2009-04-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Put BDE in aria2 namespace. BDE will also be used to store xml-rpc request. * src/AnnounceList.cc * src/AnnounceList.h * src/BDE.cc: Added * src/BDE.h: Added * 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/DHTMessageFactory.h * src/DHTMessageFactoryImpl.cc * src/DHTMessageFactoryImpl.h * src/DHTMessageReceiver.cc * src/DHTMessageTracker.cc * src/DHTMessageTracker.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/DefaultBtAnnounce.cc * src/DefaultBtContext.cc * src/DefaultBtContext.h * src/HandshakeExtensionMessage.cc * src/Makefile.am * src/PeerListProcessor.h * src/UTPexExtensionMessage.cc * src/bencode.cc * src/bencode.h * test/AnnounceListTest.cc * test/BDETest.cc: Added * test/BencodeTest.cc * test/DHTAnnouncePeerMessageTest.cc * test/DHTAnnouncePeerReplyMessageTest.cc * test/DHTFindNodeMessageTest.cc * test/DHTFindNodeReplyMessageTest.cc * test/DHTGetPeersMessageTest.cc * test/DHTGetPeersReplyMessageTest.cc * test/DHTMessageFactoryImplTest.cc * test/DHTMessageTrackerTest.cc * test/DHTPingMessageTest.cc * test/DHTPingReplyMessageTest.cc * test/Makefile.am * test/MockDHTMessageFactory.h * test/PeerListProcessorTest.cc
Diffstat (limited to 'src')
-rw-r--r--src/AnnounceList.cc12
-rw-r--r--src/AnnounceList.h6
-rw-r--r--src/BDE.cc223
-rw-r--r--src/BDE.h431
-rw-r--r--src/DHTAbstractMessage.cc2
-rw-r--r--src/DHTAbstractMessage.h4
-rw-r--r--src/DHTAnnouncePeerMessage.cc8
-rw-r--r--src/DHTAnnouncePeerMessage.h2
-rw-r--r--src/DHTAnnouncePeerReplyMessage.cc6
-rw-r--r--src/DHTAnnouncePeerReplyMessage.h2
-rw-r--r--src/DHTFindNodeMessage.cc8
-rw-r--r--src/DHTFindNodeMessage.h2
-rw-r--r--src/DHTFindNodeReplyMessage.cc8
-rw-r--r--src/DHTFindNodeReplyMessage.h2
-rw-r--r--src/DHTGetPeersMessage.cc8
-rw-r--r--src/DHTGetPeersMessage.h2
-rw-r--r--src/DHTGetPeersReplyMessage.cc12
-rw-r--r--src/DHTGetPeersReplyMessage.h2
-rw-r--r--src/DHTMessageFactory.h6
-rw-r--r--src/DHTMessageFactoryImpl.cc92
-rw-r--r--src/DHTMessageFactoryImpl.h14
-rw-r--r--src/DHTMessageReceiver.cc4
-rw-r--r--src/DHTMessageTracker.cc4
-rw-r--r--src/DHTMessageTracker.h4
-rw-r--r--src/DHTPingMessage.cc6
-rw-r--r--src/DHTPingMessage.h2
-rw-r--r--src/DHTPingReplyMessage.cc6
-rw-r--r--src/DHTPingReplyMessage.h2
-rw-r--r--src/DHTQueryMessage.cc2
-rw-r--r--src/DHTQueryMessage.h4
-rw-r--r--src/DHTResponseMessage.cc2
-rw-r--r--src/DHTResponseMessage.h4
-rw-r--r--src/DefaultBtAnnounce.cc18
-rw-r--r--src/DefaultBtContext.cc60
-rw-r--r--src/DefaultBtContext.h17
-rw-r--r--src/HandshakeExtensionMessage.cc14
-rw-r--r--src/Makefile.am3
-rw-r--r--src/Makefile.in37
-rw-r--r--src/PeerListProcessor.h14
-rw-r--r--src/UTPexExtensionMessage.cc8
-rw-r--r--src/bencode.cc185
-rw-r--r--src/bencode.h386
42 files changed, 857 insertions, 777 deletions
diff --git a/src/AnnounceList.cc b/src/AnnounceList.cc
index 0896bdae..9cbee1e0 100644
--- a/src/AnnounceList.cc
+++ b/src/AnnounceList.cc
@@ -48,7 +48,7 @@ const std::string AnnounceList::STOPPED("stopped");
const std::string AnnounceList::COMPLETED("completed");
-AnnounceList::AnnounceList(const bencode::BDE& announceList):
+AnnounceList::AnnounceList(const BDE& announceList):
currentTrackerInitialized(false) {
reconfigure(announceList);
}
@@ -58,19 +58,19 @@ AnnounceList::AnnounceList(const AnnounceTiers& announceTiers):
resetIterator();
}
-void AnnounceList::reconfigure(const bencode::BDE& announceList)
+void AnnounceList::reconfigure(const BDE& announceList)
{
if(announceList.isList()) {
- for(bencode::BDE::List::const_iterator itr = announceList.listBegin();
+ for(BDE::List::const_iterator itr = announceList.listBegin();
itr != announceList.listEnd(); ++itr) {
- const bencode::BDE& elemList = *itr;
+ const BDE& elemList = *itr;
if(!elemList.isList()) {
continue;
}
std::deque<std::string> urls;
- for(bencode::BDE::List::const_iterator elemItr = elemList.listBegin();
+ for(BDE::List::const_iterator elemItr = elemList.listBegin();
elemItr != elemList.listEnd(); ++elemItr) {
- const bencode::BDE& data = *elemItr;
+ const BDE& data = *elemItr;
if(data.isString()) {
urls.push_back(data.s());
}
diff --git a/src/AnnounceList.h b/src/AnnounceList.h
index 4c7dc5ce..5de67fdd 100644
--- a/src/AnnounceList.h
+++ b/src/AnnounceList.h
@@ -41,9 +41,7 @@
namespace aria2 {
-namespace bencode {
class BDE;
-} // namespace bencode
class AnnounceList {
public:
@@ -57,10 +55,10 @@ private:
void setCurrentTier(const std::deque<SharedHandle<AnnounceTier> >::iterator& itr);
public:
AnnounceList():currentTrackerInitialized(false) {}
- AnnounceList(const bencode::BDE& announceList);
+ AnnounceList(const BDE& announceList);
AnnounceList(const std::deque<SharedHandle<AnnounceTier> >& tiers);
- void reconfigure(const bencode::BDE& announceList);
+ void reconfigure(const BDE& announceList);
void reconfigure(const std::string& url);
size_t countTier() const {
diff --git a/src/BDE.cc b/src/BDE.cc
new file mode 100644
index 00000000..ad6b226e
--- /dev/null
+++ b/src/BDE.cc
@@ -0,0 +1,223 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2009 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you
+ * do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+
+#include "BDE.h"
+
+namespace aria2 {
+
+const BDE BDE::none;
+
+BDE::BDE():_type(TYPE_NONE) {}
+
+BDE::BDE(Integer integer):_type(TYPE_INTEGER),
+ _bobject(new BInteger(integer)) {}
+
+
+BDE::BDE(const std::string& string):_type(TYPE_STRING),
+ _bobject(new BString(std::string(string))) {}
+
+BDE::BDE(const char* cstring):_type(TYPE_STRING),
+ _bobject(new BString(std::string(cstring))) {}
+
+BDE::BDE(const char* data, size_t length):
+ _type(TYPE_STRING),
+ _bobject(new BString(std::string(&data[0], &data[length]))) {}
+
+BDE::BDE(const unsigned char* data, size_t length):
+ _type(TYPE_STRING),
+ _bobject(new BString(std::string(&data[0], &data[length]))) {}
+
+BDE BDE::dict()
+{
+ BDE bde;
+ bde._type = TYPE_DICT;
+ bde._bobject.reset(new BDict());
+ return bde;
+}
+
+BDE BDE::list()
+{
+ BDE bde;
+ bde._type = TYPE_LIST;
+ bde._bobject.reset(new BList());
+ return bde;
+}
+
+// Test for Null data
+bool BDE::isNone() const
+{
+ return _type == TYPE_NONE;
+}
+
+// Integer Interface
+
+bool BDE::isInteger() const
+{
+ return _type == TYPE_INTEGER;
+}
+
+BDE::Integer BDE::i() const
+{
+ return _bobject->i();
+}
+
+// String Interface
+
+bool BDE::isString() const
+{
+ return _type == TYPE_STRING;
+}
+
+const std::string& BDE::s() const
+{
+ return _bobject->s();
+}
+
+const unsigned char* BDE::uc() const
+{
+ return _bobject->uc();
+}
+
+// Dictionary Interface
+
+bool BDE::isDict() const
+{
+ return _type == TYPE_DICT;
+}
+
+BDE& BDE::operator[](const std::string& key)
+{
+ return _bobject->operator[](key);
+}
+
+const BDE& BDE::operator[](const std::string& key) const
+{
+ if(_bobject->containsKey(key)) {
+ return _bobject->operator[](key);
+ } else {
+ return none;
+ }
+}
+
+bool BDE::containsKey(const std::string& key) const
+{
+ return _bobject->containsKey(key);
+}
+
+void BDE::removeKey(const std::string& key)
+{
+ _bobject->removeKey(key);
+}
+
+BDE::Dict::iterator BDE::dictBegin()
+{
+ return _bobject->dictBegin();
+}
+
+BDE::Dict::const_iterator BDE::dictBegin() const
+{
+ return _bobject->dictBegin();
+}
+
+BDE::Dict::iterator BDE::dictEnd()
+{
+ return _bobject->dictEnd();
+}
+
+BDE::Dict::const_iterator BDE::dictEnd() const
+{
+ return _bobject->dictEnd();
+}
+
+// List Interface
+
+bool BDE::isList() const
+{
+ return _type == TYPE_LIST;
+}
+
+void BDE::append(const BDE& bde)
+{
+ _bobject->append(bde);
+}
+
+void BDE::operator<<(const BDE& bde)
+{
+ _bobject->operator<<(bde);
+}
+
+BDE& BDE::operator[](size_t index)
+{
+ return _bobject->operator[](index);
+}
+
+const BDE& BDE::operator[](size_t index) const
+{
+ return _bobject->operator[](index);
+}
+
+BDE::List::iterator BDE::listBegin()
+{
+ return _bobject->listBegin();
+}
+
+BDE::List::const_iterator BDE::listBegin() const
+{
+ return _bobject->listBegin();
+}
+
+BDE::List::iterator BDE::listEnd()
+{
+ return _bobject->listEnd();
+}
+
+BDE::List::const_iterator BDE::listEnd() const
+{
+ return _bobject->listEnd();
+}
+
+// Callable from List and Dict
+size_t BDE::size() const
+{
+ return _bobject->size();
+}
+
+// Callable from List and Dict
+bool BDE::empty() const
+{
+ return _bobject->empty();
+}
+
+} // namespace aria2
diff --git a/src/BDE.h b/src/BDE.h
new file mode 100644
index 00000000..7e62b62c
--- /dev/null
+++ b/src/BDE.h
@@ -0,0 +1,431 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2009 Tatsuhiro Tsujikawa
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you
+ * do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+#ifndef _D_BDE_H_
+#define _D_BDE_H_
+
+#include "common.h"
+
+#include <map>
+#include <string>
+#include <deque>
+
+#include "SharedHandle.h"
+#include "RecoverableException.h"
+
+namespace aria2 {
+
+class BDE;
+
+class BDE {
+public:
+ typedef std::map<std::string, BDE> Dict;
+ typedef std::deque<BDE> List;
+ typedef int64_t Integer;
+private:
+ enum TYPE{
+ TYPE_NONE,
+ TYPE_INTEGER,
+ TYPE_STRING,
+ TYPE_DICT,
+ TYPE_LIST,
+ };
+
+ class BObject {
+ public:
+ virtual ~BObject() {}
+
+ ////////////////////////////////////////////////////////////////////////////
+ // Integer Interface
+
+ // Returns Integer.
+ virtual Integer i() const
+ {
+ throw RecoverableException("Not Integer");
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ // String Interface
+
+ // Returns std::string.
+ virtual const std::string& s() const
+ {
+ throw RecoverableException("Not String");
+ }
+
+ // Returns std::string.data() casted to unsigned char*.
+ // Use s().size() to get length.
+ virtual const unsigned char* uc() const
+ {
+ throw RecoverableException("Not String");
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ // Dictionary Interface
+
+ // Returns the reference to BDE object associated with given key.
+ // If the key is not found, new pair with that key is created
+ // using default values, which is then returned. In other words,
+ // this is the same behavior of std::map's operator[].
+ virtual BDE& operator[](const std::string& key)
+ {
+ throw RecoverableException("Not Dict");
+ }
+
+ // Returns true if the given key is found in dict.
+ virtual bool containsKey(const std::string& key) const
+ {
+ throw RecoverableException("Not Dict");
+ }
+
+ // Removes specified key from dict.
+ virtual void removeKey(const std::string& key)
+ {
+ throw RecoverableException("Not Dict");
+ }
+
+ // Returns a read/write iterator that points to the first pair in
+ // the dict.
+ virtual Dict::iterator dictBegin()
+ {
+ throw RecoverableException("Not Dict");
+ }
+
+ // Returns a read/write read-only iterator that points to one past
+ // the last pair in the dict.
+ virtual Dict::iterator dictEnd()
+ {
+ throw RecoverableException("Not Dict");
+ }
+
+ ////////////////////////////////////////////////////////////////////////////
+ // List Interface
+
+ // Appends given bde to list.
+ virtual void append(const BDE& bde)
+ {
+ throw RecoverableException("Not List");
+ }
+
+ // Alias for append()
+ virtual void operator<<(const BDE& bde)
+ {
+ throw RecoverableException("Not List");
+ }
+
+ // Returns the reference of the object at the given index.
+ virtual BDE& operator[](size_t index)
+ {
+ throw RecoverableException("Not List");
+ }
+
+ // Returns a read/write iterator that points to the first object
+ // in list.
+ virtual List::iterator listBegin()
+ {
+ throw RecoverableException("Not List");
+ }
+
+ // Returns a read/write iterator that points to the one past the
+ // last object in list.
+ virtual List::iterator listEnd()
+ {
+ throw RecoverableException("Not List");
+ }
+
+ // Returns size of list or dict.
+ virtual size_t size() const
+ {
+ throw RecoverableException("Neither Dict nor List");
+ }
+
+ // Returns true if size of list or dict is 0.
+ virtual bool empty() const
+ {
+ throw RecoverableException("Neither Dict nor List");
+ }
+ };
+
+ class BInteger : public BObject {
+ private:
+ Integer _integer;
+ public:
+ BInteger(Integer i):_integer(i) {}
+
+ virtual BDE::Integer i() const
+ {
+ return _integer;
+ }
+ };
+
+ class BString : public BObject {
+ private:
+ std::string _string;
+ public:
+ BString(const std::string& string):_string(string) {}
+
+ virtual const std::string& s() const
+ {
+ return _string;
+ }
+
+ virtual const unsigned char* uc() const
+ {
+ return reinterpret_cast<const unsigned char*>(_string.data());
+ }
+ };
+
+ class BDict : public BObject {
+ private:
+ Dict _dict;
+ public:
+
+ virtual BDE& operator[](const std::string& key)
+ {
+ return _dict[key];
+ }
+
+ virtual bool containsKey(const std::string& key) const
+ {
+ return _dict.find(key) != _dict.end();
+ }
+
+ virtual void removeKey(const std::string& key)
+ {
+ _dict.erase(key);
+ }
+
+ virtual BDE::Dict::iterator dictBegin()
+ {
+ return _dict.begin();
+ }
+
+ virtual BDE::Dict::iterator dictEnd()
+ {
+ return _dict.end();
+ }
+
+ virtual size_t size() const
+ {
+ return _dict.size();
+ }
+
+ virtual bool empty() const
+ {
+ return _dict.empty();
+ }
+ };
+
+ class BList : public BObject {
+ private:
+ List _list;
+ public:
+ virtual void append(const BDE& bde)
+ {
+ _list.push_back(bde);
+ }
+
+ virtual void operator<<(const BDE& bde)
+ {
+ _list.push_back(bde);
+ }
+
+ virtual BDE& operator[](size_t index)
+ {
+ return _list[index];
+ }
+
+ virtual BDE::List::iterator listBegin()
+ {
+ return _list.begin();
+ }
+
+ virtual BDE::List::iterator listEnd()
+ {
+ return _list.end();
+ }
+
+ virtual size_t size() const
+ {
+ return _list.size();
+ }
+
+ virtual bool empty() const
+ {
+ return _list.empty();
+ }
+ };
+
+ TYPE _type;
+
+ SharedHandle<BObject> _bobject;
+public:
+ BDE();
+
+ static BDE dict();
+
+ static BDE list();
+
+ static const BDE none;
+
+ // Test for Null data
+ // Return true if the type of this object is None.
+ bool isNone() const;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Integer Interface
+
+ BDE(Integer integer);
+
+ // Returns true if the type of this object is Integer.
+ bool isInteger() const;
+
+ // Returns Integer. Requires this object to be Integer.
+ Integer i() const;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // String Interface
+
+ BDE(const std::string& string);
+
+ // Made explicit to avoid ambiguity with BDE(Integer).
+ explicit BDE(const char* cstring);
+
+ BDE(const char* data, size_t length);
+
+ BDE(const unsigned char* data, size_t length);
+
+ // Returns true if the type of this object is String.
+ bool isString() const;
+
+ // Returns std::string. Requires this object to be String
+ const std::string& s() const;
+
+ // Returns std::string.data() casted to unsigned char*.
+ // Use s().size() to get length.
+ const unsigned char* uc() const;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Dictionary Interface
+
+ // Returns true if the type of this object is Dict.
+ bool isDict() const;
+
+ // Returns the reference to BDE object associated with given key.
+ // If the key is not found, new pair with that key is created using default
+ // values, which is then returned. In other words, this is the same behavior
+ // of std::map's operator[].
+ // Requires this object to be Dict.
+ BDE& operator[](const std::string& key);
+
+ // Returns the const reference to BDE ojbect associated with given key.
+ // If the key is not found, BDE::none is returned.
+ // Requires this object to be Dict.
+ const BDE& operator[](const std::string& key) const;
+
+ // Returns true if the given key is found in dict.
+ // Requires this object to be Dict.
+ bool containsKey(const std::string& key) const;
+
+ // Removes specified key from dict.
+ // Requires this object to be Dict.
+ void removeKey(const std::string& key);
+
+ // Returns a read/write iterator that points to the first pair in the dict.
+ // Requires this object to be Dict.
+ Dict::iterator dictBegin();
+
+ // Returns a read/write read-only iterator that points to the first pair in
+ // the dict.
+ // Requires this object to be Dict.
+ Dict::const_iterator dictBegin() const;
+
+ // Returns a read/write read-only iterator that points to one past the last
+ // pair in the dict.
+ // Requires this object to be Dict.
+ Dict::iterator dictEnd();
+
+ // Returns a read/write read-only iterator that points to one past the last
+ // pair in the dict.
+ // Requires this object to be Dict.
+ Dict::const_iterator dictEnd() const;
+
+ //////////////////////////////////////////////////////////////////////////////
+ // List Interface
+
+ // Returns true if the type of this object is List.
+ bool isList() const;
+
+ // Appends given bde to list. Required the type of this object to be List.
+ void append(const BDE& bde);
+
+ // Alias for append()
+ void operator<<(const BDE& bde);
+
+ // Returns the reference of the object at the given index. Required this
+ // object to be List.
+ BDE& operator[](size_t index);
+
+ // Returns the const reference of the object at the given index.
+ // Required this object to be List.
+ const BDE& operator[](size_t index) const;
+
+ // Returns a read/write iterator that points to the first object in list.
+ // Required this object to be List.
+ List::iterator listBegin();
+
+ // Returns a read/write read-only iterator that points to the first object
+ // in list. Required this object to be List.
+ List::const_iterator listBegin() const;
+
+ // Returns a read/write iterator that points to the one past the last object
+ // in list. Required this object to be List.
+ List::iterator listEnd();
+
+ // Returns a read/write read-only iterator that points to the one past the
+ // last object in list. Required this object to be List.
+ List::const_iterator listEnd() const;
+
+ // For List type: Returns size of list.
+ // For Dict type: Returns size of dict.
+ size_t size() const;
+
+ // For List type: Returns true if size of list is 0.
+ // For Dict type: Returns true if size of dict is 0.
+ bool empty() const;
+};
+
+} // namespace aria2
+
+#endif // _D_BDE_H_
diff --git a/src/DHTAbstractMessage.cc b/src/DHTAbstractMessage.cc
index 41c67f27..f76bdc13 100644
--- a/src/DHTAbstractMessage.cc
+++ b/src/DHTAbstractMessage.cc
@@ -55,7 +55,7 @@ DHTAbstractMessage::~DHTAbstractMessage() {}
std::string DHTAbstractMessage::getBencodedMessage()
{
- bencode::BDE msgDict = bencode::BDE::dict();
+ BDE msgDict = BDE::dict();
msgDict[T] = _transactionID;
msgDict[Y] = getType();
fillMessage(msgDict);
diff --git a/src/DHTAbstractMessage.h b/src/DHTAbstractMessage.h
index ee7d4988..113a32f0 100644
--- a/src/DHTAbstractMessage.h
+++ b/src/DHTAbstractMessage.h
@@ -40,9 +40,7 @@
namespace aria2 {
-namespace bencode {
class BDE;
-} // namespace bencode
class DHTConnection;
class DHTMessageDispatcher;
class DHTMessageFactory;
@@ -68,7 +66,7 @@ public:
virtual std::string getType() const = 0;
- virtual void fillMessage(bencode::BDE& msgDict) = 0;
+ virtual void fillMessage(BDE& msgDict) = 0;
std::string getBencodedMessage();
diff --git a/src/DHTAnnouncePeerMessage.cc b/src/DHTAnnouncePeerMessage.cc
index 31d4d4ad..871042da 100644
--- a/src/DHTAnnouncePeerMessage.cc
+++ b/src/DHTAnnouncePeerMessage.cc
@@ -84,11 +84,11 @@ void DHTAnnouncePeerMessage::doReceivedAction()
_dispatcher->addMessageToQueue(reply);
}
-bencode::BDE DHTAnnouncePeerMessage::getArgument()
+BDE DHTAnnouncePeerMessage::getArgument()
{
- bencode::BDE aDict = bencode::BDE::dict();
- aDict[DHTMessage::ID] = bencode::BDE(_localNode->getID(), DHT_ID_LENGTH);
- aDict[INFO_HASH] = bencode::BDE(_infoHash, DHT_ID_LENGTH);
+ BDE aDict = BDE::dict();
+ aDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
+ aDict[INFO_HASH] = BDE(_infoHash, DHT_ID_LENGTH);
aDict[PORT] = _tcpPort;
aDict[TOKEN] = _token;
return aDict;
diff --git a/src/DHTAnnouncePeerMessage.h b/src/DHTAnnouncePeerMessage.h
index 8d38ea53..bc31d59a 100644
--- a/src/DHTAnnouncePeerMessage.h
+++ b/src/DHTAnnouncePeerMessage.h
@@ -69,7 +69,7 @@ public:
virtual void doReceivedAction();
- virtual bencode::BDE getArgument();
+ virtual BDE getArgument();
virtual std::string getMessageType() const;
diff --git a/src/DHTAnnouncePeerReplyMessage.cc b/src/DHTAnnouncePeerReplyMessage.cc
index 2e2b9b64..2a0fb472 100644
--- a/src/DHTAnnouncePeerReplyMessage.cc
+++ b/src/DHTAnnouncePeerReplyMessage.cc
@@ -49,10 +49,10 @@ DHTAnnouncePeerReplyMessage::~DHTAnnouncePeerReplyMessage() {}
void DHTAnnouncePeerReplyMessage::doReceivedAction() {}
-bencode::BDE DHTAnnouncePeerReplyMessage::getResponse()
+BDE DHTAnnouncePeerReplyMessage::getResponse()
{
- bencode::BDE rDict = bencode::BDE::dict();
- rDict[DHTMessage::ID] = bencode::BDE(_localNode->getID(), DHT_ID_LENGTH);
+ BDE rDict = BDE::dict();
+ rDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
return rDict;
}
diff --git a/src/DHTAnnouncePeerReplyMessage.h b/src/DHTAnnouncePeerReplyMessage.h
index 967a3088..732e610e 100644
--- a/src/DHTAnnouncePeerReplyMessage.h
+++ b/src/DHTAnnouncePeerReplyMessage.h
@@ -49,7 +49,7 @@ public:
virtual void doReceivedAction();
- virtual bencode::BDE getResponse();
+ virtual BDE getResponse();
virtual std::string getMessageType() const;
diff --git a/src/DHTFindNodeMessage.cc b/src/DHTFindNodeMessage.cc
index 47a36667..6888bf31 100644
--- a/src/DHTFindNodeMessage.cc
+++ b/src/DHTFindNodeMessage.cc
@@ -70,11 +70,11 @@ void DHTFindNodeMessage::doReceivedAction()
_dispatcher->addMessageToQueue(reply);
}
-bencode::BDE DHTFindNodeMessage::getArgument()
+BDE DHTFindNodeMessage::getArgument()
{
- bencode::BDE aDict = bencode::BDE::dict();
- aDict[DHTMessage::ID] = bencode::BDE(_localNode->getID(), DHT_ID_LENGTH);
- aDict[TARGET_NODE] = bencode::BDE(_targetNodeID, DHT_ID_LENGTH);
+ BDE aDict = BDE::dict();
+ aDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
+ aDict[TARGET_NODE] = BDE(_targetNodeID, DHT_ID_LENGTH);
return aDict;
}
diff --git a/src/DHTFindNodeMessage.h b/src/DHTFindNodeMessage.h
index 11162787..ea9e6de7 100644
--- a/src/DHTFindNodeMessage.h
+++ b/src/DHTFindNodeMessage.h
@@ -55,7 +55,7 @@ public:
virtual void doReceivedAction();
- virtual bencode::BDE getArgument();
+ virtual BDE getArgument();
virtual std::string getMessageType() const;
diff --git a/src/DHTFindNodeReplyMessage.cc b/src/DHTFindNodeReplyMessage.cc
index 0ae1d74c..360b43e3 100644
--- a/src/DHTFindNodeReplyMessage.cc
+++ b/src/DHTFindNodeReplyMessage.cc
@@ -68,10 +68,10 @@ void DHTFindNodeReplyMessage::doReceivedAction()
}
}
-bencode::BDE DHTFindNodeReplyMessage::getResponse()
+BDE DHTFindNodeReplyMessage::getResponse()
{
- bencode::BDE aDict = bencode::BDE::dict();
- aDict[DHTMessage::ID] = bencode::BDE(_localNode->getID(), DHT_ID_LENGTH);
+ BDE aDict = BDE::dict();
+ aDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
size_t offset = 0;
unsigned char buffer[DHTBucket::K*26];
// TODO if _closestKNodes.size() > DHTBucket::K ??
@@ -85,7 +85,7 @@ bencode::BDE DHTFindNodeReplyMessage::getResponse()
offset += 26;
}
}
- aDict[NODES] = bencode::BDE(buffer, offset);
+ aDict[NODES] = BDE(buffer, offset);
return aDict;
}
diff --git a/src/DHTFindNodeReplyMessage.h b/src/DHTFindNodeReplyMessage.h
index ab84d3ed..f188c0f3 100644
--- a/src/DHTFindNodeReplyMessage.h
+++ b/src/DHTFindNodeReplyMessage.h
@@ -54,7 +54,7 @@ public:
virtual void doReceivedAction();
- virtual bencode::BDE getResponse();
+ virtual BDE getResponse();
virtual std::string getMessageType() const;
diff --git a/src/DHTGetPeersMessage.cc b/src/DHTGetPeersMessage.cc
index 6532dae5..e6c2af43 100644
--- a/src/DHTGetPeersMessage.cc
+++ b/src/DHTGetPeersMessage.cc
@@ -88,11 +88,11 @@ void DHTGetPeersMessage::doReceivedAction()
_dispatcher->addMessageToQueue(reply);
}
-bencode::BDE DHTGetPeersMessage::getArgument()
+BDE DHTGetPeersMessage::getArgument()
{
- bencode::BDE aDict = bencode::BDE::dict();
- aDict[DHTMessage::ID] = bencode::BDE(_localNode->getID(), DHT_ID_LENGTH);
- aDict[INFO_HASH] = bencode::BDE(_infoHash, DHT_ID_LENGTH);
+ BDE aDict = BDE::dict();
+ aDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
+ aDict[INFO_HASH] = BDE(_infoHash, DHT_ID_LENGTH);
return aDict;
}
diff --git a/src/DHTGetPeersMessage.h b/src/DHTGetPeersMessage.h
index 237020e8..16f283c6 100644
--- a/src/DHTGetPeersMessage.h
+++ b/src/DHTGetPeersMessage.h
@@ -63,7 +63,7 @@ public:
virtual void doReceivedAction();
- virtual bencode::BDE getArgument();
+ virtual BDE getArgument();
virtual std::string getMessageType() const;
diff --git a/src/DHTGetPeersReplyMessage.cc b/src/DHTGetPeersReplyMessage.cc
index a53aa56e..0e46cf4a 100644
--- a/src/DHTGetPeersReplyMessage.cc
+++ b/src/DHTGetPeersReplyMessage.cc
@@ -72,10 +72,10 @@ void DHTGetPeersReplyMessage::doReceivedAction()
// Returned peers and nodes are handled in DHTPeerLookupTask.
}
-bencode::BDE DHTGetPeersReplyMessage::getResponse()
+BDE DHTGetPeersReplyMessage::getResponse()
{
- bencode::BDE rDict = bencode::BDE::dict();
- rDict[DHTMessage::ID] = bencode::BDE(_localNode->getID(), DHT_ID_LENGTH);
+ BDE rDict = BDE::dict();
+ rDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
rDict[TOKEN] = _token;
if(_values.empty()) {
size_t offset = 0;
@@ -89,15 +89,15 @@ bencode::BDE DHTGetPeersReplyMessage::getResponse()
offset += 26;
}
}
- rDict[NODES] = bencode::BDE(buffer, offset);
+ rDict[NODES] = BDE(buffer, offset);
} else {
- bencode::BDE valuesList = bencode::BDE::list();
+ BDE valuesList = BDE::list();
for(std::deque<SharedHandle<Peer> >::const_iterator i = _values.begin();
i != _values.end(); ++i) {
const SharedHandle<Peer>& peer = *i;
unsigned char buffer[6];
if(PeerMessageUtil::createcompact(buffer, peer->ipaddr, peer->port)) {
- valuesList << bencode::BDE(buffer, sizeof(buffer));
+ valuesList << BDE(buffer, sizeof(buffer));
}
}
rDict[VALUES] = valuesList;
diff --git a/src/DHTGetPeersReplyMessage.h b/src/DHTGetPeersReplyMessage.h
index de77d0d0..62908154 100644
--- a/src/DHTGetPeersReplyMessage.h
+++ b/src/DHTGetPeersReplyMessage.h
@@ -64,7 +64,7 @@ public:
virtual void doReceivedAction();
- virtual bencode::BDE getResponse();
+ virtual BDE getResponse();
virtual std::string getMessageType() const;
diff --git a/src/DHTMessageFactory.h b/src/DHTMessageFactory.h
index 5db6bfe0..863c5c24 100644
--- a/src/DHTMessageFactory.h
+++ b/src/DHTMessageFactory.h
@@ -48,21 +48,19 @@ namespace aria2 {
class DHTMessage;
class DHTNode;
class Peer;
-namespace bencode {
class BDE;
-} // namespace bencode
class DHTMessageFactory {
public:
virtual ~DHTMessageFactory() {}
virtual SharedHandle<DHTMessage>
- createQueryMessage(const bencode::BDE& dict,
+ createQueryMessage(const BDE& dict,
const std::string& ipaddr, uint16_t port) = 0;
virtual SharedHandle<DHTMessage>
createResponseMessage(const std::string& messageType,
- const bencode::BDE& dict,
+ const BDE& dict,
const std::string& ipaddr, uint16_t port) = 0;
virtual SharedHandle<DHTMessage>
diff --git a/src/DHTMessageFactoryImpl.cc b/src/DHTMessageFactoryImpl.cc
index 80845a43..b9fc5eb6 100644
--- a/src/DHTMessageFactoryImpl.cc
+++ b/src/DHTMessageFactoryImpl.cc
@@ -82,10 +82,10 @@ DHTMessageFactoryImpl::getRemoteNode(const unsigned char* id, const std::string&
return node;
}
-static const bencode::BDE& getDictionary(const bencode::BDE& dict,
+static const BDE& getDictionary(const BDE& dict,
const std::string& key)
{
- const bencode::BDE& d = dict[key];
+ const BDE& d = dict[key];
if(d.isDict()) {
return d;
} else {
@@ -94,10 +94,10 @@ static const bencode::BDE& getDictionary(const bencode::BDE& dict,
}
}
-static const bencode::BDE& getString(const bencode::BDE& dict,
+static const BDE& getString(const BDE& dict,
const std::string& key)
{
- const bencode::BDE& c = dict[key];
+ const BDE& c = dict[key];
if(c.isString()) {
return c;
} else {
@@ -106,10 +106,10 @@ static const bencode::BDE& getString(const bencode::BDE& dict,
}
}
-static const bencode::BDE& getInteger(const bencode::BDE& dict,
+static const BDE& getInteger(const BDE& dict,
const std::string& key)
{
- const bencode::BDE& c = dict[key];
+ const BDE& c = dict[key];
if(c.isInteger()) {
return c;
} else {
@@ -118,9 +118,9 @@ static const bencode::BDE& getInteger(const bencode::BDE& dict,
}
}
-static const bencode::BDE& getString(const bencode::BDE& list, size_t index)
+static const BDE& getString(const BDE& list, size_t index)
{
- const bencode::BDE& c = list[index];
+ const BDE& c = list[index];
if(c.isString()) {
return c;
} else {
@@ -130,9 +130,9 @@ static const bencode::BDE& getString(const bencode::BDE& list, size_t index)
}
}
-static const bencode::BDE& getInteger(const bencode::BDE& list, size_t index)
+static const BDE& getInteger(const BDE& list, size_t index)
{
- const bencode::BDE& c = list[index];
+ const BDE& c = list[index];
if(c.isInteger()) {
return c;
} else {
@@ -142,10 +142,10 @@ static const bencode::BDE& getInteger(const bencode::BDE& list, size_t index)
}
}
-static const bencode::BDE& getList(const bencode::BDE& dict,
+static const BDE& getList(const BDE& dict,
const std::string& key)
{
- const bencode::BDE& l = dict[key];
+ const BDE& l = dict[key];
if(l.isList()) {
return l;
} else {
@@ -154,7 +154,7 @@ static const bencode::BDE& getList(const bencode::BDE& dict,
}
}
-void DHTMessageFactoryImpl::validateID(const bencode::BDE& id) const
+void DHTMessageFactoryImpl::validateID(const BDE& id) const
{
if(id.s().size() != DHT_ID_LENGTH) {
throw DlAbortEx
@@ -164,9 +164,9 @@ void DHTMessageFactoryImpl::validateID(const bencode::BDE& id) const
}
}
-void DHTMessageFactoryImpl::validatePort(const bencode::BDE& i) const
+void DHTMessageFactoryImpl::validatePort(const BDE& i) const
{
- bencode::BDE::Integer port = i.i();
+ BDE::Integer port = i.i();
if(!(0 < port && port < UINT16_MAX)) {
throw DlAbortEx
(StringFormat("Malformed DHT message. Invalid port=%s",
@@ -175,41 +175,41 @@ void DHTMessageFactoryImpl::validatePort(const bencode::BDE& i) const
}
SharedHandle<DHTMessage> DHTMessageFactoryImpl::createQueryMessage
-(const bencode::BDE& dict,
+(const BDE& dict,
const std::string& ipaddr,
uint16_t port)
{
- const bencode::BDE& messageType = getString(dict, DHTQueryMessage::Q);
- const bencode::BDE& transactionID = getString(dict, DHTMessage::T);
- const bencode::BDE& y = getString(dict, DHTMessage::Y);
- const bencode::BDE& aDict = getDictionary(dict, DHTQueryMessage::A);
+ const BDE& messageType = getString(dict, DHTQueryMessage::Q);
+ const BDE& transactionID = getString(dict, DHTMessage::T);
+ const BDE& y = getString(dict, DHTMessage::Y);
+ const BDE& aDict = getDictionary(dict, DHTQueryMessage::A);
if(y.s() != DHTQueryMessage::Q) {
throw DlAbortEx("Malformed DHT message. y != q");
}
- const bencode::BDE& id = getString(aDict, DHTMessage::ID);
+ const BDE& id = getString(aDict, DHTMessage::ID);
validateID(id);
SharedHandle<DHTNode> remoteNode = getRemoteNode(id.uc(), ipaddr, port);
if(messageType.s() == DHTPingMessage::PING) {
return createPingMessage(remoteNode, transactionID.s());
} else if(messageType.s() == DHTFindNodeMessage::FIND_NODE) {
- const bencode::BDE& targetNodeID =
+ const BDE& targetNodeID =
getString(aDict, DHTFindNodeMessage::TARGET_NODE);
validateID(targetNodeID);
return createFindNodeMessage(remoteNode, targetNodeID.uc(),
transactionID.s());
} else if(messageType.s() == DHTGetPeersMessage::GET_PEERS) {
- const bencode::BDE& infoHash =
+ const BDE& infoHash =
getString(aDict, DHTGetPeersMessage::INFO_HASH);
validateID(infoHash);
return createGetPeersMessage(remoteNode,
infoHash.uc(), transactionID.s());
} else if(messageType.s() == DHTAnnouncePeerMessage::ANNOUNCE_PEER) {
- const bencode::BDE& infoHash =
+ const BDE& infoHash =
getString(aDict, DHTAnnouncePeerMessage::INFO_HASH);
validateID(infoHash);
- const bencode::BDE& port = getInteger(aDict, DHTAnnouncePeerMessage::PORT);
+ const BDE& port = getInteger(aDict, DHTAnnouncePeerMessage::PORT);
validatePort(port);
- const bencode::BDE& token = getString(aDict, DHTAnnouncePeerMessage::TOKEN);
+ const BDE& token = getString(aDict, DHTAnnouncePeerMessage::TOKEN);
return createAnnouncePeerMessage(remoteNode, infoHash.uc(),
static_cast<uint16_t>(port.i()),
token.s(), transactionID.s());
@@ -222,15 +222,15 @@ SharedHandle<DHTMessage> DHTMessageFactoryImpl::createQueryMessage
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createResponseMessage(const std::string& messageType,
- const bencode::BDE& dict,
+ const BDE& dict,
const std::string& ipaddr,
uint16_t port)
{
- const bencode::BDE& transactionID = getString(dict, DHTMessage::T);
- const bencode::BDE& y = getString(dict, DHTMessage::Y);
+ const BDE& transactionID = getString(dict, DHTMessage::T);
+ const BDE& y = getString(dict, DHTMessage::Y);
if(y.s() == DHTUnknownMessage::E) {
// for now, just report error message arrived and throw exception.
- const bencode::BDE& e = getList(dict, DHTUnknownMessage::E);
+ 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(),
@@ -244,8 +244,8 @@ DHTMessageFactoryImpl::createResponseMessage(const std::string& messageType,
(StringFormat("Malformed DHT message. y != r: y=%s",
Util::urlencode(y.s()).c_str()).str());
}
- const bencode::BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
- const bencode::BDE& id = getString(rDict, DHTMessage::ID);
+ const BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
+ const BDE& id = getString(rDict, DHTMessage::ID);
validateID(id);
SharedHandle<DHTNode> remoteNode = getRemoteNode(id.uc(), ipaddr, port);
@@ -254,12 +254,12 @@ DHTMessageFactoryImpl::createResponseMessage(const std::string& messageType,
} else if(messageType == DHTFindNodeReplyMessage::FIND_NODE) {
return createFindNodeReplyMessage(remoteNode, dict, transactionID.s());
} else if(messageType == DHTGetPeersReplyMessage::GET_PEERS) {
- const bencode::BDE& valuesList = rDict[DHTGetPeersReplyMessage::VALUES];
+ const BDE& valuesList = rDict[DHTGetPeersReplyMessage::VALUES];
if(valuesList.isList()) {
return createGetPeersReplyMessageWithValues(remoteNode, dict,
transactionID.s());
} else {
- const bencode::BDE& nodes = rDict[DHTGetPeersReplyMessage::NODES];
+ const BDE& nodes = rDict[DHTGetPeersReplyMessage::NODES];
if(nodes.isString()) {
return createGetPeersReplyMessageWithNodes(remoteNode, dict,
transactionID.s());
@@ -346,10 +346,10 @@ DHTMessageFactoryImpl::extractNodes(const unsigned char* src, size_t length)
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createFindNodeReplyMessage
(const SharedHandle<DHTNode>& remoteNode,
- const bencode::BDE& dict,
+ const BDE& dict,
const std::string& transactionID)
{
- const bencode::BDE& nodesData =
+ const BDE& nodesData =
getString(getDictionary(dict, DHTResponseMessage::R),
DHTFindNodeReplyMessage::NODES);
std::deque<SharedHandle<DHTNode> > nodes = extractNodes(nodesData.uc(),
@@ -375,15 +375,15 @@ DHTMessageFactoryImpl::createGetPeersMessage(const SharedHandle<DHTNode>& remote
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createGetPeersReplyMessageWithNodes
(const SharedHandle<DHTNode>& remoteNode,
- const bencode::BDE& dict,
+ const BDE& dict,
const std::string& transactionID)
{
- const bencode::BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
- const bencode::BDE& nodesData = getString(rDict,
+ const BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
+ const BDE& nodesData = getString(rDict,
DHTGetPeersReplyMessage::NODES);
std::deque<SharedHandle<DHTNode> > nodes = extractNodes(nodesData.uc(),
nodesData.s().size());
- const bencode::BDE& token = getString(rDict, DHTGetPeersReplyMessage::TOKEN);
+ const BDE& token = getString(rDict, DHTGetPeersReplyMessage::TOKEN);
return createGetPeersReplyMessage(remoteNode, nodes, token.s(),
transactionID);
}
@@ -404,16 +404,16 @@ DHTMessageFactoryImpl::createGetPeersReplyMessage(const SharedHandle<DHTNode>& r
SharedHandle<DHTMessage>
DHTMessageFactoryImpl::createGetPeersReplyMessageWithValues
(const SharedHandle<DHTNode>& remoteNode,
- const bencode::BDE& dict,
+ const BDE& dict,
const std::string& transactionID)
{
- const bencode::BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
- const bencode::BDE& valuesList = getList(rDict,
+ const BDE& rDict = getDictionary(dict, DHTResponseMessage::R);
+ const BDE& valuesList = getList(rDict,
DHTGetPeersReplyMessage::VALUES);
std::deque<SharedHandle<Peer> > peers;
- for(bencode::BDE::List::const_iterator i = valuesList.listBegin();
+ for(BDE::List::const_iterator i = valuesList.listBegin();
i != valuesList.listEnd(); ++i) {
- const bencode::BDE& data = *i;
+ const BDE& data = *i;
if(data.isString() && data.s().size() == 6) {
std::pair<std::string, uint16_t> addr =
PeerMessageUtil::unpackcompact(data.uc());
@@ -421,7 +421,7 @@ DHTMessageFactoryImpl::createGetPeersReplyMessageWithValues
peers.push_back(peer);
}
}
- const bencode::BDE& token = getString(rDict, DHTGetPeersReplyMessage::TOKEN);
+ const BDE& token = getString(rDict, DHTGetPeersReplyMessage::TOKEN);
return createGetPeersReplyMessage(remoteNode, peers, token.s(),
transactionID);
}
diff --git a/src/DHTMessageFactoryImpl.h b/src/DHTMessageFactoryImpl.h
index 4e666a26..ef0cd70b 100644
--- a/src/DHTMessageFactoryImpl.h
+++ b/src/DHTMessageFactoryImpl.h
@@ -68,9 +68,9 @@ private:
// search node in routingTable. If it is not found, create new one.
SharedHandle<DHTNode> getRemoteNode(const unsigned char* id, const std::string& ipaddr, uint16_t port) const;
- void validateID(const bencode::BDE& id) const;
+ void validateID(const BDE& id) const;
- void validatePort(const bencode::BDE& i) const;
+ void validatePort(const BDE& i) const;
std::deque<SharedHandle<DHTNode> > extractNodes(const unsigned char* src, size_t length);
@@ -82,12 +82,12 @@ public:
virtual ~DHTMessageFactoryImpl();
virtual SharedHandle<DHTMessage>
- createQueryMessage(const bencode::BDE& dict,
+ createQueryMessage(const BDE& dict,
const std::string& ipaddr, uint16_t port);
virtual SharedHandle<DHTMessage>
createResponseMessage(const std::string& messageType,
- const bencode::BDE& dict,
+ const BDE& dict,
const std::string& ipaddr, uint16_t port);
virtual SharedHandle<DHTMessage>
@@ -106,7 +106,7 @@ public:
SharedHandle<DHTMessage>
createFindNodeReplyMessage(const SharedHandle<DHTNode>& remoteNode,
- const bencode::BDE& dict,
+ const BDE& dict,
const std::string& transactionID);
@@ -128,7 +128,7 @@ public:
SharedHandle<DHTMessage>
createGetPeersReplyMessageWithNodes(const SharedHandle<DHTNode>& remoteNode,
- const bencode::BDE& dict,
+ const BDE& dict,
const std::string& transactionID);
virtual SharedHandle<DHTMessage>
@@ -139,7 +139,7 @@ public:
SharedHandle<DHTMessage>
createGetPeersReplyMessageWithValues(const SharedHandle<DHTNode>& remoteNode,
- const bencode::BDE& dict,
+ const BDE& dict,
const std::string& transactionID);
virtual SharedHandle<DHTMessage>
diff --git a/src/DHTMessageReceiver.cc b/src/DHTMessageReceiver.cc
index 15669a0a..3f1e1123 100644
--- a/src/DHTMessageReceiver.cc
+++ b/src/DHTMessageReceiver.cc
@@ -74,9 +74,9 @@ SharedHandle<DHTMessage> DHTMessageReceiver::receiveMessage()
}
try {
bool isReply = false;
- const bencode::BDE dict = bencode::decode(data, length);
+ const BDE dict = bencode::decode(data, length);
if(dict.isDict()) {
- const bencode::BDE& y = dict[DHTMessage::Y];
+ const BDE& y = dict[DHTMessage::Y];
if(y.isString()) {
if(y.s() == DHTResponseMessage::R || y.s() == DHTUnknownMessage::E) {
isReply = true;
diff --git a/src/DHTMessageTracker.cc b/src/DHTMessageTracker.cc
index a64e5a9b..1207658d 100644
--- a/src/DHTMessageTracker.cc
+++ b/src/DHTMessageTracker.cc
@@ -69,10 +69,10 @@ void DHTMessageTracker::addMessage(const SharedHandle<DHTMessage>& message, cons
}
std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> >
-DHTMessageTracker::messageArrived(const bencode::BDE& dict,
+DHTMessageTracker::messageArrived(const BDE& dict,
const std::string& ipaddr, uint16_t port)
{
- const bencode::BDE& tid = dict[DHTMessage::T];
+ const BDE& tid = dict[DHTMessage::T];
if(!tid.isString()) {
throw DlAbortEx(StringFormat("Malformed DHT message. From:%s:%u",
ipaddr.c_str(), port).str());
diff --git a/src/DHTMessageTracker.h b/src/DHTMessageTracker.h
index 218d988b..62c47af1 100644
--- a/src/DHTMessageTracker.h
+++ b/src/DHTMessageTracker.h
@@ -51,9 +51,7 @@ class DHTRoutingTable;
class DHTMessageFactory;
class DHTMessageTrackerEntry;
class Logger;
-namespace bencode {
class BDE;
-} // namespace bencode
class DHTMessageTracker {
private:
@@ -79,7 +77,7 @@ public:
SharedHandle<DHTMessageCallback>());
std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> >
- messageArrived(const bencode::BDE& dict,
+ messageArrived(const BDE& dict,
const std::string& ipaddr, uint16_t port);
void handleTimeout();
diff --git a/src/DHTPingMessage.cc b/src/DHTPingMessage.cc
index c68324a3..2ee39920 100644
--- a/src/DHTPingMessage.cc
+++ b/src/DHTPingMessage.cc
@@ -58,10 +58,10 @@ void DHTPingMessage::doReceivedAction()
_dispatcher->addMessageToQueue(reply);
}
-bencode::BDE DHTPingMessage::getArgument()
+BDE DHTPingMessage::getArgument()
{
- bencode::BDE aDict = bencode::BDE::dict();
- aDict[DHTMessage::ID] = bencode::BDE(_localNode->getID(), DHT_ID_LENGTH);
+ BDE aDict = BDE::dict();
+ aDict[DHTMessage::ID] = BDE(_localNode->getID(), DHT_ID_LENGTH);
return aDict;
}
diff --git a/src/DHTPingMessage.h b/src/DHTPingMessage.h
index 4479555d..eec9a5a0 100644
--- a/src/DHTPingMessage.h
+++ b/src/DHTPingMessage.h
@@ -50,7 +50,7 @@ public:
virtual void doReceivedAction();
- virtual bencode::BDE getArgument();
+ virtual BDE getArgument();
virtual std::string getMessageType() const;
diff --git a/src/DHTPingReplyMessage.cc b/src/DHTPingReplyMessage.cc
index 2d04364b..887c626e 100644
--- a/src/DHTPingReplyMessage.cc
+++ b/src/DHTPingReplyMessage.cc
@@ -56,10 +56,10 @@ DHTPingReplyMessage::~DHTPingReplyMessage() {}
void DHTPingReplyMessage::doReceivedAction() {}
-bencode::BDE DHTPingReplyMessage::getResponse()
+BDE DHTPingReplyMessage::getResponse()
{
- bencode::BDE rDict = bencode::BDE::dict();
- rDict[DHTMessage::ID] = bencode::BDE(_id, DHT_ID_LENGTH);
+ BDE rDict = BDE::dict();
+ rDict[DHTMessage::ID] = BDE(_id, DHT_ID_LENGTH);
return rDict;
}
diff --git a/src/DHTPingReplyMessage.h b/src/DHTPingReplyMessage.h
index e0c41de5..93ca50f7 100644
--- a/src/DHTPingReplyMessage.h
+++ b/src/DHTPingReplyMessage.h
@@ -53,7 +53,7 @@ public:
virtual void doReceivedAction();
- virtual bencode::BDE getResponse();
+ virtual BDE getResponse();
virtual std::string getMessageType() const;
diff --git a/src/DHTQueryMessage.cc b/src/DHTQueryMessage.cc
index dc891e59..9ed0c373 100644
--- a/src/DHTQueryMessage.cc
+++ b/src/DHTQueryMessage.cc
@@ -55,7 +55,7 @@ std::string DHTQueryMessage::getType() const
return Q;
}
-void DHTQueryMessage::fillMessage(bencode::BDE& msgDict)
+void DHTQueryMessage::fillMessage(BDE& msgDict)
{
msgDict[Q] = getMessageType();
msgDict[A] = getArgument();
diff --git a/src/DHTQueryMessage.h b/src/DHTQueryMessage.h
index 955bb9e8..5f6b13ba 100644
--- a/src/DHTQueryMessage.h
+++ b/src/DHTQueryMessage.h
@@ -52,9 +52,9 @@ public:
virtual std::string getType() const;
- virtual void fillMessage(bencode::BDE& msgDict);
+ virtual void fillMessage(BDE& msgDict);
- virtual bencode::BDE getArgument() = 0;
+ virtual BDE getArgument() = 0;
virtual bool isReply() const;
diff --git a/src/DHTResponseMessage.cc b/src/DHTResponseMessage.cc
index 6cb03037..ebed7954 100644
--- a/src/DHTResponseMessage.cc
+++ b/src/DHTResponseMessage.cc
@@ -53,7 +53,7 @@ std::string DHTResponseMessage::getType() const
return R;
}
-void DHTResponseMessage::fillMessage(bencode::BDE& msgDict)
+void DHTResponseMessage::fillMessage(BDE& msgDict)
{
msgDict[R] = getResponse();
}
diff --git a/src/DHTResponseMessage.h b/src/DHTResponseMessage.h
index 1ab80a95..646011cb 100644
--- a/src/DHTResponseMessage.h
+++ b/src/DHTResponseMessage.h
@@ -52,9 +52,9 @@ public:
virtual std::string getType() const;
- virtual void fillMessage(bencode::BDE& msgDict);
+ virtual void fillMessage(BDE& msgDict);
- virtual bencode::BDE getResponse() = 0;
+ virtual BDE getResponse() = 0;
virtual bool isReply() const;
diff --git a/src/DefaultBtAnnounce.cc b/src/DefaultBtAnnounce.cc
index a2e99f1f..72ab6512 100644
--- a/src/DefaultBtAnnounce.cc
+++ b/src/DefaultBtAnnounce.cc
@@ -204,31 +204,31 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
size_t trackerResponseLength)
{
logger->debug("Now processing tracker response.");
- const bencode::BDE dict =
+ const BDE dict =
bencode::decode(trackerResponse, trackerResponseLength);
if(!dict.isDict()) {
throw DlAbortEx(MSG_NULL_TRACKER_RESPONSE);
}
- const bencode::BDE& failure = dict[BtAnnounce::FAILURE_REASON];
+ const BDE& failure = dict[BtAnnounce::FAILURE_REASON];
if(failure.isString()) {
throw DlAbortEx
(StringFormat(EX_TRACKER_FAILURE, failure.s().c_str()).str());
}
- const bencode::BDE& warn = dict[BtAnnounce::WARNING_MESSAGE];
+ const BDE& warn = dict[BtAnnounce::WARNING_MESSAGE];
if(warn.isString()) {
logger->warn(MSG_TRACKER_WARNING_MESSAGE, warn.s().c_str());
}
- const bencode::BDE& tid = dict[BtAnnounce::TRACKER_ID];
+ const BDE& tid = dict[BtAnnounce::TRACKER_ID];
if(tid.isString()) {
trackerId = tid.s();
logger->debug("Tracker ID:%s", trackerId.c_str());
}
- const bencode::BDE& ival = dict[BtAnnounce::INTERVAL];
+ const BDE& ival = dict[BtAnnounce::INTERVAL];
if(ival.isInteger() && ival.i() > 0) {
interval = ival.i();
logger->debug("Interval:%d", interval);
}
- const bencode::BDE& mival = dict[BtAnnounce::MIN_INTERVAL];
+ const BDE& mival = dict[BtAnnounce::MIN_INTERVAL];
if(mival.isInteger() && mival.i() > 0) {
minInterval = mival.i();
logger->debug("Min interval:%d", minInterval);
@@ -239,17 +239,17 @@ DefaultBtAnnounce::processAnnounceResponse(const unsigned char* trackerResponse,
// Use interval as a minInterval if minInterval is not supplied.
minInterval = interval;
}
- const bencode::BDE& comp = dict[BtAnnounce::COMPLETE];
+ const BDE& comp = dict[BtAnnounce::COMPLETE];
if(comp.isInteger()) {
complete = comp.i();
logger->debug("Complete:%d", complete);
}
- const bencode::BDE& incomp = dict[BtAnnounce::INCOMPLETE];
+ const BDE& incomp = dict[BtAnnounce::INCOMPLETE];
if(incomp.isInteger()) {
incomplete = incomp.i();
logger->debug("Incomplete:%d", incomplete);
}
- const bencode::BDE& peerData = dict[BtAnnounce::PEERS];
+ const BDE& peerData = dict[BtAnnounce::PEERS];
if(peerData.isNone()) {
logger->info(MSG_NO_PEER_LIST_RECEIVED);
} else {
diff --git a/src/DefaultBtContext.cc b/src/DefaultBtContext.cc
index 99b8beef..7bc86e54 100644
--- a/src/DefaultBtContext.cc
+++ b/src/DefaultBtContext.cc
@@ -111,13 +111,13 @@ void DefaultBtContext::extractPieceHash(const std::string& hashData,
}
}
-void DefaultBtContext::extractFileEntries(const bencode::BDE& infoDict,
+void DefaultBtContext::extractFileEntries(const BDE& infoDict,
const std::string& defaultName,
const std::string& overrideName,
const std::deque<std::string>& urlList)
{
if(overrideName.empty()) {
- const bencode::BDE& nameData = infoDict[BtContext::C_NAME];
+ const BDE& nameData = infoDict[BtContext::C_NAME];
if(nameData.isString()) {
name = nameData.s();
} else {
@@ -126,34 +126,34 @@ void DefaultBtContext::extractFileEntries(const bencode::BDE& infoDict,
} else {
name = overrideName;
}
- const bencode::BDE& filesList = infoDict[BtContext::C_FILES];
+ const BDE& filesList = infoDict[BtContext::C_FILES];
if(filesList.isList()) {
uint64_t length = 0;
off_t offset = 0;
// multi-file mode
fileMode = BtContext::MULTI;
- for(bencode::BDE::List::const_iterator itr = filesList.listBegin();
+ for(BDE::List::const_iterator itr = filesList.listBegin();
itr != filesList.listEnd(); ++itr) {
- const bencode::BDE& fileDict = *itr;
+ const BDE& fileDict = *itr;
if(!fileDict.isDict()) {
continue;
}
- const bencode::BDE& fileLengthData = fileDict[BtContext::C_LENGTH];
+ const BDE& fileLengthData = fileDict[BtContext::C_LENGTH];
if(!fileLengthData.isInteger()) {
throw DlAbortEx(StringFormat(MSG_MISSING_BT_INFO,
BtContext::C_LENGTH.c_str()).str());
}
length += fileLengthData.i();
- const bencode::BDE& pathList = fileDict[BtContext::C_PATH];
+ const BDE& pathList = fileDict[BtContext::C_PATH];
if(!pathList.isList() || pathList.empty()) {
throw DlAbortEx("Path is empty.");
}
std::vector<std::string> pathelem(pathList.size());
std::transform(pathList.listBegin(), pathList.listEnd(), pathelem.begin(),
- std::mem_fun_ref(&bencode::BDE::s));
+ std::mem_fun_ref(&BDE::s));
std::string path =
name+"/"+Util::joinPath(pathelem.begin(), pathelem.end());
// Split path with '/' again because each pathList element can
@@ -174,7 +174,7 @@ void DefaultBtContext::extractFileEntries(const bencode::BDE& infoDict,
} else {
// single-file mode;
fileMode = BtContext::SINGLE;
- const bencode::BDE& lengthData = infoDict[BtContext::C_LENGTH];
+ const BDE& lengthData = infoDict[BtContext::C_LENGTH];
if(!lengthData.isInteger()) {
throw DlAbortEx(StringFormat(MSG_MISSING_BT_INFO,
BtContext::C_LENGTH.c_str()).str());
@@ -203,7 +203,7 @@ void DefaultBtContext::extractFileEntries(const bencode::BDE& infoDict,
}
}
-void DefaultBtContext::extractAnnounceURI(const bencode::BDE& announceData)
+void DefaultBtContext::extractAnnounceURI(const BDE& announceData)
{
// Assumed announceData is string
std::deque<std::string> urls;
@@ -211,19 +211,19 @@ void DefaultBtContext::extractAnnounceURI(const bencode::BDE& announceData)
announceTiers.push_back(AnnounceTierHandle(new AnnounceTier(urls)));
}
-void DefaultBtContext::extractAnnounceList(const bencode::BDE& announceList)
+void DefaultBtContext::extractAnnounceList(const BDE& announceList)
{
// Assumed announceList is string
- for(bencode::BDE::List::const_iterator itr = announceList.listBegin();
+ for(BDE::List::const_iterator itr = announceList.listBegin();
itr != announceList.listEnd(); ++itr) {
- const bencode::BDE& elemList = *itr;
+ const BDE& elemList = *itr;
if(!elemList.isList()) {
continue;
}
std::deque<std::string> urls;
- for(bencode::BDE::List::const_iterator elemItr = elemList.listBegin();
+ for(BDE::List::const_iterator elemItr = elemList.listBegin();
elemItr != elemList.listEnd(); ++elemItr) {
- const bencode::BDE& url = (*elemItr);
+ const BDE& url = (*elemItr);
if(url.isString()) {
urls.push_back(Util::trim(url.s()));
}
@@ -235,13 +235,13 @@ void DefaultBtContext::extractAnnounceList(const bencode::BDE& announceList)
}
}
-void DefaultBtContext::extractAnnounce(const bencode::BDE& rootDict)
+void DefaultBtContext::extractAnnounce(const BDE& rootDict)
{
- const bencode::BDE& announceList = rootDict[BtContext::C_ANNOUNCE_LIST];
+ const BDE& announceList = rootDict[BtContext::C_ANNOUNCE_LIST];
if(announceList.isList()) {
extractAnnounceList(announceList);
} else {
- const bencode::BDE& announce = rootDict[BtContext::C_ANNOUNCE];
+ const BDE& announce = rootDict[BtContext::C_ANNOUNCE];
if(announce.isString()) {
extractAnnounceURI(announce);
}
@@ -249,10 +249,10 @@ void DefaultBtContext::extractAnnounce(const bencode::BDE& rootDict)
}
void DefaultBtContext::extractUrlList(std::deque<std::string>& uris,
- const bencode::BDE& bde)
+ const BDE& bde)
{
if(bde.isList()) {
- for(bencode::BDE::List::const_iterator itr = bde.listBegin();
+ for(BDE::List::const_iterator itr = bde.listBegin();
itr != bde.listEnd(); ++itr) {
if((*itr).isString()) {
uris.push_back((*itr).s());
@@ -263,25 +263,25 @@ void DefaultBtContext::extractUrlList(std::deque<std::string>& uris,
}
}
-void DefaultBtContext::extractNodes(const bencode::BDE& nodesList)
+void DefaultBtContext::extractNodes(const BDE& nodesList)
{
if(!nodesList.isList()) {
return;
}
- for(bencode::BDE::List::const_iterator i = nodesList.listBegin();
+ for(BDE::List::const_iterator i = nodesList.listBegin();
i != nodesList.listEnd(); ++i) {
- const bencode::BDE& addrPairList = (*i);
+ const BDE& addrPairList = (*i);
if(!addrPairList.isList() || addrPairList.size() != 2) {
continue;
}
- const bencode::BDE& hostname = addrPairList[0];
+ const BDE& hostname = addrPairList[0];
if(!hostname.isString()) {
continue;
}
if(Util::trim(hostname.s()).empty()) {
continue;
}
- const bencode::BDE& port = addrPairList[1];
+ const BDE& port = addrPairList[1];
if(!port.isInteger() || !(0 < port.i() && port.i() < 65536)) {
continue;
}
@@ -304,7 +304,7 @@ void DefaultBtContext::load(const std::string& torrentFile,
overrideName);
}
-void DefaultBtContext::processRootDictionary(const bencode::BDE& rootDict,
+void DefaultBtContext::processRootDictionary(const BDE& rootDict,
const std::string& defaultName,
const std::string& overrideName)
{
@@ -312,7 +312,7 @@ void DefaultBtContext::processRootDictionary(const bencode::BDE& rootDict,
if(!rootDict.isDict()) {
throw DlAbortEx("torrent file does not contain a root dictionary.");
}
- const bencode::BDE& infoDict = rootDict[BtContext::C_INFO];
+ const BDE& infoDict = rootDict[BtContext::C_INFO];
if(!infoDict.isDict()) {
throw DlAbortEx(StringFormat(MSG_MISSING_BT_INFO,
BtContext::C_INFO.c_str()).str());
@@ -325,7 +325,7 @@ void DefaultBtContext::processRootDictionary(const bencode::BDE& rootDict,
encodedInfoDict.size());
infoHashString = Util::toHex(infoHash, INFO_HASH_LENGTH);
// calculate the number of pieces
- const bencode::BDE& piecesData = infoDict[BtContext::C_PIECES];
+ const BDE& piecesData = infoDict[BtContext::C_PIECES];
if(!piecesData.isString()) {
throw DlAbortEx(StringFormat(MSG_MISSING_BT_INFO,
BtContext::C_PIECES.c_str()).str());
@@ -338,7 +338,7 @@ void DefaultBtContext::processRootDictionary(const bencode::BDE& rootDict,
throw DlAbortEx("The number of pieces is 0.");
}
// retrieve piece length
- const bencode::BDE& pieceLengthData = infoDict[BtContext::C_PIECE_LENGTH];
+ const BDE& pieceLengthData = infoDict[BtContext::C_PIECE_LENGTH];
if(!pieceLengthData.isInteger()) {
throw DlAbortEx(StringFormat(MSG_MISSING_BT_INFO,
BtContext::C_PIECE_LENGTH.c_str()).str());
@@ -347,7 +347,7 @@ void DefaultBtContext::processRootDictionary(const bencode::BDE& rootDict,
// retrieve piece hashes
extractPieceHash(piecesData.s(), PIECE_HASH_LENGTH);
// private flag
- const bencode::BDE& privateData = infoDict[BtContext::C_PRIVATE];
+ const BDE& privateData = infoDict[BtContext::C_PRIVATE];
if(privateData.isInteger()) {
_private = (privateData.i() == 1);
}
diff --git a/src/DefaultBtContext.h b/src/DefaultBtContext.h
index c3a12c98..4085891e 100644
--- a/src/DefaultBtContext.h
+++ b/src/DefaultBtContext.h
@@ -43,10 +43,7 @@ namespace aria2 {
class Randomizer;
class Logger;
-
-namespace bencode {
class BDE;
-}
#define INFO_HASH_LENGTH 20
#define PIECE_HASH_LENGTH 20
@@ -74,19 +71,19 @@ private:
void clear();
void extractPieceHash(const std::string& hashData, size_t hashLength);
- void extractFileEntries(const bencode::BDE& infoDic,
+ void extractFileEntries(const BDE& infoDic,
const std::string& defaultName,
const std::string& overrideName,
const std::deque<std::string>& urlList);
- void extractAnnounceURI(const bencode::BDE& announceData);
- void extractAnnounceList(const bencode::BDE& announceListData);
- void extractAnnounce(const bencode::BDE& rootDict);
+ void extractAnnounceURI(const BDE& announceData);
+ void extractAnnounceList(const BDE& announceListData);
+ void extractAnnounce(const BDE& rootDict);
- void extractUrlList(std::deque<std::string>& uris, const bencode::BDE& obj);
+ void extractUrlList(std::deque<std::string>& uris, const BDE& obj);
- void extractNodes(const bencode::BDE& nodes);
+ void extractNodes(const BDE& nodes);
- void processRootDictionary(const bencode::BDE& rootDic,
+ void processRootDictionary(const BDE& rootDic,
const std::string& defaultName,
const std::string& overrideName);
diff --git a/src/HandshakeExtensionMessage.cc b/src/HandshakeExtensionMessage.cc
index 6344d2ea..3d107e95 100644
--- a/src/HandshakeExtensionMessage.cc
+++ b/src/HandshakeExtensionMessage.cc
@@ -55,14 +55,14 @@ HandshakeExtensionMessage::~HandshakeExtensionMessage() {}
std::string HandshakeExtensionMessage::getBencodedData()
{
- bencode::BDE dict = bencode::BDE::dict();
+ BDE dict = BDE::dict();
if(!_clientVersion.empty()) {
dict["v"] = _clientVersion;
}
if(_tcpPort > 0) {
dict["p"] = _tcpPort;
}
- bencode::BDE extDict = bencode::BDE::dict();
+ BDE extDict = BDE::dict();
for(std::map<std::string, uint8_t>::const_iterator itr = _extensions.begin();
itr != _extensions.end(); ++itr) {
const std::map<std::string, uint8_t>::value_type& vt = *itr;
@@ -133,21 +133,21 @@ HandshakeExtensionMessage::create(const unsigned char* data, size_t length)
HandshakeExtensionMessageHandle msg(new HandshakeExtensionMessage());
msg->_logger->debug("Creating HandshakeExtensionMessage from %s",
Util::urlencode(data, length).c_str());
- const bencode::BDE dict = bencode::decode(data+1, length-1);
+ const BDE dict = bencode::decode(data+1, length-1);
if(!dict.isDict()) {
throw DlAbortEx("Unexpected payload format for extended message handshake");
}
- const bencode::BDE& port = dict["p"];
+ const BDE& port = dict["p"];
if(port.isInteger() && 0 < port.i() && port.i() < 65536) {
msg->_tcpPort = port.i();
}
- const bencode::BDE& version = dict["v"];
+ const BDE& version = dict["v"];
if(version.isString()) {
msg->_clientVersion = version.s();
}
- const bencode::BDE& extDict = dict["m"];
+ const BDE& extDict = dict["m"];
if(extDict.isDict()) {
- for(bencode::BDE::Dict::const_iterator i = extDict.dictBegin();
+ for(BDE::Dict::const_iterator i = extDict.dictBegin();
i != extDict.dictEnd(); ++i) {
if((*i).second.isInteger()) {
msg->_extensions[(*i).first] = (*i).second.i();
diff --git a/src/Makefile.am b/src/Makefile.am
index fa61578a..694af206 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -205,7 +205,8 @@ SRCS = Socket.h\
HttpServer.cc HttpServer.h\
PieceSelector.h\
LongestSequencePieceSelector.cc LongestSequencePieceSelector.h\
- bitfield.h
+ bitfield.h\
+ BDE.cc BDE.h
if HAVE_POSIX_FALLOCATE
SRCS += FallocFileAllocationIterator.cc FallocFileAllocationIterator.h
diff --git a/src/Makefile.in b/src/Makefile.in
index 4eca3e3d..b085f827 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -409,7 +409,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
HttpServerCommand.h HttpServerResponseCommand.cc \
HttpServerResponseCommand.h HttpServer.cc HttpServer.h \
PieceSelector.h LongestSequencePieceSelector.cc \
- LongestSequencePieceSelector.h bitfield.h \
+ LongestSequencePieceSelector.h bitfield.h BDE.cc BDE.h \
FallocFileAllocationIterator.cc FallocFileAllocationIterator.h \
EpollEventPoll.cc EpollEventPoll.h TLSContext.h \
LibgnutlsTLSContext.cc LibgnutlsTLSContext.h \
@@ -804,14 +804,15 @@ am__objects_23 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
SelectEventPoll.$(OBJEXT) HttpListenCommand.$(OBJEXT) \
HttpServerCommand.$(OBJEXT) \
HttpServerResponseCommand.$(OBJEXT) HttpServer.$(OBJEXT) \
- LongestSequencePieceSelector.$(OBJEXT) $(am__objects_1) \
- $(am__objects_2) $(am__objects_3) $(am__objects_4) \
- $(am__objects_5) $(am__objects_6) $(am__objects_7) \
- $(am__objects_8) $(am__objects_9) $(am__objects_10) \
- $(am__objects_11) $(am__objects_12) $(am__objects_13) \
- $(am__objects_14) $(am__objects_15) $(am__objects_16) \
- $(am__objects_17) $(am__objects_18) $(am__objects_19) \
- $(am__objects_20) $(am__objects_21) $(am__objects_22)
+ LongestSequencePieceSelector.$(OBJEXT) BDE.$(OBJEXT) \
+ $(am__objects_1) $(am__objects_2) $(am__objects_3) \
+ $(am__objects_4) $(am__objects_5) $(am__objects_6) \
+ $(am__objects_7) $(am__objects_8) $(am__objects_9) \
+ $(am__objects_10) $(am__objects_11) $(am__objects_12) \
+ $(am__objects_13) $(am__objects_14) $(am__objects_15) \
+ $(am__objects_16) $(am__objects_17) $(am__objects_18) \
+ $(am__objects_19) $(am__objects_20) $(am__objects_21) \
+ $(am__objects_22)
am_libaria2c_a_OBJECTS = $(am__objects_23)
libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
am__installdirs = "$(DESTDIR)$(bindir)"
@@ -1139,14 +1140,15 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
HttpServerCommand.h HttpServerResponseCommand.cc \
HttpServerResponseCommand.h HttpServer.cc HttpServer.h \
PieceSelector.h LongestSequencePieceSelector.cc \
- LongestSequencePieceSelector.h bitfield.h $(am__append_1) \
- $(am__append_2) $(am__append_3) $(am__append_4) \
- $(am__append_5) $(am__append_6) $(am__append_7) \
- $(am__append_8) $(am__append_9) $(am__append_10) \
- $(am__append_11) $(am__append_12) $(am__append_13) \
- $(am__append_14) $(am__append_15) $(am__append_16) \
- $(am__append_17) $(am__append_18) $(am__append_19) \
- $(am__append_20) $(am__append_21) $(am__append_22)
+ LongestSequencePieceSelector.h bitfield.h BDE.cc BDE.h \
+ $(am__append_1) $(am__append_2) $(am__append_3) \
+ $(am__append_4) $(am__append_5) $(am__append_6) \
+ $(am__append_7) $(am__append_8) $(am__append_9) \
+ $(am__append_10) $(am__append_11) $(am__append_12) \
+ $(am__append_13) $(am__append_14) $(am__append_15) \
+ $(am__append_16) $(am__append_17) $(am__append_18) \
+ $(am__append_19) $(am__append_20) $(am__append_21) \
+ $(am__append_22)
noinst_LIBRARIES = libaria2c.a
libaria2c_a_SOURCES = $(SRCS)
aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
@@ -1251,6 +1253,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfig.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfigFactory.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AutoSaveCommand.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BDE.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BNode.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BitfieldMan.Po@am__quote@
diff --git a/src/PeerListProcessor.h b/src/PeerListProcessor.h
index 67d12930..04d79c4a 100644
--- a/src/PeerListProcessor.h
+++ b/src/PeerListProcessor.h
@@ -45,7 +45,7 @@ namespace aria2 {
class PeerListProcessor {
public:
template<typename OutputIterator>
- void extractPeer(const bencode::BDE& peerData, OutputIterator dest)
+ void extractPeer(const BDE& peerData, OutputIterator dest)
{
if(peerData.isList()) {
extractPeerFromList(peerData, dest);
@@ -55,18 +55,18 @@ public:
}
template<typename OutputIterator>
- void extractPeerFromList(const bencode::BDE& peerData, OutputIterator dest)
+ void extractPeerFromList(const BDE& peerData, OutputIterator dest)
{
- for(bencode::BDE::List::const_iterator itr = peerData.listBegin();
+ for(BDE::List::const_iterator itr = peerData.listBegin();
itr != peerData.listEnd(); ++itr) {
- const bencode::BDE& peerDict = *itr;
+ const BDE& peerDict = *itr;
if(!peerDict.isDict()) {
continue;
}
static const std::string IP = "ip";
static const std::string PORT = "port";
- const bencode::BDE& ip = peerDict[IP];
- const bencode::BDE& port = peerDict[PORT];
+ const BDE& ip = peerDict[IP];
+ const BDE& port = peerDict[PORT];
if(!ip.isString() || !port.isInteger() ||
!(0 < port.i() && port.i() < 65536)) {
continue;
@@ -77,7 +77,7 @@ public:
}
template<typename OutputIterator>
- void extractPeerFromCompact(const bencode::BDE& peerData, OutputIterator dest)
+ void extractPeerFromCompact(const BDE& peerData, OutputIterator dest)
{
size_t length = peerData.s().size();
if(length%6 == 0) {
diff --git a/src/UTPexExtensionMessage.cc b/src/UTPexExtensionMessage.cc
index 7fa05dcc..d20c5295 100644
--- a/src/UTPexExtensionMessage.cc
+++ b/src/UTPexExtensionMessage.cc
@@ -62,7 +62,7 @@ std::string UTPexExtensionMessage::getBencodedData()
std::pair<std::string, std::string> droppedPeerPair =
createCompactPeerListAndFlag(_droppedPeers);
- bencode::BDE dict = bencode::BDE::dict();
+ BDE dict = BDE::dict();
dict["added"] = freshPeerPair.first;
dict["added.f"] = freshPeerPair.second;
dict["dropped"] = droppedPeerPair.first;
@@ -172,14 +172,14 @@ UTPexExtensionMessage::create(const unsigned char* data, size_t len)
}
UTPexExtensionMessageHandle msg(new UTPexExtensionMessage(*data));
- const bencode::BDE dict = bencode::decode(data+1, len-1);
+ const BDE dict = bencode::decode(data+1, len-1);
if(dict.isDict()) {
PeerListProcessor proc;
- const bencode::BDE& added = dict["added"];
+ const BDE& added = dict["added"];
if(added.isString()) {
proc.extractPeerFromCompact(added, std::back_inserter(msg->_freshPeers));
}
- const bencode::BDE& dropped = dict["dropped"];
+ const BDE& dropped = dict["dropped"];
if(dropped.isString()) {
proc.extractPeerFromCompact(dropped,
std::back_inserter(msg->_droppedPeers));
diff --git a/src/bencode.cc b/src/bencode.cc
index 5ca10fb3..9b43261e 100644
--- a/src/bencode.cc
+++ b/src/bencode.cc
@@ -38,195 +38,12 @@
#include <sstream>
#include "StringFormat.h"
-#include "Util.h"
+#include "RecoverableException.h"
namespace aria2 {
namespace bencode {
-const BDE BDE::none;
-
-BDE::BDE():_type(TYPE_NONE) {}
-
-BDE::BDE(Integer integer):_type(TYPE_INTEGER),
- _bobject(new BInteger(integer)) {}
-
-
-BDE::BDE(const std::string& string):_type(TYPE_STRING),
- _bobject(new BString(std::string(string))) {}
-
-BDE::BDE(const char* cstring):_type(TYPE_STRING),
- _bobject(new BString(std::string(cstring))) {}
-
-BDE::BDE(const char* data, size_t length):
- _type(TYPE_STRING),
- _bobject(new BString(std::string(&data[0], &data[length]))) {}
-
-BDE::BDE(const unsigned char* data, size_t length):
- _type(TYPE_STRING),
- _bobject(new BString(std::string(&data[0], &data[length]))) {}
-
-BDE BDE::dict()
-{
- BDE bde;
- bde._type = TYPE_DICT;
- bde._bobject.reset(new BDict());
- return bde;
-}
-
-BDE BDE::list()
-{
- BDE bde;
- bde._type = TYPE_LIST;
- bde._bobject.reset(new BList());
- return bde;
-}
-
-// Test for Null data
-bool BDE::isNone() const
-{
- return _type == TYPE_NONE;
-}
-
-// Integer Interface
-
-bool BDE::isInteger() const
-{
- return _type == TYPE_INTEGER;
-}
-
-BDE::Integer BDE::i() const
-{
- return _bobject->i();
-}
-
-// String Interface
-
-bool BDE::isString() const
-{
- return _type == TYPE_STRING;
-}
-
-const std::string& BDE::s() const
-{
- return _bobject->s();
-}
-
-const unsigned char* BDE::uc() const
-{
- return _bobject->uc();
-}
-
-// Dictionary Interface
-
-bool BDE::isDict() const
-{
- return _type == TYPE_DICT;
-}
-
-BDE& BDE::operator[](const std::string& key)
-{
- return _bobject->operator[](key);
-}
-
-const BDE& BDE::operator[](const std::string& key) const
-{
- if(_bobject->containsKey(key)) {
- return _bobject->operator[](key);
- } else {
- return none;
- }
-}
-
-bool BDE::containsKey(const std::string& key) const
-{
- return _bobject->containsKey(key);
-}
-
-void BDE::removeKey(const std::string& key)
-{
- _bobject->removeKey(key);
-}
-
-BDE::Dict::iterator BDE::dictBegin()
-{
- return _bobject->dictBegin();
-}
-
-BDE::Dict::const_iterator BDE::dictBegin() const
-{
- return _bobject->dictBegin();
-}
-
-BDE::Dict::iterator BDE::dictEnd()
-{
- return _bobject->dictEnd();
-}
-
-BDE::Dict::const_iterator BDE::dictEnd() const
-{
- return _bobject->dictEnd();
-}
-
-// List Interface
-
-bool BDE::isList() const
-{
- return _type == TYPE_LIST;
-}
-
-void BDE::append(const BDE& bde)
-{
- _bobject->append(bde);
-}
-
-void BDE::operator<<(const BDE& bde)
-{
- _bobject->operator<<(bde);
-}
-
-BDE& BDE::operator[](size_t index)
-{
- return _bobject->operator[](index);
-}
-
-const BDE& BDE::operator[](size_t index) const
-{
- return _bobject->operator[](index);
-}
-
-BDE::List::iterator BDE::listBegin()
-{
- return _bobject->listBegin();
-}
-
-BDE::List::const_iterator BDE::listBegin() const
-{
- return _bobject->listBegin();
-}
-
-BDE::List::iterator BDE::listEnd()
-{
- return _bobject->listEnd();
-}
-
-BDE::List::const_iterator BDE::listEnd() const
-{
- return _bobject->listEnd();
-}
-
-// Callable from List and Dict
-size_t BDE::size() const
-{
- return _bobject->size();
-}
-
-// Callable from List and Dict
-bool BDE::empty() const
-{
- return _bobject->empty();
-}
-
static BDE decodeiter(std::istream& ss);
static void checkdelim(std::istream& ss, const char delim = ':')
diff --git a/src/bencode.h b/src/bencode.h
index 568b98fe..a1630f72 100644
--- a/src/bencode.h
+++ b/src/bencode.h
@@ -38,398 +38,14 @@
#include "common.h"
#include <string>
-#include <map>
-#include <deque>
#include <iosfwd>
-#include "SharedHandle.h"
-#include "A2STR.h"
-#include "RecoverableException.h"
+#include "BDE.h"
namespace aria2 {
namespace bencode {
-class BDE;
-
-class BDE {
-public:
- typedef std::map<std::string, BDE> Dict;
- typedef std::deque<BDE> List;
- typedef int64_t Integer;
-private:
- enum TYPE{
- TYPE_NONE,
- TYPE_INTEGER,
- TYPE_STRING,
- TYPE_DICT,
- TYPE_LIST,
- };
-
- class BObject {
- public:
- virtual ~BObject() {}
-
- ////////////////////////////////////////////////////////////////////////////
- // Integer Interface
-
- // Returns Integer.
- virtual Integer i() const
- {
- throw RecoverableException("Not Integer");
- }
-
- ////////////////////////////////////////////////////////////////////////////
- // String Interface
-
- // Returns std::string.
- virtual const std::string& s() const
- {
- throw RecoverableException("Not String");
- }
-
- // Returns std::string.data() casted to unsigned char*.
- // Use s().size() to get length.
- virtual const unsigned char* uc() const
- {
- throw RecoverableException("Not String");
- }
-
- ////////////////////////////////////////////////////////////////////////////
- // Dictionary Interface
-
- // Returns the reference to BDE object associated with given key.
- // If the key is not found, new pair with that key is created
- // using default values, which is then returned. In other words,
- // this is the same behavior of std::map's operator[].
- virtual BDE& operator[](const std::string& key)
- {
- throw RecoverableException("Not Dict");
- }
-
- // Returns true if the given key is found in dict.
- virtual bool containsKey(const std::string& key) const
- {
- throw RecoverableException("Not Dict");
- }
-
- // Removes specified key from dict.
- virtual void removeKey(const std::string& key)
- {
- throw RecoverableException("Not Dict");
- }
-
- // Returns a read/write iterator that points to the first pair in
- // the dict.
- virtual Dict::iterator dictBegin()
- {
- throw RecoverableException("Not Dict");
- }
-
- // Returns a read/write read-only iterator that points to one past
- // the last pair in the dict.
- virtual Dict::iterator dictEnd()
- {
- throw RecoverableException("Not Dict");
- }
-
- ////////////////////////////////////////////////////////////////////////////
- // List Interface
-
- // Appends given bde to list.
- virtual void append(const BDE& bde)
- {
- throw RecoverableException("Not List");
- }
-
- // Alias for append()
- virtual void operator<<(const BDE& bde)
- {
- throw RecoverableException("Not List");
- }
-
- // Returns the reference of the object at the given index.
- virtual BDE& operator[](size_t index)
- {
- throw RecoverableException("Not List");
- }
-
- // Returns a read/write iterator that points to the first object
- // in list.
- virtual List::iterator listBegin()
- {
- throw RecoverableException("Not List");
- }
-
- // Returns a read/write iterator that points to the one past the
- // last object in list.
- virtual List::iterator listEnd()
- {
- throw RecoverableException("Not List");
- }
-
- // Returns size of list or dict.
- virtual size_t size() const
- {
- throw RecoverableException("Neither Dict nor List");
- }
-
- // Returns true if size of list or dict is 0.
- virtual bool empty() const
- {
- throw RecoverableException("Neither Dict nor List");
- }
- };
-
- class BInteger : public BObject {
- private:
- Integer _integer;
- public:
- BInteger(Integer i):_integer(i) {}
-
- virtual BDE::Integer i() const
- {
- return _integer;
- }
- };
-
- class BString : public BObject {
- private:
- std::string _string;
- public:
- BString(const std::string& string):_string(string) {}
-
- virtual const std::string& s() const
- {
- return _string;
- }
-
- virtual const unsigned char* uc() const
- {
- return reinterpret_cast<const unsigned char*>(_string.data());
- }
- };
-
- class BDict : public BObject {
- private:
- Dict _dict;
- public:
-
- virtual BDE& operator[](const std::string& key)
- {
- return _dict[key];
- }
-
- virtual bool containsKey(const std::string& key) const
- {
- return _dict.find(key) != _dict.end();
- }
-
- virtual void removeKey(const std::string& key)
- {
- _dict.erase(key);
- }
-
- virtual BDE::Dict::iterator dictBegin()
- {
- return _dict.begin();
- }
-
- virtual BDE::Dict::iterator dictEnd()
- {
- return _dict.end();
- }
-
- virtual size_t size() const
- {
- return _dict.size();
- }
-
- virtual bool empty() const
- {
- return _dict.empty();
- }
- };
-
- class BList : public BObject {
- private:
- List _list;
- public:
- virtual void append(const BDE& bde)
- {
- _list.push_back(bde);
- }
-
- virtual void operator<<(const BDE& bde)
- {
- _list.push_back(bde);
- }
-
- virtual BDE& operator[](size_t index)
- {
- return _list[index];
- }
-
- virtual BDE::List::iterator listBegin()
- {
- return _list.begin();
- }
-
- virtual BDE::List::iterator listEnd()
- {
- return _list.end();
- }
-
- virtual size_t size() const
- {
- return _list.size();
- }
-
- virtual bool empty() const
- {
- return _list.empty();
- }
- };
-
- TYPE _type;
-
- SharedHandle<BObject> _bobject;
-public:
- BDE();
-
- static BDE dict();
-
- static BDE list();
-
- static const BDE none;
-
- // Test for Null data
- // Return true if the type of this object is None.
- bool isNone() const;
-
- //////////////////////////////////////////////////////////////////////////////
- // Integer Interface
-
- BDE(Integer integer);
-
- // Returns true if the type of this object is Integer.
- bool isInteger() const;
-
- // Returns Integer. Requires this object to be Integer.
- Integer i() const;
-
- //////////////////////////////////////////////////////////////////////////////
- // String Interface
-
- BDE(const std::string& string);
-
- // Made explicit to avoid ambiguity with BDE(Integer).
- explicit BDE(const char* cstring);
-
- BDE(const char* data, size_t length);
-
- BDE(const unsigned char* data, size_t length);
-
- // Returns true if the type of this object is String.
- bool isString() const;
-
- // Returns std::string. Requires this object to be String
- const std::string& s() const;
-
- // Returns std::string.data() casted to unsigned char*.
- // Use s().size() to get length.
- const unsigned char* uc() const;
-
- //////////////////////////////////////////////////////////////////////////////
- // Dictionary Interface
-
- // Returns true if the type of this object is Dict.
- bool isDict() const;
-
- // Returns the reference to BDE object associated with given key.
- // If the key is not found, new pair with that key is created using default
- // values, which is then returned. In other words, this is the same behavior
- // of std::map's operator[].
- // Requires this object to be Dict.
- BDE& operator[](const std::string& key);
-
- // Returns the const reference to BDE ojbect associated with given key.
- // If the key is not found, BDE::none is returned.
- // Requires this object to be Dict.
- const BDE& operator[](const std::string& key) const;
-
- // Returns true if the given key is found in dict.
- // Requires this object to be Dict.
- bool containsKey(const std::string& key) const;
-
- // Removes specified key from dict.
- // Requires this object to be Dict.
- void removeKey(const std::string& key);
-
- // Returns a read/write iterator that points to the first pair in the dict.
- // Requires this object to be Dict.
- Dict::iterator dictBegin();
-
- // Returns a read/write read-only iterator that points to the first pair in
- // the dict.
- // Requires this object to be Dict.
- Dict::const_iterator dictBegin() const;
-
- // Returns a read/write read-only iterator that points to one past the last
- // pair in the dict.
- // Requires this object to be Dict.
- Dict::iterator dictEnd();
-
- // Returns a read/write read-only iterator that points to one past the last
- // pair in the dict.
- // Requires this object to be Dict.
- Dict::const_iterator dictEnd() const;
-
- //////////////////////////////////////////////////////////////////////////////
- // List Interface
-
- // Returns true if the type of this object is List.
- bool isList() const;
-
- // Appends given bde to list. Required the type of this object to be List.
- void append(const BDE& bde);
-
- // Alias for append()
- void operator<<(const BDE& bde);
-
- // Returns the reference of the object at the given index. Required this
- // object to be List.
- BDE& operator[](size_t index);
-
- // Returns the const reference of the object at the given index.
- // Required this object to be List.
- const BDE& operator[](size_t index) const;
-
- // Returns a read/write iterator that points to the first object in list.
- // Required this object to be List.
- List::iterator listBegin();
-
- // Returns a read/write read-only iterator that points to the first object
- // in list. Required this object to be List.
- List::const_iterator listBegin() const;
-
- // Returns a read/write iterator that points to the one past the last object
- // in list. Required this object to be List.
- List::iterator listEnd();
-
- // Returns a read/write read-only iterator that points to the one past the
- // last object in list. Required this object to be List.
- List::const_iterator listEnd() const;
-
- // For List type: Returns size of list.
- // For Dict type: Returns size of dict.
- size_t size() const;
-
- // For List type: Returns true if size of list is 0.
- // For Dict type: Returns true if size of dict is 0.
- bool empty() const;
-};
-
BDE decode(std::istream& in);
// Decode the data in s.