Gentoo Archives: gentoo-commits

From: "Peter Alfredsen (loki_val)" <loki_val@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in net-libs/libtorrent/files: libtorrent-0.12.2-fix_dht-get_peers.patch
Date: Tue, 26 Aug 2008 21:17:20
Message-Id: E1KY5ue-0000hu-JL@stork.gentoo.org
1 loki_val 08/08/26 21:17:16
2
3 Added: libtorrent-0.12.2-fix_dht-get_peers.patch
4 Log:
5 Fixes an interoperability issue in the get_peers handling, now it behaves according to the clarified BEP-0005. Also fixes a minor issue of not being able to generate error packets. Patch by Josef Drexler.
6 (Portage version: 2.2_rc8/cvs/Linux 2.6.25.8 i686)
7
8 Revision Changes Path
9 1.1 net-libs/libtorrent/files/libtorrent-0.12.2-fix_dht-get_peers.patch
10
11 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/net-libs/libtorrent/files/libtorrent-0.12.2-fix_dht-get_peers.patch?rev=1.1&view=markup
12 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/net-libs/libtorrent/files/libtorrent-0.12.2-fix_dht-get_peers.patch?rev=1.1&content-type=text/plain
13
14 Index: libtorrent-0.12.2-fix_dht-get_peers.patch
15 ===================================================================
16 # Fixes an interoperability issue in the get_peers handling, now it
17 # behaves according to the clarified BEP-0005. Also fixes a minor
18 # issue of not being able to generate error packets.
19 Index: libtorrent/src/dht/dht_tracker.h
20 ===================================================================
21 --- libtorrent/src/dht/dht_tracker.h (revision 1063)
22 +++ libtorrent/src/dht/dht_tracker.h (working copy)
23 @@ -65,7 +65,7 @@
24 size_t size() const { return m_peers.size(); }
25
26 void add_peer(uint32_t addr, uint16_t port);
27 - std::string get_peers(unsigned int maxPeers = max_peers);
28 + Object get_peers(unsigned int maxPeers = max_peers);
29
30 // Remove old announces from the tracker that have not reannounced for
31 // more than the given number of seconds.
32 Index: libtorrent/src/dht/dht_transaction.cc
33 ===================================================================
34 --- libtorrent/src/dht/dht_transaction.cc (revision 1063)
35 +++ libtorrent/src/dht/dht_transaction.cc (working copy)
36 @@ -252,7 +252,7 @@
37 }
38
39 void
40 -DhtAnnounce::receive_peers(const std::string& peers) {
41 +DhtAnnounce::receive_peers(const Object& peers) {
42 m_tracker->receive_peers(peers);
43 }
44
45 Index: libtorrent/src/dht/dht_server.cc
46 ===================================================================
47 --- libtorrent/src/dht/dht_server.cc (revision 1063)
48 +++ libtorrent/src/dht/dht_server.cc (working copy)
49 @@ -302,8 +302,7 @@
50 reply.insert_key("nodes", std::string(compact, end));
51
52 } else {
53 - Object& values = reply.insert_key("values", Object::create_list());
54 - values.insert_back(tracker->get_peers());
55 + reply.insert_key("values", Object::create_list()).as_list().swap(tracker->get_peers().as_list());
56 }
57 }
58
59 @@ -417,7 +416,7 @@
60 transaction->complete(true);
61
62 if (response.has_key_list("values"))
63 - announce->receive_peers((*response.get_key_list("values").begin()).as_string());
64 + announce->receive_peers(response.get_key("values"));
65
66 if (response.has_key_string("token"))
67 add_transaction(new DhtTransactionAnnouncePeer(transaction->id(), transaction->address(), announce->target(), response.get_key_string("token")), packet_prio_low);
68 @@ -641,6 +640,7 @@
69 sstream.imbue(std::locale::classic());
70
71 while (true) {
72 + Object request;
73 rak::socket_address sa;
74 int type = '?';
75 const Object* transactionId = NULL;
76 @@ -656,7 +656,6 @@
77 total += read;
78 sstream.str(std::string(buffer, read));
79
80 - Object request;
81 sstream >> request;
82
83 // If it's not a valid bencode dictionary at all, it's probably not a DHT
84 Index: libtorrent/src/dht/dht_transaction.h
85 ===================================================================
86 --- libtorrent/src/dht/dht_transaction.h (revision 1063)
87 +++ libtorrent/src/dht/dht_transaction.h (working copy)
88 @@ -178,7 +178,7 @@
89 // counts announces instead.
90 const_accessor start_announce();
91
92 - void receive_peers(const std::string& peers);
93 + void receive_peers(const Object& peer_list);
94 void update_status();
95
96 private:
97 Index: libtorrent/src/dht/dht_tracker.cc
98 ===================================================================
99 --- libtorrent/src/dht/dht_tracker.cc (revision 1063)
100 +++ libtorrent/src/dht/dht_tracker.cc (working copy)
101 @@ -79,7 +79,7 @@
102
103 // Return compact info (6 bytes) for up to 30 peers, returning different
104 // peers for each call if there are more.
105 -std::string
106 +Object
107 DhtTracker::get_peers(unsigned int maxPeers) {
108 PeerList::iterator first = m_peers.begin();
109 PeerList::iterator last = m_peers.end();
110 @@ -94,7 +94,11 @@
111 last = first + maxPeers;
112 }
113
114 - return std::string(first->c_str(), last->c_str());
115 + Object peers = Object::create_list();
116 + for (; first != last; ++first)
117 + peers.insert_back(std::string(first->c_str(), sizeof(*first)));
118 +
119 + return peers;
120 }
121
122 // Remove old announces.
123 Index: libtorrent/src/tracker/tracker_dht.h
124 ===================================================================
125 --- libtorrent/src/tracker/tracker_dht.h (revision 1063)
126 +++ libtorrent/src/tracker/tracker_dht.h (working copy)
127 @@ -71,7 +71,7 @@
128
129 bool has_peers() const { return !m_peers.empty(); }
130
131 - void receive_peers(const std::string& peers);
132 + void receive_peers(const Object& peer_list);
133 void receive_success();
134 void receive_failed(const char* msg);
135 void receive_progress(int replied, int contacted);
136 Index: libtorrent/src/tracker/tracker_dht.cc
137 ===================================================================
138 --- libtorrent/src/tracker/tracker_dht.cc (revision 1063)
139 +++ libtorrent/src/tracker/tracker_dht.cc (working copy)
140 @@ -114,11 +114,13 @@
141 }
142
143 void
144 -TrackerDht::receive_peers(const std::string& peers) {
145 +TrackerDht::receive_peers(const Object& peer_list) {
146 if (!is_busy())
147 throw internal_error("TrackerDht::receive_peers called while not busy.");
148
149 - m_peers.parse_address_compact(peers);
150 + Object::list_type peers = peer_list.as_list();
151 + for (Object::list_type::const_iterator itr = peers.begin(); itr != peers.end(); ++itr)
152 + m_peers.parse_address_compact(itr->as_string());
153 }
154
155 void