mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-22 20:44:56 +00:00
compare contents (v) before adding multi valued key
This commit is contained in:
parent
830a02c009
commit
9c52adbe25
@ -142,7 +142,10 @@ struct dht_mutable_item : dht_immutable_item
|
|||||||
|
|
||||||
struct dht_storage_item
|
struct dht_storage_item
|
||||||
{
|
{
|
||||||
|
// FIXME: optimize so bdecode is not needed all the time
|
||||||
dht_storage_item() : p(), sig_p(), sig_user() {}
|
dht_storage_item() : p(), sig_p(), sig_user() {}
|
||||||
|
dht_storage_item(std::string &_p, lazy_entry const *_sig_p, lazy_entry const *_sig_user)
|
||||||
|
: p(_p), sig_p(_sig_p->string_value()), sig_user(_sig_user->string_value()) {}
|
||||||
std::string p;
|
std::string p;
|
||||||
std::string sig_p;
|
std::string sig_p;
|
||||||
std::string sig_user;
|
std::string sig_user;
|
||||||
|
@ -1221,19 +1221,15 @@ void node_impl::incoming_request(msg const& m, entry& e)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dht_storage_item item(str_p, msg_keys[mk_sig_p], msg_keys[mk_sig_user]);
|
||||||
dht_storage_table_t::iterator i = m_storage_table.find(target);
|
dht_storage_table_t::iterator i = m_storage_table.find(target);
|
||||||
if (i == m_storage_table.end()) {
|
if (i == m_storage_table.end()) {
|
||||||
// make sure we don't add too many items
|
// make sure we don't add too many items
|
||||||
if (int(m_storage_table.size()) >= m_settings.max_dht_items)
|
if (int(m_storage_table.size()) >= m_settings.max_dht_items)
|
||||||
{
|
{
|
||||||
// erase one? preferably a multi
|
// FIXME: erase one? preferably a multi
|
||||||
}
|
}
|
||||||
|
|
||||||
dht_storage_item item;
|
|
||||||
item.p = str_p;
|
|
||||||
item.sig_p = msg_keys[mk_sig_p]->string_value();
|
|
||||||
item.sig_user = msg_keys[mk_sig_user]->string_value();
|
|
||||||
|
|
||||||
dht_storage_list_t to_add;
|
dht_storage_list_t to_add;
|
||||||
to_add.push_back(item);
|
to_add.push_back(item);
|
||||||
|
|
||||||
@ -1242,37 +1238,39 @@ void node_impl::incoming_request(msg const& m, entry& e)
|
|||||||
} else {
|
} else {
|
||||||
dht_storage_list_t & lsto = i->second;
|
dht_storage_list_t & lsto = i->second;
|
||||||
|
|
||||||
// if not multi, seq must increase
|
int j;
|
||||||
if(!multi) {
|
for( j = 0; j < lsto.size(); j++) {
|
||||||
dht_storage_item &item = lsto[0];
|
dht_storage_item &olditem = lsto[j];
|
||||||
|
|
||||||
lazy_entry p;
|
lazy_entry p;
|
||||||
int pos;
|
int pos;
|
||||||
error_code err;
|
error_code err;
|
||||||
int ret = lazy_bdecode(item.p.data(), item.p.data() + item.p.size(), p, err, &pos, 10, 500);
|
// FIXME: optimize to avoid bdecode (store seq separated, etc)
|
||||||
if( msg_keys[mk_seq]->int_value() > p.dict_find_int("seq")->int_value() ) {
|
int ret = lazy_bdecode(olditem.p.data(), olditem.p.data() + olditem.p.size(), p, err, &pos, 10, 500);
|
||||||
item.p = str_p;
|
|
||||||
item.sig_p = msg_keys[mk_sig_p]->string_value();
|
if( !multi ) {
|
||||||
item.sig_user = msg_keys[mk_sig_user]->string_value();
|
if( msg_keys[mk_seq]->int_value() > p.dict_find_int("seq")->int_value() ) {
|
||||||
|
olditem = item;
|
||||||
|
} else {
|
||||||
|
incoming_error(e, "old sequence number");
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
incoming_error(e, "old sequence number");
|
std::pair<char const*, int> bufv = msg_keys[mk_v]->data_section();
|
||||||
return;
|
|
||||||
|
// compare contents before adding to the list
|
||||||
|
std::pair<char const*, int> bufoldv = p.dict_find("v")->data_section();
|
||||||
|
if( bufv.second == bufoldv.second &&
|
||||||
|
!memcmp(bufv.first, bufoldv.first,bufv.second)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
dht_storage_list_t::iterator j = lsto.begin(), end(lsto.end());
|
|
||||||
for (; j != end; ++j)
|
|
||||||
{
|
|
||||||
// compare p contents before adding to the list
|
|
||||||
if( j->p == str_p ) break;
|
|
||||||
}
|
|
||||||
if(j == end) {
|
|
||||||
// new entry
|
|
||||||
dht_storage_item item;
|
|
||||||
item.p = str_p;
|
|
||||||
item.sig_p = msg_keys[mk_sig_p]->string_value();
|
|
||||||
item.sig_user = msg_keys[mk_sig_user]->string_value();
|
|
||||||
lsto.push_back(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if(multi && j == lsto.size()) {
|
||||||
|
// new entry
|
||||||
|
lsto.push_back(item);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_table.node_seen(id, m.addr, 0xffff);
|
m_table.node_seen(id, m.addr, 0xffff);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user