mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-22 12:34:24 +00:00
add consistency checks to node_impl::putDataSigned and a flag to mean that locally generated content should be kept for periodic refresh.
This commit is contained in:
parent
7651134016
commit
5af649a58a
@ -312,7 +312,7 @@ namespace libtorrent
|
||||
boost::int64_t timeutc, int seq);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -101,7 +101,7 @@ namespace libtorrent { namespace dht
|
||||
boost::int64_t timeutc, int seq);
|
||||
|
||||
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,
|
||||
boost::function<void(entry::list_type const&)> fdata,
|
||||
|
@ -228,7 +228,7 @@ public:
|
||||
boost::int64_t timeutc, int seq);
|
||||
|
||||
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,
|
||||
boost::function<void(entry::list_type const&)> fdata,
|
||||
|
@ -443,7 +443,7 @@ namespace libtorrent
|
||||
boost::int64_t timeutc, int seq);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -441,9 +441,9 @@ namespace libtorrent { namespace dht
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -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,
|
||||
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",
|
||||
username.c_str(), resource.c_str(), multi, sig_user.c_str());
|
||||
|
||||
// search for nodes with ids close to id or with peers
|
||||
// for info-hash id. then send putData to them.
|
||||
boost::intrusive_ptr<dht_get> ta(new dht_get(*this, username, resource, multi,
|
||||
boost::bind(&nop),
|
||||
boost::bind(&putData_fun, _1, boost::ref(*this), p, sig_p, sig_user), true));
|
||||
// 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")) ) {
|
||||
|
||||
// now send it to the network (start transversal algorithm)
|
||||
ta->start();
|
||||
// search for nodes with ids close to id or with peers
|
||||
// for info-hash id. then send putData to them.
|
||||
boost::intrusive_ptr<dht_get> ta(new dht_get(*this, username, resource, multi,
|
||||
boost::bind(&nop),
|
||||
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)
|
||||
ta->start();
|
||||
} else {
|
||||
printf("putDataSigned: consistency checks failed!\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -864,10 +864,10 @@ namespace libtorrent
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -5789,9 +5789,9 @@ retry:
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -1365,7 +1365,7 @@ void dhtPutData(std::string const &username, std::string const &resource, bool m
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user