浏览代码

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
Tatsuhiro Tsujikawa 16 年之前
父节点
当前提交
49b4cfbfcd
共有 60 个文件被更改,包括 1207 次插入1044 次删除
  1. 62 0
      ChangeLog
  2. 6 6
      src/AnnounceList.cc
  3. 2 4
      src/AnnounceList.h
  4. 223 0
      src/BDE.cc
  5. 431 0
      src/BDE.h
  6. 1 1
      src/DHTAbstractMessage.cc
  7. 1 3
      src/DHTAbstractMessage.h
  8. 4 4
      src/DHTAnnouncePeerMessage.cc
  9. 1 1
      src/DHTAnnouncePeerMessage.h
  10. 3 3
      src/DHTAnnouncePeerReplyMessage.cc
  11. 1 1
      src/DHTAnnouncePeerReplyMessage.h
  12. 4 4
      src/DHTFindNodeMessage.cc
  13. 1 1
      src/DHTFindNodeMessage.h
  14. 4 4
      src/DHTFindNodeReplyMessage.cc
  15. 1 1
      src/DHTFindNodeReplyMessage.h
  16. 4 4
      src/DHTGetPeersMessage.cc
  17. 1 1
      src/DHTGetPeersMessage.h
  18. 6 6
      src/DHTGetPeersReplyMessage.cc
  19. 1 1
      src/DHTGetPeersReplyMessage.h
  20. 2 4
      src/DHTMessageFactory.h
  21. 46 46
      src/DHTMessageFactoryImpl.cc
  22. 7 7
      src/DHTMessageFactoryImpl.h
  23. 2 2
      src/DHTMessageReceiver.cc
  24. 2 2
      src/DHTMessageTracker.cc
  25. 1 3
      src/DHTMessageTracker.h
  26. 3 3
      src/DHTPingMessage.cc
  27. 1 1
      src/DHTPingMessage.h
  28. 3 3
      src/DHTPingReplyMessage.cc
  29. 1 1
      src/DHTPingReplyMessage.h
  30. 1 1
      src/DHTQueryMessage.cc
  31. 2 2
      src/DHTQueryMessage.h
  32. 1 1
      src/DHTResponseMessage.cc
  33. 2 2
      src/DHTResponseMessage.h
  34. 9 9
      src/DefaultBtAnnounce.cc
  35. 30 30
      src/DefaultBtContext.cc
  36. 7 10
      src/DefaultBtContext.h
  37. 7 7
      src/HandshakeExtensionMessage.cc
  38. 2 1
      src/Makefile.am
  39. 20 17
      src/Makefile.in
  40. 7 7
      src/PeerListProcessor.h
  41. 4 4
      src/UTPexExtensionMessage.cc
  42. 1 184
      src/bencode.cc
  43. 1 385
      src/bencode.h
  44. 8 8
      test/AnnounceListTest.cc
  45. 149 0
      test/BDETest.cc
  46. 14 144
      test/BencodeTest.cc
  47. 6 6
      test/DHTAnnouncePeerMessageTest.cc
  48. 4 4
      test/DHTAnnouncePeerReplyMessageTest.cc
  49. 6 6
      test/DHTFindNodeMessageTest.cc
  50. 4 4
      test/DHTFindNodeReplyMessageTest.cc
  51. 6 6
      test/DHTGetPeersMessageTest.cc
  52. 6 6
      test/DHTGetPeersReplyMessageTest.cc
  53. 61 61
      test/DHTMessageFactoryImplTest.cc
  54. 3 3
      test/DHTMessageTrackerTest.cc
  55. 5 5
      test/DHTPingMessageTest.cc
  56. 4 4
      test/DHTPingReplyMessageTest.cc
  57. 2 1
      test/Makefile.am
  58. 6 5
      test/Makefile.in
  59. 2 2
      test/MockDHTMessageFactory.h
  60. 2 2
      test/PeerListProcessorTest.cc

+ 62 - 0
ChangeLog

@@ -1,3 +1,65 @@
+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
+
 2009-04-27  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Use url-list (web-seeding) only for single-file torrent.  This is

+ 6 - 6
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());
 	}

+ 2 - 4
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 {

+ 223 - 0
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

+ 431 - 0
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_

+ 1 - 1
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);

+ 1 - 3
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();
 

+ 4 - 4
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;

+ 1 - 1
src/DHTAnnouncePeerMessage.h

@@ -69,7 +69,7 @@ public:
 
   virtual void doReceivedAction();
 
-  virtual bencode::BDE getArgument();
+  virtual BDE getArgument();
   
   virtual std::string getMessageType() const;
 

+ 3 - 3
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;
 }
 

+ 1 - 1
src/DHTAnnouncePeerReplyMessage.h

@@ -49,7 +49,7 @@ public:
 
   virtual void doReceivedAction();
 
-  virtual bencode::BDE getResponse();
+  virtual BDE getResponse();
 
   virtual std::string getMessageType() const;
 

+ 4 - 4
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;
 }
 

+ 1 - 1
src/DHTFindNodeMessage.h

@@ -55,7 +55,7 @@ public:
 
   virtual void doReceivedAction();
 
-  virtual bencode::BDE getArgument();
+  virtual BDE getArgument();
   
   virtual std::string getMessageType() const;
 

+ 4 - 4
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;
 }
 

+ 1 - 1
src/DHTFindNodeReplyMessage.h

@@ -54,7 +54,7 @@ public:
 
   virtual void doReceivedAction();
 
-  virtual bencode::BDE getResponse();
+  virtual BDE getResponse();
   
   virtual std::string getMessageType() const;
 

+ 4 - 4
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;
 }
 

+ 1 - 1
src/DHTGetPeersMessage.h

@@ -63,7 +63,7 @@ public:
 
   virtual void doReceivedAction();
 
-  virtual bencode::BDE getArgument();
+  virtual BDE getArgument();
   
   virtual std::string getMessageType() const;
 

+ 6 - 6
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;

+ 1 - 1
src/DHTGetPeersReplyMessage.h

@@ -64,7 +64,7 @@ public:
 
   virtual void doReceivedAction();
 
-  virtual bencode::BDE getResponse();
+  virtual BDE getResponse();
 
   virtual std::string getMessageType() const;
 

+ 2 - 4
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>

+ 46 - 46
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);
 }

+ 7 - 7
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>

+ 2 - 2
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;

+ 2 - 2
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());

+ 1 - 3
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();

+ 3 - 3
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;
 }
 

+ 1 - 1
src/DHTPingMessage.h

@@ -50,7 +50,7 @@ public:
 
   virtual void doReceivedAction();
 
-  virtual bencode::BDE getArgument();
+  virtual BDE getArgument();
 
   virtual std::string getMessageType() const;
 

+ 3 - 3
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;
 }
 

+ 1 - 1
src/DHTPingReplyMessage.h

@@ -53,7 +53,7 @@ public:
 
   virtual void doReceivedAction();
 
-  virtual bencode::BDE getResponse();
+  virtual BDE getResponse();
 
   virtual std::string getMessageType() const;
 

+ 1 - 1
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();

+ 2 - 2
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;
 

+ 1 - 1
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();
 }

+ 2 - 2
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;
 

+ 9 - 9
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 {

+ 30 - 30
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);
   }

+ 7 - 10
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);
 

+ 7 - 7
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();

+ 2 - 1
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

+ 20 - 17
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@

+ 7 - 7
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) {

+ 4 - 4
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));

+ 1 - 184
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 = ':')

+ 1 - 385
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.

+ 8 - 8
test/AnnounceListTest.cc

@@ -44,7 +44,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( AnnounceListTest );
 
 void AnnounceListTest::testSingleElementList() {
   std::string peersString = "ll8:tracker1el8:tracker2el8:tracker3ee";
-  const bencode::BDE announcesList = bencode::decode(peersString);
+  const BDE announcesList = bencode::decode(peersString);
 
   // ANNOUNCE_LIST
   // [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ]
@@ -90,7 +90,7 @@ void AnnounceListTest::testSingleElementList() {
 
 void AnnounceListTest::testMultiElementList() {
   std::string peersString = "ll8:tracker18:tracker28:tracker3ee";
-  const bencode::BDE announcesList = bencode::decode(peersString);
+  const BDE announcesList = bencode::decode(peersString);
 
   // ANNOUNCE_LIST
   // [ [ tracker1, tracker2, tracker3 ] ]
@@ -123,7 +123,7 @@ void AnnounceListTest::testMultiElementList() {
 
 void AnnounceListTest::testSingleAndMulti() {
   std::string peersString = "ll8:tracker18:tracker2el8:tracker3ee";
-  const bencode::BDE announcesList = bencode::decode(peersString);
+  const BDE announcesList = bencode::decode(peersString);
 
   // ANNOUNCE_LIST
   // [ [ tracker1, tracker2 ], [ tracker3 ] ]
@@ -149,7 +149,7 @@ void AnnounceListTest::testSingleAndMulti() {
 
 void AnnounceListTest::testNoGroup() {
   std::string peersString = "llee";
-  const bencode::BDE announcesList = bencode::decode(peersString);
+  const BDE announcesList = bencode::decode(peersString);
 
   AnnounceList announceList(announcesList);
 
@@ -158,7 +158,7 @@ void AnnounceListTest::testNoGroup() {
 
 void AnnounceListTest::testNextEventIfAfterStarted() {
   std::string peersString = "ll8:tracker1ee";
-  const bencode::BDE announcesList = bencode::decode(peersString);
+  const BDE announcesList = bencode::decode(peersString);
 
   // ANNOUNCE_LIST
   // [ [ tracker1 ] ]
@@ -178,7 +178,7 @@ void AnnounceListTest::testNextEventIfAfterStarted() {
 
 void AnnounceListTest::testEvent() {
   std::string peersString = "ll8:tracker1el8:tracker2el8:tracker3ee";
-  const bencode::BDE announcesList = bencode::decode(peersString);
+  const BDE announcesList = bencode::decode(peersString);
 
   // ANNOUNCE_LIST
   // [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ]
@@ -202,7 +202,7 @@ void AnnounceListTest::testEvent() {
 
 void AnnounceListTest::testCountStoppedAllowedTier() {
   std::string peersString = "ll8:tracker1el8:tracker2el8:tracker3ee";
-  const bencode::BDE announcesList = bencode::decode(peersString);
+  const BDE announcesList = bencode::decode(peersString);
 
   // ANNOUNCE_LIST
   // [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ]
@@ -229,7 +229,7 @@ void AnnounceListTest::testCountStoppedAllowedTier() {
 
 void AnnounceListTest::testCountCompletedAllowedTier() {
   std::string peersString = "ll8:tracker1el8:tracker2el8:tracker3ee";
-  const bencode::BDE announcesList = bencode::decode(peersString);
+  const BDE announcesList = bencode::decode(peersString);
 
   // ANNOUNCE_LIST
   // [ [ tracker1 ], [ tracker2 ], [ tracker3 ] ]

+ 149 - 0
test/BDETest.cc

@@ -0,0 +1,149 @@
+#include "BDE.h"
+
+#include <cstring>
+
+#include <cppunit/extensions/HelperMacros.h>
+
+#include "Util.h"
+
+namespace aria2 {
+
+class BDETest:public CppUnit::TestFixture {
+
+  CPPUNIT_TEST_SUITE(BDETest);
+  CPPUNIT_TEST(testString);
+  CPPUNIT_TEST(testInteger);
+  CPPUNIT_TEST(testDict);
+  CPPUNIT_TEST(testDictIter);
+  CPPUNIT_TEST(testList);
+  CPPUNIT_TEST(testListIter);
+  CPPUNIT_TEST_SUITE_END();
+private:
+
+public:
+  void testString();
+  void testInteger();
+  void testDict();
+  void testDictIter();
+  void testList();
+  void testListIter();
+  void testDecode();
+  void testEncode();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION( BDETest );
+
+void BDETest::testString()
+{
+  BDE s(std::string("aria2"));
+  CPPUNIT_ASSERT_EQUAL(std::string("aria2"), s.s());
+
+  unsigned char dataWithNull[] = { 0xf0, '\0', 0x0f };
+  BDE sWithNull(dataWithNull, sizeof(dataWithNull));
+  CPPUNIT_ASSERT(memcmp(dataWithNull, sWithNull.s().c_str(),
+			sizeof(dataWithNull)) == 0);
+
+  BDE zero("");
+  CPPUNIT_ASSERT_EQUAL(std::string(""), zero.s());
+
+  const unsigned char uc[] = { 0x08, 0x19, 0x2a, 0x3b };
+  BDE data(uc, sizeof(uc));
+  CPPUNIT_ASSERT_EQUAL(Util::toHex(uc, sizeof(uc)),
+		       Util::toHex(data.uc(), data.s().size()));
+}
+
+void BDETest::testInteger()
+{
+  BDE integer(INT64_MAX);
+  CPPUNIT_ASSERT_EQUAL(INT64_MAX, integer.i());
+}
+
+void BDETest::testDict()
+{
+  BDE dict = BDE::dict();
+  CPPUNIT_ASSERT(dict.empty());
+
+  dict["ki"] = 7;
+  dict["ks"] = std::string("abc");
+
+  CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), dict.size());
+  CPPUNIT_ASSERT(dict.containsKey("ki"));
+  CPPUNIT_ASSERT_EQUAL(static_cast<BDE::Integer>(7), dict["ki"].i());
+  CPPUNIT_ASSERT(dict.containsKey("ks"));
+  CPPUNIT_ASSERT_EQUAL(std::string("abc"), dict["ks"].s());
+
+  CPPUNIT_ASSERT(dict["kn"].isNone()); // This adds kn key with default value.
+  CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), dict.size());
+  CPPUNIT_ASSERT(dict.containsKey("kn"));
+
+  const BDE& ref = dict;
+  ref["kn2"]; // This doesn't add kn2 key.
+  CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), ref.size());
+  CPPUNIT_ASSERT(!ref.containsKey("kn2"));
+
+  dict.removeKey("kn");
+  CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), dict.size());
+  CPPUNIT_ASSERT(!dict.containsKey("kn"));
+}
+
+void BDETest::testDictIter()
+{
+  BDE dict = BDE::dict();
+  dict["alpha2"] = std::string("alpha2");
+  dict["charlie"] = std::string("charlie");
+  dict["bravo"] = std::string("bravo");
+  dict["alpha"] = std::string("alpha");
+
+  BDE::Dict::iterator i = dict.dictBegin();
+  CPPUNIT_ASSERT_EQUAL(std::string("alpha"), (*i++).first); 
+  CPPUNIT_ASSERT_EQUAL(std::string("alpha2"), (*i++).first);
+  CPPUNIT_ASSERT_EQUAL(std::string("bravo"), (*i++).first);
+  CPPUNIT_ASSERT_EQUAL(std::string("charlie"), (*i++).first);
+  CPPUNIT_ASSERT(dict.dictEnd() == i);
+
+  const BDE& ref = dict;
+  BDE::Dict::const_iterator ci = ref.dictBegin();
+  CPPUNIT_ASSERT_EQUAL(std::string("alpha"), (*ci++).first);
+  std::advance(ci, 3);
+  CPPUNIT_ASSERT(ref.dictEnd() == ci);
+}
+
+void BDETest::testList()
+{
+  BDE list = BDE::list();
+  CPPUNIT_ASSERT(list.empty());
+  list << 7;
+  list << std::string("aria2");
+
+  CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), list.size());
+  CPPUNIT_ASSERT_EQUAL(static_cast<BDE::Integer>(7), list[0].i());
+  CPPUNIT_ASSERT_EQUAL(std::string("aria2"), list[1].s());
+
+  const BDE& ref = list;
+  CPPUNIT_ASSERT_EQUAL(static_cast<BDE::Integer>(7), ref[0].i());
+  CPPUNIT_ASSERT_EQUAL(std::string("aria2"), ref[1].s());
+}
+
+void BDETest::testListIter()
+{
+  BDE list = BDE::list();
+  list << std::string("alpha2");
+  list << std::string("charlie");
+  list << std::string("bravo");
+  list << std::string("alpha");
+
+  BDE::List::iterator i = list.listBegin();
+  CPPUNIT_ASSERT_EQUAL(std::string("alpha2"), (*i++).s());
+  CPPUNIT_ASSERT_EQUAL(std::string("charlie"), (*i++).s());
+  CPPUNIT_ASSERT_EQUAL(std::string("bravo"), (*i++).s());
+  CPPUNIT_ASSERT_EQUAL(std::string("alpha"), (*i++).s());
+  CPPUNIT_ASSERT(list.listEnd() == i);
+
+  const BDE& ref = list;
+  BDE::List::const_iterator ci = ref.listBegin();
+  CPPUNIT_ASSERT_EQUAL(std::string("alpha2"), (*ci++).s());
+  std::advance(ci, 3);
+  CPPUNIT_ASSERT(ref.listEnd() == ci);
+}
+
+} // namespace aria2

+ 14 - 144
test/BencodeTest.cc

@@ -1,11 +1,7 @@
 #include "bencode.h"
 
-#include <cstring>
-#include <iostream>
-
 #include <cppunit/extensions/HelperMacros.h>
 
-#include "Util.h"
 #include "RecoverableException.h"
 
 namespace aria2 {
@@ -13,155 +9,29 @@ namespace aria2 {
 class BencodeTest:public CppUnit::TestFixture {
 
   CPPUNIT_TEST_SUITE(BencodeTest);
-  CPPUNIT_TEST(testString);
-  CPPUNIT_TEST(testInteger);
-  CPPUNIT_TEST(testDict);
-  CPPUNIT_TEST(testDictIter);
-  CPPUNIT_TEST(testList);
-  CPPUNIT_TEST(testListIter);
   CPPUNIT_TEST(testDecode);
   CPPUNIT_TEST(testEncode);
   CPPUNIT_TEST_SUITE_END();
 private:
 
 public:
-  void testString();
-  void testInteger();
-  void testDict();
-  void testDictIter();
-  void testList();
-  void testListIter();
   void testDecode();
   void testEncode();
 };
 
-
 CPPUNIT_TEST_SUITE_REGISTRATION( BencodeTest );
 
-void BencodeTest::testString()
-{
-  bencode::BDE s(std::string("aria2"));
-  CPPUNIT_ASSERT_EQUAL(std::string("aria2"), s.s());
-
-  unsigned char dataWithNull[] = { 0xf0, '\0', 0x0f };
-  bencode::BDE sWithNull(dataWithNull, sizeof(dataWithNull));
-  CPPUNIT_ASSERT(memcmp(dataWithNull, sWithNull.s().c_str(),
-			sizeof(dataWithNull)) == 0);
-
-  bencode::BDE zero("");
-  CPPUNIT_ASSERT_EQUAL(std::string(""), zero.s());
-
-  const unsigned char uc[] = { 0x08, 0x19, 0x2a, 0x3b };
-  bencode::BDE data(uc, sizeof(uc));
-  CPPUNIT_ASSERT_EQUAL(Util::toHex(uc, sizeof(uc)),
-		       Util::toHex(data.uc(), data.s().size()));
-}
-
-void BencodeTest::testInteger()
-{
-  bencode::BDE integer(INT64_MAX);
-  CPPUNIT_ASSERT_EQUAL(INT64_MAX, integer.i());
-}
-
-void BencodeTest::testDict()
-{
-  bencode::BDE dict = bencode::BDE::dict();
-  CPPUNIT_ASSERT(dict.empty());
-
-  dict["ki"] = 7;
-  dict["ks"] = std::string("abc");
-
-  CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), dict.size());
-  CPPUNIT_ASSERT(dict.containsKey("ki"));
-  CPPUNIT_ASSERT_EQUAL(static_cast<bencode::BDE::Integer>(7), dict["ki"].i());
-  CPPUNIT_ASSERT(dict.containsKey("ks"));
-  CPPUNIT_ASSERT_EQUAL(std::string("abc"), dict["ks"].s());
-
-  CPPUNIT_ASSERT(dict["kn"].isNone()); // This adds kn key with default value.
-  CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), dict.size());
-  CPPUNIT_ASSERT(dict.containsKey("kn"));
-
-  const bencode::BDE& ref = dict;
-  ref["kn2"]; // This doesn't add kn2 key.
-  CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), ref.size());
-  CPPUNIT_ASSERT(!ref.containsKey("kn2"));
-
-  dict.removeKey("kn");
-  CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), dict.size());
-  CPPUNIT_ASSERT(!dict.containsKey("kn"));
-}
-
-void BencodeTest::testDictIter()
-{
-  bencode::BDE dict = bencode::BDE::dict();
-  dict["alpha2"] = std::string("alpha2");
-  dict["charlie"] = std::string("charlie");
-  dict["bravo"] = std::string("bravo");
-  dict["alpha"] = std::string("alpha");
-
-  bencode::BDE::Dict::iterator i = dict.dictBegin();
-  CPPUNIT_ASSERT_EQUAL(std::string("alpha"), (*i++).first); 
-  CPPUNIT_ASSERT_EQUAL(std::string("alpha2"), (*i++).first);
-  CPPUNIT_ASSERT_EQUAL(std::string("bravo"), (*i++).first);
-  CPPUNIT_ASSERT_EQUAL(std::string("charlie"), (*i++).first);
-  CPPUNIT_ASSERT(dict.dictEnd() == i);
-
-  const bencode::BDE& ref = dict;
-  bencode::BDE::Dict::const_iterator ci = ref.dictBegin();
-  CPPUNIT_ASSERT_EQUAL(std::string("alpha"), (*ci++).first);
-  std::advance(ci, 3);
-  CPPUNIT_ASSERT(ref.dictEnd() == ci);
-}
-
-void BencodeTest::testList()
-{
-  bencode::BDE list = bencode::BDE::list();
-  CPPUNIT_ASSERT(list.empty());
-  list << 7;
-  list << std::string("aria2");
-
-  CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), list.size());
-  CPPUNIT_ASSERT_EQUAL(static_cast<bencode::BDE::Integer>(7), list[0].i());
-  CPPUNIT_ASSERT_EQUAL(std::string("aria2"), list[1].s());
-
-  const bencode::BDE& ref = list;
-  CPPUNIT_ASSERT_EQUAL(static_cast<bencode::BDE::Integer>(7), ref[0].i());
-  CPPUNIT_ASSERT_EQUAL(std::string("aria2"), ref[1].s());
-}
-
-void BencodeTest::testListIter()
-{
-  bencode::BDE list = bencode::BDE::list();
-  list << std::string("alpha2");
-  list << std::string("charlie");
-  list << std::string("bravo");
-  list << std::string("alpha");
-
-  bencode::BDE::List::iterator i = list.listBegin();
-  CPPUNIT_ASSERT_EQUAL(std::string("alpha2"), (*i++).s());
-  CPPUNIT_ASSERT_EQUAL(std::string("charlie"), (*i++).s());
-  CPPUNIT_ASSERT_EQUAL(std::string("bravo"), (*i++).s());
-  CPPUNIT_ASSERT_EQUAL(std::string("alpha"), (*i++).s());
-  CPPUNIT_ASSERT(list.listEnd() == i);
-
-  const bencode::BDE& ref = list;
-  bencode::BDE::List::const_iterator ci = ref.listBegin();
-  CPPUNIT_ASSERT_EQUAL(std::string("alpha2"), (*ci++).s());
-  std::advance(ci, 3);
-  CPPUNIT_ASSERT(ref.listEnd() == ci);
-}
-
 void BencodeTest::testDecode()
 {
   {
     // string, integer and list in dict
-    bencode::BDE dict =
+    BDE dict =
       bencode::decode("d4:name5:aria24:sizei12345678900e5:filesl3:bin3:docee");
     CPPUNIT_ASSERT(dict.isDict());
     CPPUNIT_ASSERT_EQUAL(std::string("aria2"), dict["name"].s());
-    CPPUNIT_ASSERT_EQUAL(static_cast<bencode::BDE::Integer>(12345678900LL),
+    CPPUNIT_ASSERT_EQUAL(static_cast<BDE::Integer>(12345678900LL),
 			 dict["size"].i());
-    bencode::BDE list = dict["files"];
+    BDE list = dict["files"];
     CPPUNIT_ASSERT(list.isList());
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), list.size());
     CPPUNIT_ASSERT_EQUAL(std::string("bin"), list[0].s());
@@ -169,31 +39,31 @@ void BencodeTest::testDecode()
   }
   {
     // dict in list
-    bencode::BDE list = bencode::decode("ld1:ki123eee");
+    BDE list = bencode::decode("ld1:ki123eee");
     CPPUNIT_ASSERT(list.isList());
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), list.size());
-    bencode::BDE dict = list[0];
+    BDE dict = list[0];
     CPPUNIT_ASSERT(dict.isDict());
-    CPPUNIT_ASSERT_EQUAL(static_cast<bencode::BDE::Integer>(123),
+    CPPUNIT_ASSERT_EQUAL(static_cast<BDE::Integer>(123),
 			 dict["k"].i());
   }
   {
     // empty key is allowed
-    bencode::BDE s = bencode::decode("d0:1:ve");
+    BDE s = bencode::decode("d0:1:ve");
   }
   {
     // empty string
-    bencode::BDE s = bencode::decode("0:");
+    BDE s = bencode::decode("0:");
     CPPUNIT_ASSERT_EQUAL(std::string(""), s.s());
   }
   {
     // empty dict
-    bencode::BDE d = bencode::decode("de");
+    BDE d = bencode::decode("de");
     CPPUNIT_ASSERT(d.empty());
   }
   {
     // empty list
-    bencode::BDE l = bencode::decode("le");
+    BDE l = bencode::decode("le");
     CPPUNIT_ASSERT(l.empty());
   }
   {
@@ -267,7 +137,7 @@ void BencodeTest::testDecode()
   }
   {
     // ignore trailing garbage at the end of the input.
-    bencode::BDE s = bencode::decode("5:aria2trail");
+    BDE s = bencode::decode("5:aria2trail");
     CPPUNIT_ASSERT_EQUAL(std::string("aria2"), s.s());
   }
 }
@@ -275,12 +145,12 @@ void BencodeTest::testDecode()
 void BencodeTest::testEncode()
 {
   {
-    bencode::BDE dict = bencode::BDE::dict();
+    BDE dict = BDE::dict();
     dict["name"] = std::string("aria2");
     dict["loc"] = 80000;
-    dict["files"] = bencode::BDE::list();
+    dict["files"] = BDE::list();
     dict["files"] << std::string("aria2c");
-    dict["attrs"] = bencode::BDE::dict();
+    dict["attrs"] = BDE::dict();
     dict["attrs"]["license"] = std::string("GPL");
 
     CPPUNIT_ASSERT_EQUAL(std::string("d"

+ 6 - 6
test/DHTAnnouncePeerMessageTest.cc

@@ -60,13 +60,13 @@ void DHTAnnouncePeerMessageTest::testGetBencodedMessage()
 
   std::string msgbody = msg.getBencodedMessage();
 
-  bencode::BDE dict = bencode::BDE::dict();
+  BDE dict = BDE::dict();
   dict["t"] = transactionID;
-  dict["y"] = bencode::BDE("q");
-  dict["q"] = bencode::BDE("announce_peer");
-  bencode::BDE aDict = bencode::BDE::dict();
-  aDict["id"] = bencode::BDE(localNode->getID(), DHT_ID_LENGTH);
-  aDict["info_hash"] = bencode::BDE(infoHash, DHT_ID_LENGTH);
+  dict["y"] = BDE("q");
+  dict["q"] = BDE("announce_peer");
+  BDE aDict = BDE::dict();
+  aDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
+  aDict["info_hash"] = BDE(infoHash, DHT_ID_LENGTH);
   aDict["port"] = port;
   aDict["token"] = token;
   dict["a"] = aDict;

+ 4 - 4
test/DHTAnnouncePeerReplyMessageTest.cc

@@ -39,11 +39,11 @@ void DHTAnnouncePeerReplyMessageTest::testGetBencodedMessage()
 
   std::string msgbody = msg.getBencodedMessage();
 
-  bencode::BDE dict = bencode::BDE::dict();
+  BDE dict = BDE::dict();
   dict["t"] = transactionID;
-  dict["y"] = bencode::BDE("r");
-  bencode::BDE rDict = bencode::BDE::dict();
-  rDict["id"] = bencode::BDE(localNode->getID(), DHT_ID_LENGTH);
+  dict["y"] = BDE("r");
+  BDE rDict = BDE::dict();
+  rDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
   dict["r"] = rDict;
 
   CPPUNIT_ASSERT_EQUAL(bencode::encode(dict), msgbody);

+ 6 - 6
test/DHTFindNodeMessageTest.cc

@@ -61,13 +61,13 @@ void DHTFindNodeMessageTest::testGetBencodedMessage()
 
   std::string msgbody = msg.getBencodedMessage();
 
-  bencode::BDE dict = bencode::BDE::dict();
+  BDE dict = BDE::dict();
   dict["t"] = transactionID;
-  dict["y"] = bencode::BDE("q");
-  dict["q"] = bencode::BDE("find_node");
-  bencode::BDE aDict = bencode::BDE::dict();
-  aDict["id"] = bencode::BDE(localNode->getID(), DHT_ID_LENGTH);
-  aDict["target"] = bencode::BDE(targetNode->getID(), DHT_ID_LENGTH);
+  dict["y"] = BDE("q");
+  dict["q"] = BDE("find_node");
+  BDE aDict = BDE::dict();
+  aDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
+  aDict["target"] = BDE(targetNode->getID(), DHT_ID_LENGTH);
   dict["a"] = aDict;
 
   CPPUNIT_ASSERT_EQUAL(bencode::encode(dict), msgbody);

+ 4 - 4
test/DHTFindNodeReplyMessageTest.cc

@@ -56,11 +56,11 @@ void DHTFindNodeReplyMessageTest::testGetBencodedMessage()
 
   std::string msgbody = msg.getBencodedMessage();
 
-  bencode::BDE dict = bencode::BDE::dict();
+  BDE dict = BDE::dict();
   dict["t"] = transactionID;
-  dict["y"] = bencode::BDE("r");
-  bencode::BDE rDict = bencode::BDE::dict();
-  rDict["id"] = bencode::BDE(localNode->getID(), DHT_ID_LENGTH);
+  dict["y"] = BDE("r");
+  BDE rDict = BDE::dict();
+  rDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
   rDict["nodes"] = compactNodeInfo;
   dict["r"] = rDict;
 

+ 6 - 6
test/DHTGetPeersMessageTest.cc

@@ -80,13 +80,13 @@ void DHTGetPeersMessageTest::testGetBencodedMessage()
 
   std::string msgbody = msg.getBencodedMessage();
 
-  bencode::BDE dict = bencode::BDE::dict();
+  BDE dict = BDE::dict();
   dict["t"] = transactionID;
-  dict["y"] = bencode::BDE("q");
-  dict["q"] = bencode::BDE("get_peers");
-  bencode::BDE aDict = bencode::BDE::dict();
-  aDict["id"] = bencode::BDE(localNode->getID(), DHT_ID_LENGTH);
-  aDict["info_hash"] = bencode::BDE(infoHash, DHT_ID_LENGTH);
+  dict["y"] = BDE("q");
+  dict["q"] = BDE("get_peers");
+  BDE aDict = BDE::dict();
+  aDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
+  aDict["info_hash"] = BDE(infoHash, DHT_ID_LENGTH);
   dict["a"] = aDict;
 
   CPPUNIT_ASSERT_EQUAL(Util::urlencode(bencode::encode(dict)),

+ 6 - 6
test/DHTGetPeersReplyMessageTest.cc

@@ -42,11 +42,11 @@ void DHTGetPeersReplyMessageTest::testGetBencodedMessage()
 
   DHTGetPeersReplyMessage msg(localNode, remoteNode, token, transactionID);
 
-  bencode::BDE dict = bencode::BDE::dict();
+  BDE dict = BDE::dict();
   dict["t"] = transactionID;
-  dict["y"] = bencode::BDE("r");
-  bencode::BDE rDict = bencode::BDE::dict();
-  rDict["id"] = bencode::BDE(localNode->getID(), DHT_ID_LENGTH);
+  dict["y"] = BDE("r");
+  BDE rDict = BDE::dict();
+  rDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
   rDict["token"] = token;
   dict["r"] = rDict;
   {
@@ -77,12 +77,12 @@ void DHTGetPeersReplyMessageTest::testGetBencodedMessage()
   rDict.removeKey("nodes");
   {
     std::deque<SharedHandle<Peer> > peers;
-    bencode::BDE valuesList = bencode::BDE::list();
+    BDE valuesList = BDE::list();
     for(size_t i = 0; i < 4; ++i) {
       SharedHandle<Peer> peer(new Peer("192.168.0."+Util::uitos(i+1), 6881+i));
       unsigned char buffer[6];
       CPPUNIT_ASSERT(PeerMessageUtil::createcompact(buffer, peer->ipaddr, peer->port));
-      valuesList << bencode::BDE(buffer, sizeof(buffer));
+      valuesList << BDE(buffer, sizeof(buffer));
       peers.push_back(peer);
     }
     rDict["values"] = valuesList;

+ 61 - 61
test/DHTMessageFactoryImplTest.cc

@@ -79,12 +79,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION(DHTMessageFactoryImplTest);
 
 void DHTMessageFactoryImplTest::testCreatePingMessage()
 {
-  bencode::BDE dict = bencode::BDE::dict();
-  dict["t"] = bencode::BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
-  dict["y"] = bencode::BDE("q");
-  dict["q"] = bencode::BDE("ping");
-  bencode::BDE aDict = bencode::BDE::dict();
-  aDict["id"] = bencode::BDE(remoteNodeID, DHT_ID_LENGTH);
+  BDE dict = BDE::dict();
+  dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
+  dict["y"] = BDE("q");
+  dict["q"] = BDE("ping");
+  BDE aDict = BDE::dict();
+  aDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
   dict["a"] = aDict;
   
   SharedHandle<DHTPingMessage> m
@@ -102,11 +102,11 @@ void DHTMessageFactoryImplTest::testCreatePingMessage()
 
 void DHTMessageFactoryImplTest::testCreatePingReplyMessage()
 {
-  bencode::BDE dict = bencode::BDE::dict();
-  dict["t"] = bencode::BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
-  dict["y"] = bencode::BDE("r");
-  bencode::BDE rDict = bencode::BDE::dict();
-  rDict["id"] = bencode::BDE(remoteNodeID, DHT_ID_LENGTH);
+  BDE dict = BDE::dict();
+  dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
+  dict["y"] = BDE("r");
+  BDE rDict = BDE::dict();
+  rDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
   dict["r"] = rDict;
 
   SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
@@ -127,15 +127,15 @@ void DHTMessageFactoryImplTest::testCreatePingReplyMessage()
 
 void DHTMessageFactoryImplTest::testCreateFindNodeMessage()
 {
-  bencode::BDE dict = bencode::BDE::dict();
-  dict["t"] = bencode::BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
-  dict["y"] = bencode::BDE("q");
-  dict["q"] = bencode::BDE("find_node");
-  bencode::BDE aDict = bencode::BDE::dict();
-  aDict["id"] = bencode::BDE(remoteNodeID, DHT_ID_LENGTH);
+  BDE dict = BDE::dict();
+  dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
+  dict["y"] = BDE("q");
+  dict["q"] = BDE("find_node");
+  BDE aDict = BDE::dict();
+  aDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
   unsigned char targetNodeID[DHT_ID_LENGTH];
   memset(targetNodeID, 0x11, DHT_ID_LENGTH);
-  aDict["target"] = bencode::BDE(targetNodeID, DHT_ID_LENGTH);
+  aDict["target"] = BDE(targetNodeID, DHT_ID_LENGTH);
   dict["a"] = aDict;
   
   SharedHandle<DHTFindNodeMessage> m
@@ -156,11 +156,11 @@ void DHTMessageFactoryImplTest::testCreateFindNodeMessage()
 void DHTMessageFactoryImplTest::testCreateFindNodeReplyMessage()
 {
   try {
-    bencode::BDE dict = bencode::BDE::dict();
-    dict["t"] = bencode::BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
-    dict["y"] = bencode::BDE("r");
-    bencode::BDE rDict = bencode::BDE::dict();
-    rDict["id"] = bencode::BDE(remoteNodeID, DHT_ID_LENGTH);
+    BDE dict = BDE::dict();
+    dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
+    dict["y"] = BDE("r");
+    BDE rDict = BDE::dict();
+    rDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
     std::string compactNodeInfo;
     SharedHandle<DHTNode> nodes[8];
     for(size_t i = 0; i < DHTBucket::K; ++i) {
@@ -202,15 +202,15 @@ void DHTMessageFactoryImplTest::testCreateFindNodeReplyMessage()
 
 void DHTMessageFactoryImplTest::testCreateGetPeersMessage()
 {
-  bencode::BDE dict = bencode::BDE::dict();
-  dict["t"] = bencode::BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
-  dict["y"] = bencode::BDE("q");
-  dict["q"] = bencode::BDE("get_peers");
-  bencode::BDE aDict = bencode::BDE::dict();
-  aDict["id"] = bencode::BDE(remoteNodeID, DHT_ID_LENGTH);
+  BDE dict = BDE::dict();
+  dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
+  dict["y"] = BDE("q");
+  dict["q"] = BDE("get_peers");
+  BDE aDict = BDE::dict();
+  aDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
   unsigned char infoHash[DHT_ID_LENGTH];
   memset(infoHash, 0x11, DHT_ID_LENGTH);
-  aDict["info_hash"] = bencode::BDE(infoHash, DHT_ID_LENGTH);
+  aDict["info_hash"] = BDE(infoHash, DHT_ID_LENGTH);
   dict["a"] = aDict;
   
   SharedHandle<DHTGetPeersMessage> m
@@ -231,11 +231,11 @@ void DHTMessageFactoryImplTest::testCreateGetPeersMessage()
 void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_nodes()
 {
   try {
-    bencode::BDE dict = bencode::BDE::dict();
-    dict["t"] = bencode::BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
-    dict["y"] = bencode::BDE("r");
-    bencode::BDE rDict = bencode::BDE::dict();
-    rDict["id"] = bencode::BDE(remoteNodeID, DHT_ID_LENGTH);
+    BDE dict = BDE::dict();
+    dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
+    dict["y"] = BDE("r");
+    BDE rDict = BDE::dict();
+    rDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
     std::string compactNodeInfo;
     SharedHandle<DHTNode> nodes[8];
     for(size_t i = 0; i < DHTBucket::K; ++i) {
@@ -251,7 +251,7 @@ void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_nodes()
 	std::string(&buf[0], &buf[sizeof(buf)]);
     }
     rDict["nodes"] = compactNodeInfo;
-    rDict["token"] = bencode::BDE("token");
+    rDict["token"] = BDE("token");
     dict["r"] = rDict;
 
     SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
@@ -280,24 +280,24 @@ void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_nodes()
 void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_values()
 {
   try {
-    bencode::BDE dict = bencode::BDE::dict();
-    dict["t"] = bencode::BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
-    dict["y"] = bencode::BDE("r");
-    bencode::BDE rDict = bencode::BDE::dict();
-    rDict["id"] = bencode::BDE(remoteNodeID, DHT_ID_LENGTH);
+    BDE dict = BDE::dict();
+    dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
+    dict["y"] = BDE("r");
+    BDE rDict = BDE::dict();
+    rDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
 
     std::deque<SharedHandle<Peer> > peers;
-    bencode::BDE valuesList = bencode::BDE::list();
+    BDE valuesList = BDE::list();
     for(size_t i = 0; i < 4; ++i) {
       SharedHandle<Peer> peer(new Peer("192.168.0."+Util::uitos(i+1), 6881+i));
       unsigned char buffer[6];
       CPPUNIT_ASSERT(PeerMessageUtil::createcompact(buffer, peer->ipaddr,
 						    peer->port));
-      valuesList << bencode::BDE(buffer, sizeof(buffer));
+      valuesList << BDE(buffer, sizeof(buffer));
       peers.push_back(peer);
     }
     rDict["values"] = valuesList;
-    rDict["token"] = bencode::BDE("token");
+    rDict["token"] = BDE("token");
     dict["r"] = rDict;
 
     SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
@@ -326,15 +326,15 @@ void DHTMessageFactoryImplTest::testCreateGetPeersReplyMessage_values()
 void DHTMessageFactoryImplTest::testCreateAnnouncePeerMessage()
 {
   try {
-    bencode::BDE dict = bencode::BDE::dict();
-    dict["t"] = bencode::BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
-    dict["y"] = bencode::BDE("q");
-    dict["q"] = bencode::BDE("announce_peer");
-    bencode::BDE aDict = bencode::BDE::dict();
-    aDict["id"] = bencode::BDE(remoteNodeID, DHT_ID_LENGTH);
+    BDE dict = BDE::dict();
+    dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
+    dict["y"] = BDE("q");
+    dict["q"] = BDE("announce_peer");
+    BDE aDict = BDE::dict();
+    aDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
     unsigned char infoHash[DHT_ID_LENGTH];
     memset(infoHash, 0x11, DHT_ID_LENGTH);
-    aDict["info_hash"] = bencode::BDE(infoHash, DHT_ID_LENGTH);
+    aDict["info_hash"] = BDE(infoHash, DHT_ID_LENGTH);
     std::string token = "ffff";
     uint16_t port = 6881;
     aDict["port"] = port;
@@ -363,11 +363,11 @@ void DHTMessageFactoryImplTest::testCreateAnnouncePeerMessage()
 
 void DHTMessageFactoryImplTest::testCreateAnnouncePeerReplyMessage()
 {
-  bencode::BDE dict = bencode::BDE::dict();
-  dict["t"] = bencode::BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
-  dict["y"] = bencode::BDE("r");
-  bencode::BDE rDict = bencode::BDE::dict();
-  rDict["id"] = bencode::BDE(remoteNodeID, DHT_ID_LENGTH);
+  BDE dict = BDE::dict();
+  dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
+  dict["y"] = BDE("r");
+  BDE rDict = BDE::dict();
+  rDict["id"] = BDE(remoteNodeID, DHT_ID_LENGTH);
   dict["r"] = rDict;
 
   SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));
@@ -388,12 +388,12 @@ void DHTMessageFactoryImplTest::testCreateAnnouncePeerReplyMessage()
 
 void DHTMessageFactoryImplTest::testReceivedErrorMessage()
 {
-  bencode::BDE dict = bencode::BDE::dict();
-  dict["t"] = bencode::BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
-  dict["y"] = bencode::BDE("e");
-  bencode::BDE list = bencode::BDE::list();
+  BDE dict = BDE::dict();
+  dict["t"] = BDE(transactionID, DHT_TRANSACTION_ID_LENGTH);
+  dict["y"] = BDE("e");
+  BDE list = BDE::list();
   list << 404;
-  list << bencode::BDE("Not found");
+  list << BDE("Not found");
   dict["e"] = list;
 
   SharedHandle<DHTNode> remoteNode(new DHTNode(remoteNodeID));

+ 3 - 3
test/DHTMessageTrackerTest.cc

@@ -76,7 +76,7 @@ void DHTMessageTrackerTest::testMessageArrived()
   tracker.addMessage(m3);
 
   {
-    bencode::BDE resDict = bencode::BDE::dict();
+    BDE resDict = BDE::dict();
     resDict["t"] = m2->getTransactionID();
     
     std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> > p =
@@ -90,7 +90,7 @@ void DHTMessageTrackerTest::testMessageArrived()
     CPPUNIT_ASSERT_EQUAL((size_t)2, tracker.countEntry());
   }
   {
-    bencode::BDE resDict = bencode::BDE::dict();
+    BDE resDict = BDE::dict();
     resDict["t"] = m3->getTransactionID();
 
     std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> > p =
@@ -103,7 +103,7 @@ void DHTMessageTrackerTest::testMessageArrived()
     CPPUNIT_ASSERT_EQUAL((size_t)1, tracker.countEntry());
   }
   {
-    bencode::BDE resDict = bencode::BDE::dict();
+    BDE resDict = BDE::dict();
     resDict["t"] = m1->getTransactionID();
 
     std::pair<SharedHandle<DHTMessage>, SharedHandle<DHTMessageCallback> > p =

+ 5 - 5
test/DHTPingMessageTest.cc

@@ -57,12 +57,12 @@ void DHTPingMessageTest::testGetBencodedMessage()
 
   std::string msgbody = msg.getBencodedMessage();
 
-  bencode::BDE dict = bencode::BDE::dict();
+  BDE dict = BDE::dict();
   dict["t"] = transactionID;
-  dict["y"] = bencode::BDE("q");
-  dict["q"] = bencode::BDE("ping");
-  bencode::BDE aDict = bencode::BDE::dict();
-  aDict["id"] = bencode::BDE(localNode->getID(), DHT_ID_LENGTH);
+  dict["y"] = BDE("q");
+  dict["q"] = BDE("ping");
+  BDE aDict = BDE::dict();
+  aDict["id"] = BDE(localNode->getID(), DHT_ID_LENGTH);
   dict["a"] = aDict;
 
   CPPUNIT_ASSERT_EQUAL(bencode::encode(dict), msgbody);

+ 4 - 4
test/DHTPingReplyMessageTest.cc

@@ -42,11 +42,11 @@ void DHTPingReplyMessageTest::testGetBencodedMessage()
 
   std::string msgbody = msg.getBencodedMessage();
 
-  bencode::BDE dict = bencode::BDE::dict();
+  BDE dict = BDE::dict();
   dict["t"] = transactionID;
-  dict["y"] = bencode::BDE("r");
-  bencode::BDE rDict = bencode::BDE::dict();
-  rDict["id"] = bencode::BDE(id, DHT_ID_LENGTH);
+  dict["y"] = BDE("r");
+  BDE rDict = BDE::dict();
+  rDict["id"] = BDE(id, DHT_ID_LENGTH);
   dict["r"] = rDict;
 
   CPPUNIT_ASSERT_EQUAL(bencode::encode(dict), msgbody);

+ 2 - 1
test/Makefile.am

@@ -68,7 +68,8 @@ aria2c_SOURCES = AllTest.cc\
 	RarestPieceSelectorTest.cc\
 	LongestSequencePieceSelectorTest.cc\
 	a2algoTest.cc\
-	bitfieldTest.cc
+	bitfieldTest.cc\
+	BDETest.cc
 
 if HAVE_POSIX_FALLOCATE
 aria2c_SOURCES += FallocFileAllocationIteratorTest.cc

+ 6 - 5
test/Makefile.in

@@ -194,7 +194,7 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
 	SimpleDNSCacheTest.cc DownloadHelperTest.cc BencodeTest.cc \
 	SequentialPickerTest.cc RarestPieceSelectorTest.cc \
 	LongestSequencePieceSelectorTest.cc a2algoTest.cc \
-	bitfieldTest.cc FallocFileAllocationIteratorTest.cc \
+	bitfieldTest.cc BDETest.cc FallocFileAllocationIteratorTest.cc \
 	GZipDecoderTest.cc Sqlite3MozCookieParserTest.cc \
 	MessageDigestHelperTest.cc \
 	IteratableChunkChecksumValidatorTest.cc \
@@ -365,9 +365,9 @@ am_aria2c_OBJECTS = AllTest.$(OBJEXT) TestUtil.$(OBJEXT) \
 	SequentialPickerTest.$(OBJEXT) \
 	RarestPieceSelectorTest.$(OBJEXT) \
 	LongestSequencePieceSelectorTest.$(OBJEXT) \
-	a2algoTest.$(OBJEXT) bitfieldTest.$(OBJEXT) $(am__objects_1) \
-	$(am__objects_2) $(am__objects_3) $(am__objects_4) \
-	$(am__objects_5) $(am__objects_6)
+	a2algoTest.$(OBJEXT) bitfieldTest.$(OBJEXT) BDETest.$(OBJEXT) \
+	$(am__objects_1) $(am__objects_2) $(am__objects_3) \
+	$(am__objects_4) $(am__objects_5) $(am__objects_6)
 aria2c_OBJECTS = $(am_aria2c_OBJECTS)
 am__DEPENDENCIES_1 =
 aria2c_DEPENDENCIES = ../src/libaria2c.a ../src/download_helper.o \
@@ -592,7 +592,7 @@ aria2c_SOURCES = AllTest.cc TestUtil.cc TestUtil.h SocketCoreTest.cc \
 	SimpleDNSCacheTest.cc DownloadHelperTest.cc BencodeTest.cc \
 	SequentialPickerTest.cc RarestPieceSelectorTest.cc \
 	LongestSequencePieceSelectorTest.cc a2algoTest.cc \
-	bitfieldTest.cc $(am__append_1) $(am__append_2) \
+	bitfieldTest.cc BDETest.cc $(am__append_1) $(am__append_2) \
 	$(am__append_3) $(am__append_4) $(am__append_5) \
 	$(am__append_6)
 
@@ -688,6 +688,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AlphaNumberDecoratorTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AnnounceListTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/AuthConfigFactoryTest.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BDETest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BNodeTest.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Base64Test.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BencodeTest.Po@am__quote@

+ 2 - 2
test/MockDHTMessageFactory.h

@@ -17,7 +17,7 @@ public:
   virtual ~MockDHTMessageFactory() {}
 
   virtual SharedHandle<DHTMessage>
-  createQueryMessage(const bencode::BDE& dict,
+  createQueryMessage(const BDE& dict,
 		     const std::string& ipaddr, uint16_t port)
   {
     return SharedHandle<DHTMessage>();
@@ -25,7 +25,7 @@ public:
 
   virtual SharedHandle<DHTMessage>
   createResponseMessage(const std::string& messageType,
-			const bencode::BDE& dict,
+			const BDE& dict,
 			const std::string& ipaddr, uint16_t port)
   {
     SharedHandle<DHTNode> remoteNode(new DHTNode());

+ 2 - 2
test/PeerListProcessorTest.cc

@@ -35,7 +35,7 @@ void PeerListProcessorTest::testExtractPeerFromList() {
   PeerListProcessor proc;
   std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti2006eeee";
 
-  const bencode::BDE dict = bencode::decode(peersString);
+  const BDE dict = bencode::decode(peersString);
   
   std::deque<SharedHandle<Peer> > peers;
   proc.extractPeerFromList(dict["peers"], std::back_inserter(peers));
@@ -49,7 +49,7 @@ void PeerListProcessorTest::testExtract2PeersFromList() {
   PeerListProcessor proc;
   std::string peersString = "d5:peersld2:ip11:192.168.0.17:peer id20:aria2-000000000000004:porti65535eed2:ip11:192.168.0.27:peer id20:aria2-000000000000004:porti2007eeee";
 
-  const bencode::BDE dict = bencode::decode(peersString);
+  const BDE dict = bencode::decode(peersString);
 
   std::deque<SharedHandle<Peer> > peers;
   proc.extractPeerFromList(dict["peers"], std::back_inserter(peers));