Browse Source

Save lastk field to post so torrent-less navigation through posts is possible. => DONE

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
3e64454b7d
  1. 2
      TODO
  2. 38
      src/twister.cpp

2
TODO

@ -58,7 +58,7 @@ Key pair might have changed and currently we receive a lot of errors from other
- save_file() must truncate file. - save_file() must truncate file.
- Save lastk field to post so torrent-less navigation through posts is possible. - Save lastk field to post so torrent-less navigation through posts is possible. => DONE
- Implement dht-to-torrent gateway, the "swarm" resource (so poster may not need to be member - Implement dht-to-torrent gateway, the "swarm" resource (so poster may not need to be member
of his own torrent) of his own torrent)

38
src/twister.cpp

@ -1024,6 +1024,34 @@ Value dhtget(const Array& params, bool fHelp)
return ret; return ret;
} }
int findLastPublicPostLocalUser( std::string strUsername )
{
int lastk = -1;
LOCK(cs_twister);
if( strUsername.size() && m_userTorrent.count(strUsername) &&
m_userTorrent[strUsername].is_valid() ){
std::vector<std::string> pieces;
int max_id = std::numeric_limits<int>::max();
int since_id = -1;
m_userTorrent[strUsername].get_pieces(pieces, 1, max_id, since_id, USERPOST_FLAG_RT);
if( pieces.size() ) {
string const& piece = pieces.front();
lazy_entry v;
int pos;
error_code ec;
if (lazy_bdecode(piece.data(), piece.data()+piece.size(), v, ec, &pos) == 0) {
lazy_entry const* post = v.dict_find_dict("userpost");
lastk = post->dict_find_int_value("k",-1);
}
}
}
return lastk;
}
Value newpostmsg(const Array& params, bool fHelp) Value newpostmsg(const Array& params, bool fHelp)
{ {
if (fHelp || (params.size() != 3 && params.size() != 5)) if (fHelp || (params.size() != 3 && params.size() != 5))
@ -1047,6 +1075,11 @@ Value newpostmsg(const Array& params, bool fHelp)
} }
entry v; entry v;
// [MF] Warning: findLastPublicPostLocalUser requires that we follow ourselves
int lastk = findLastPublicPostLocalUser(strUsername);
if( lastk >= 0 )
v["userpost"]["lastk"] = lastk;
if( !createSignedUserpost(v, strUsername, k, strMsg, if( !createSignedUserpost(v, strUsername, k, strMsg,
NULL, NULL, NULL, NULL, NULL, NULL,
strReplyN, replyK) ) strReplyN, replyK) )
@ -1166,6 +1199,11 @@ Value newrtmsg(const Array& params, bool fHelp)
entry const *sig_rt= vrt.find_key("sig_userpost"); entry const *sig_rt= vrt.find_key("sig_userpost");
entry v; entry v;
// [MF] Warning: findLastPublicPostLocalUser requires that we follow ourselves
int lastk = findLastPublicPostLocalUser(strUsername);
if( lastk >= 0 )
v["userpost"]["lastk"] = lastk;
if( !createSignedUserpost(v, strUsername, k, "", if( !createSignedUserpost(v, strUsername, k, "",
rt, sig_rt, NULL, rt, sig_rt, NULL,
std::string(""), 0) ) std::string(""), 0) )

Loading…
Cancel
Save