Browse Source

add consistency checks to node_impl::putDataSigned and a flag to mean that locally generated content should be kept for periodic refresh.

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
5af649a58a
  1. 2
      libtorrent/include/libtorrent/aux_/session_impl.hpp
  2. 2
      libtorrent/include/libtorrent/kademlia/dht_tracker.hpp
  3. 2
      libtorrent/include/libtorrent/kademlia/node.hpp
  4. 2
      libtorrent/include/libtorrent/session.hpp
  5. 4
      libtorrent/src/kademlia/dht_tracker.cpp
  6. 42
      libtorrent/src/kademlia/node.cpp
  7. 4
      libtorrent/src/session.cpp
  8. 4
      libtorrent/src/session_impl.cpp
  9. 2
      src/twister.cpp

2
libtorrent/include/libtorrent/aux_/session_impl.hpp

@ -312,7 +312,7 @@ namespace libtorrent
boost::int64_t timeutc, int seq); boost::int64_t timeutc, int seq);
void dht_putDataSigned(std::string const &username, std::string const &resource, bool multi, void dht_putDataSigned(std::string const &username, std::string const &resource, bool multi,
entry const &p, std::string const &sig_p, std::string const &sig_user); entry const &p, std::string const &sig_p, std::string const &sig_user, bool local);
void dht_getData(std::string const &username, std::string const &resource, bool multi); void dht_getData(std::string const &username, std::string const &resource, bool multi);

2
libtorrent/include/libtorrent/kademlia/dht_tracker.hpp

@ -101,7 +101,7 @@ namespace libtorrent { namespace dht
boost::int64_t timeutc, int seq); boost::int64_t timeutc, int seq);
void putDataSigned(std::string const &username, std::string const &resource, bool multi, void putDataSigned(std::string const &username, std::string const &resource, bool multi,
entry const &p, std::string const &sig_p, std::string const &sig_user); entry const &p, std::string const &sig_p, std::string const &sig_user, bool local);
void getData(std::string const &username, std::string const &resource, bool multi, void getData(std::string const &username, std::string const &resource, bool multi,
boost::function<void(entry::list_type const&)> fdata, boost::function<void(entry::list_type const&)> fdata,

2
libtorrent/include/libtorrent/kademlia/node.hpp

@ -228,7 +228,7 @@ public:
boost::int64_t timeutc, int seq); boost::int64_t timeutc, int seq);
void putDataSigned(std::string const &username, std::string const &resource, bool multi, void putDataSigned(std::string const &username, std::string const &resource, bool multi,
entry const &p, std::string const &sig_p, std::string const &sig_user); entry const &p, std::string const &sig_p, std::string const &sig_user, bool local);
void getData(std::string const &username, std::string const &resource, bool multi, void getData(std::string const &username, std::string const &resource, bool multi,
boost::function<void(entry::list_type const&)> fdata, boost::function<void(entry::list_type const&)> fdata,

2
libtorrent/include/libtorrent/session.hpp

@ -443,7 +443,7 @@ namespace libtorrent
boost::int64_t timeutc, int seq); boost::int64_t timeutc, int seq);
void dht_putDataSigned(std::string const &username, std::string const &resource, bool multi, void dht_putDataSigned(std::string const &username, std::string const &resource, bool multi,
entry const &p, std::string const &sig_p, std::string const &sig_user); entry const &p, std::string const &sig_p, std::string const &sig_user, bool local);
void dht_getData(std::string const &username, std::string const &resource, bool multi); void dht_getData(std::string const &username, std::string const &resource, bool multi);

4
libtorrent/src/kademlia/dht_tracker.cpp

@ -441,9 +441,9 @@ namespace libtorrent { namespace dht
} }
void dht_tracker::putDataSigned(std::string const &username, std::string const &resource, bool multi, void dht_tracker::putDataSigned(std::string const &username, std::string const &resource, bool multi,
entry const &p, std::string const &sig_p, std::string const &sig_user) entry const &p, std::string const &sig_p, std::string const &sig_user, bool local)
{ {
m_dht.putDataSigned(username,resource, multi, p, sig_p, sig_user); m_dht.putDataSigned(username,resource, multi, p, sig_p, sig_user, local);
} }
void dht_tracker::getData(std::string const &username, std::string const &resource, bool multi, void dht_tracker::getData(std::string const &username, std::string const &resource, bool multi,

42
libtorrent/src/kademlia/node.cpp

@ -475,19 +475,59 @@ void node_impl::putData(std::string const &username, std::string const &resource
} }
void node_impl::putDataSigned(std::string const &username, std::string const &resource, bool multi, void node_impl::putDataSigned(std::string const &username, std::string const &resource, bool multi,
entry const &p, std::string const &sig_p, std::string const &sig_user) entry const &p, std::string const &sig_p, std::string const &sig_user, bool local)
{ {
printf("putDataSigned: username=%s,res=%s,multi=%d sig_user=%s\n", printf("putDataSigned: username=%s,res=%s,multi=%d sig_user=%s\n",
username.c_str(), resource.c_str(), multi, sig_user.c_str()); username.c_str(), resource.c_str(), multi, sig_user.c_str());
// consistency checks
entry const* seqEntry = p.find_key("seq");
entry const* heightEntry = p.find_key("height");
entry const* target = p.find_key("target");
std::string n, r, t;
if( target ) {
entry const* nEntry = target->find_key("n");
entry const* rEntry = target->find_key("r");
entry const* tEntry = target->find_key("t");
if( nEntry && nEntry->type() == entry::string_t )
n = nEntry->string();
if( rEntry && rEntry->type() == entry::string_t )
r = rEntry->string();
if( tEntry && tEntry->type() == entry::string_t )
t = tEntry->string();
}
if( p.find_key("v") && heightEntry && heightEntry->type() == entry::int_t &&
(multi || (seqEntry && seqEntry->type() == entry::int_t)) && target &&
n == username && r == resource && ((!multi && t == "s") || (multi && t == "m")) ) {
// search for nodes with ids close to id or with peers // search for nodes with ids close to id or with peers
// for info-hash id. then send putData to them. // for info-hash id. then send putData to them.
boost::intrusive_ptr<dht_get> ta(new dht_get(*this, username, resource, multi, boost::intrusive_ptr<dht_get> ta(new dht_get(*this, username, resource, multi,
boost::bind(&nop), boost::bind(&nop),
boost::bind(&putData_fun, _1, boost::ref(*this), p, sig_p, sig_user), true)); boost::bind(&putData_fun, _1, boost::ref(*this), p, sig_p, sig_user), true));
if( local ) {
// store it locally so it will be automatically refreshed with the rest
std::vector<char> pbuf;
bencode(std::back_inserter(pbuf), p);
std::string str_p = std::string(pbuf.data(),pbuf.size());
dht_storage_item item(str_p, sig_p, sig_user);
item.local_add_time = time(NULL);
std::vector<char> vbuf;
bencode(std::back_inserter(vbuf), p["v"]);
std::pair<char const*, int> bufv = std::make_pair(vbuf.data(), vbuf.size());
int seq = (seqEntry && seqEntry->type() == entry::int_t) ? seqEntry->integer() : -1;
int height = heightEntry->integer();
store_dht_item(item, ta->target(), multi, seq, height, bufv);
}
// now send it to the network (start transversal algorithm) // now send it to the network (start transversal algorithm)
ta->start(); ta->start();
} else {
printf("putDataSigned: consistency checks failed!\n");
}
} }

4
libtorrent/src/session.cpp

@ -864,10 +864,10 @@ namespace libtorrent
} }
void session::dht_putDataSigned(std::string const &username, std::string const &resource, bool multi, void session::dht_putDataSigned(std::string const &username, std::string const &resource, bool multi,
entry const &p, std::string const &sig_p, std::string const &sig_user) entry const &p, std::string const &sig_p, std::string const &sig_user, bool local)
{ {
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
TORRENT_ASYNC_CALL6(dht_putDataSigned, username, resource, multi, p, sig_p, sig_user); TORRENT_ASYNC_CALL7(dht_putDataSigned, username, resource, multi, p, sig_p, sig_user, local);
#endif #endif
} }

4
libtorrent/src/session_impl.cpp

@ -5789,9 +5789,9 @@ retry:
} }
void session_impl::dht_putDataSigned(std::string const &username, std::string const &resource, bool multi, void session_impl::dht_putDataSigned(std::string const &username, std::string const &resource, bool multi,
entry const &p, std::string const &sig_p, std::string const &sig_user) entry const &p, std::string const &sig_p, std::string const &sig_user, bool local)
{ {
if (m_dht) m_dht->putDataSigned(username, resource, multi, p, sig_p, sig_user); if (m_dht) m_dht->putDataSigned(username, resource, multi, p, sig_p, sig_user, local);
} }
void post_dht_getData(aux::session_impl *si, entry::list_type const&lst) void post_dht_getData(aux::session_impl *si, entry::list_type const&lst)

2
src/twister.cpp

@ -1365,7 +1365,7 @@ void dhtPutData(std::string const &username, std::string const &resource, bool m
return; return;
} }
ses->dht_putDataSigned(username,resource,multi,p,sig_p,sig_user); ses->dht_putDataSigned(username,resource,multi,p,sig_p,sig_user, true);
} }
Value dhtput(const Array& params, bool fHelp) Value dhtput(const Array& params, bool fHelp)

Loading…
Cancel
Save