incompatible dht change 3: get_peers, find_node, info_hash => getPeers, findNode, infoHash

This commit is contained in:
Miguel Freitas 2013-07-29 15:27:34 -03:00
parent 7275eb698c
commit a1b44a6bb4
6 changed files with 23 additions and 23 deletions

View File

@ -56,13 +56,13 @@ def random_key():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
node_id = '1' * 20; node_id = '1' * 20;
query = 'get_peers' query = 'getPeers'
print 'test random info-hashes' print 'test random info-hashes'
for i in xrange(1, 30000): for i in xrange(1, 30000):
send_dht_message({'x': {'id': node_id, 'info_hash': random_key()}, 'q': query, 'z': 'q', 't': '%d' % i}) send_dht_message({'x': {'id': node_id, 'infoHash': random_key()}, 'q': query, 'z': 'q', 't': '%d' % i})
print 'test random peer-ids' print 'test random peer-ids'
for i in xrange(1, 30000): for i in xrange(1, 30000):
send_dht_message({'x': {'id': random_key(), 'info_hash': random_key()}, 'q': query, 'z': 'q', 't': '%d' % i}) send_dht_message({'x': {'id': random_key(), 'infoHash': random_key()}, 'q': query, 'z': 'q', 't': '%d' % i})

View File

@ -74,7 +74,7 @@ public:
, nodes_callback const& ncallback , nodes_callback const& ncallback
, bool noseeds); , bool noseeds);
virtual char const* name() const { return "get_peers"; } virtual char const* name() const { return "getPeers"; }
node_id const target() const { return m_target; } node_id const target() const { return m_target; }

View File

@ -206,9 +206,9 @@ bool find_data::invoke(observer_ptr o)
entry e; entry e;
e["z"] = "q"; e["z"] = "q";
e["q"] = "get_peers"; e["q"] = "getPeers";
entry& a = e["x"]; entry& a = e["x"];
a["info_hash"] = m_target.to_string(); a["infoHash"] = m_target.to_string();
if (m_noseeds) a["noseed"] = 1; if (m_noseeds) a["noseed"] = 1;
return m_node.m_rpc.invoke(e, o->target_ep(), o); return m_node.m_rpc.invoke(e, o->target_ep(), o);
} }

View File

@ -282,9 +282,9 @@ namespace
#endif #endif
entry e; entry e;
e["z"] = "q"; e["z"] = "q";
e["q"] = "announce_peer"; e["q"] = "announcePeer";
entry& a = e["x"]; entry& a = e["x"];
a["info_hash"] = ih.to_string(); a["infoHash"] = ih.to_string();
a["port"] = listen_port; a["port"] = listen_port;
a["token"] = i->second; a["token"] = i->second;
a["seed"] = int(seed); a["seed"] = int(seed);
@ -641,10 +641,10 @@ void node_impl::incoming_request(msg const& m, entry& e)
// we already have 't' and 'id' in the response // we already have 't' and 'id' in the response
// no more left to add // no more left to add
} }
else if (strcmp(query, "get_peers") == 0) else if (strcmp(query, "getPeers") == 0)
{ {
key_desc_t msg_desc[] = { key_desc_t msg_desc[] = {
{"info_hash", lazy_entry::string_t, 20, 0}, {"infoHash", lazy_entry::string_t, 20, 0},
{"ifhpfxl", lazy_entry::int_t, 0, key_desc_t::optional}, {"ifhpfxl", lazy_entry::int_t, 0, key_desc_t::optional},
{"noseed", lazy_entry::int_t, 0, key_desc_t::optional}, {"noseed", lazy_entry::int_t, 0, key_desc_t::optional},
{"scrape", lazy_entry::int_t, 0, key_desc_t::optional}, {"scrape", lazy_entry::int_t, 0, key_desc_t::optional},
@ -681,7 +681,7 @@ void node_impl::incoming_request(msg const& m, entry& e)
} }
#endif #endif
} }
else if (strcmp(query, "find_node") == 0) else if (strcmp(query, "findNode") == 0)
{ {
key_desc_t msg_desc[] = { key_desc_t msg_desc[] = {
{"target", lazy_entry::string_t, 20, 0}, {"target", lazy_entry::string_t, 20, 0},
@ -701,10 +701,10 @@ void node_impl::incoming_request(msg const& m, entry& e)
m_table.find_node(target, n, 0); m_table.find_node(target, n, 0);
write_nodes_entry(reply, n); write_nodes_entry(reply, n);
} }
else if (strcmp(query, "announce_peer") == 0) else if (strcmp(query, "announcePeer") == 0)
{ {
key_desc_t msg_desc[] = { key_desc_t msg_desc[] = {
{"info_hash", lazy_entry::string_t, 20, 0}, {"infoHash", lazy_entry::string_t, 20, 0},
{"port", lazy_entry::int_t, 0, 0}, {"port", lazy_entry::int_t, 0, 0},
{"token", lazy_entry::string_t, 0, 0}, {"token", lazy_entry::string_t, 0, 0},
{"n", lazy_entry::string_t, 0, key_desc_t::optional}, {"n", lazy_entry::string_t, 0, key_desc_t::optional},
@ -1029,12 +1029,12 @@ void node_impl::incoming_request(msg const& m, entry& e)
else else
{ {
// if we don't recognize the message but there's a // if we don't recognize the message but there's a
// 'target' or 'info_hash' in the arguments, treat it // 'target' or 'infoHash' in the arguments, treat it
// as find_node to be future compatible // as find_node to be future compatible
lazy_entry const* target_ent = arg_ent->dict_find_string("target"); lazy_entry const* target_ent = arg_ent->dict_find_string("target");
if (target_ent == 0 || target_ent->string_length() != 20) if (target_ent == 0 || target_ent->string_length() != 20)
{ {
target_ent = arg_ent->dict_find_string("info_hash"); target_ent = arg_ent->dict_find_string("infoHash");
if (target_ent == 0 || target_ent->string_length() != 20) if (target_ent == 0 || target_ent->string_length() != 20)
{ {
incoming_error(e, "unknown message"); incoming_error(e, "unknown message");

View File

@ -72,7 +72,7 @@ bool refresh::invoke(observer_ptr o)
{ {
entry e; entry e;
e["z"] = "q"; e["z"] = "q";
e["q"] = "find_node"; e["q"] = "findNode";
entry& a = e["x"]; entry& a = e["x"];
a["target"] = target().to_string(); a["target"] = target().to_string();
return m_node.m_rpc.invoke(e, o->target_ep(), o); return m_node.m_rpc.invoke(e, o->target_ep(), o);

View File

@ -109,7 +109,7 @@ void send_dht_msg(node_impl& node, char const* msg, udp::endpoint const& ep
e["z"] = "q"; e["z"] = "q";
entry::dictionary_type& a = e["x"].dict(); entry::dictionary_type& a = e["x"].dict();
a["id"] = generate_next().to_string(); a["id"] = generate_next().to_string();
if (info_hash) a["info_hash"] = std::string(info_hash, 20); if (info_hash) a["infoHash"] = std::string(info_hash, 20);
if (name) a["n"] = name; if (name) a["n"] = name;
if (!token.empty()) a["token"] = token; if (!token.empty()) a["token"] = token;
if (port) a["port"] = port; if (port) a["port"] = port;
@ -334,7 +334,7 @@ int test_main()
// ====== invalid message ====== // ====== invalid message ======
send_dht_msg(node, "find_node", source, &response, "10"); send_dht_msg(node, "findNode", source, &response, "10");
dht::key_desc_t err_desc[] = { dht::key_desc_t err_desc[] = {
{"z", lazy_entry::string_t, 1, 0}, {"z", lazy_entry::string_t, 1, 0},
@ -366,7 +366,7 @@ int test_main()
// ====== get_peers ====== // ====== get_peers ======
send_dht_msg(node, "get_peers", source, &response, "10", "01010101010101010101"); send_dht_msg(node, "getPeers", source, &response, "10", "01010101010101010101");
dht::key_desc_t peer1_desc[] = { dht::key_desc_t peer1_desc[] = {
{"z", lazy_entry::string_t, 1, 0}, {"z", lazy_entry::string_t, 1, 0},
@ -393,7 +393,7 @@ int test_main()
// ====== announce ====== // ====== announce ======
send_dht_msg(node, "announce_peer", source, &response, "10", "01010101010101010101", "test", token, 8080); send_dht_msg(node, "announcePeer", source, &response, "10", "01010101010101010101", "test", token, 8080);
dht::key_desc_t ann_desc[] = { dht::key_desc_t ann_desc[] = {
{"z", lazy_entry::string_t, 1, 0}, {"z", lazy_entry::string_t, 1, 0},
@ -418,7 +418,7 @@ int test_main()
for (int i = 0; i < 100; ++i) for (int i = 0; i < 100; ++i)
{ {
source = udp::endpoint(rand_v4(), 6000); source = udp::endpoint(rand_v4(), 6000);
send_dht_msg(node, "get_peers", source, &response, "10", "01010101010101010101"); send_dht_msg(node, "getPeers", source, &response, "10", "01010101010101010101");
ret = dht::verify_message(&response, peer1_desc, parsed, 4, error_string, sizeof(error_string)); ret = dht::verify_message(&response, peer1_desc, parsed, 4, error_string, sizeof(error_string));
if (ret) if (ret)
@ -433,14 +433,14 @@ int test_main()
fprintf(stderr, " invalid get_peers response: %s\n", error_string); fprintf(stderr, " invalid get_peers response: %s\n", error_string);
} }
response.clear(); response.clear();
send_dht_msg(node, "announce_peer", source, &response, "10", "01010101010101010101" send_dht_msg(node, "announcePeer", source, &response, "10", "01010101010101010101"
, "test", token, 8080, 0, 0, false, i >= 50); , "test", token, 8080, 0, 0, false, i >= 50);
response.clear(); response.clear();
} }
// ====== get_peers ====== // ====== get_peers ======
send_dht_msg(node, "get_peers", source, &response, "10", "01010101010101010101" send_dht_msg(node, "getPeers", source, &response, "10", "01010101010101010101"
, 0, no, 0, 0, 0, true); , 0, no, 0, 0, 0, true);
dht::key_desc_t peer2_desc[] = { dht::key_desc_t peer2_desc[] = {