keep track of torrent location (n,k) for direct messages as well.

this way we may check for piece delivery to the network.
This commit is contained in:
Miguel Freitas 2015-05-31 09:06:42 -03:00
parent 1056d874bf
commit 2668b4d832
4 changed files with 18 additions and 6 deletions

View File

@ -417,7 +417,7 @@ namespace libtorrent
struct piece_pos
{
piece_pos() {}
piece_pos(int peer_count_, int index_)
piece_pos(boost::uint32_t peer_count_, int index_)
: peer_count(peer_count_)
, max_seen((peer_count_ <= max_seen_count) ? peer_count_ : max_seen_count)
, downloading(0)

View File

@ -1147,7 +1147,7 @@ string getGroupAliasByKey(const string &privKey)
return groupAlias;
}
void registerNewGroup(const string &privKey, const string &desc, const string &member, const string &invitedBy, int64_t utcTime)
void registerNewGroup(const string &privKey, const string &desc, const string &member, const string &invitedBy, int64_t utcTime, int k)
{
string groupAlias = getGroupAliasByKey(privKey);
if( !groupAlias.length() ) {
@ -1191,6 +1191,7 @@ void registerNewGroup(const string &privKey, const string &desc, const string &m
StoredDirectMsg stoDM;
stoDM.m_fromMe = false;
stoDM.m_from = invitedBy;
stoDM.m_k = k;
// temporary hack: we must add new fields to StoredDirectMsg so text may be translated by UI
stoDM.m_text = "*** '" + invitedBy + "' changed group description to: " + desc;
stoDM.m_utcTime = utcTime;
@ -1202,6 +1203,7 @@ void registerNewGroup(const string &privKey, const string &desc, const string &m
StoredDirectMsg stoDM;
stoDM.m_fromMe = false;
stoDM.m_from = invitedBy;
stoDM.m_k = k;
// temporary hack: we must add new fields to StoredDirectMsg so text may be translated by UI
stoDM.m_text = "*** Invited by '" + invitedBy + "' to group: " + desc;
stoDM.m_utcTime = utcTime;
@ -1211,7 +1213,7 @@ void registerNewGroup(const string &privKey, const string &desc, const string &m
}
}
void notifyNewGroupMember(string &groupAlias, string &newmember, string &invitedBy, int64_t utcTime)
void notifyNewGroupMember(string &groupAlias, string &newmember, string &invitedBy, int64_t utcTime, int k)
{
LOCK(cs_twister);
if( !m_groups.count(groupAlias) )
@ -1227,6 +1229,7 @@ void notifyNewGroupMember(string &groupAlias, string &newmember, string &invited
StoredDirectMsg stoDM;
stoDM.m_fromMe = false;
stoDM.m_from = invitedBy;
stoDM.m_k = k;
// temporary hack: we must add new fields to StoredDirectMsg so text may be translated by UI
stoDM.m_text = "*** New member '" + newmember + "' invited by '" + invitedBy + "'";
stoDM.m_utcTime = utcTime;
@ -1266,6 +1269,7 @@ bool processReceivedDM(lazy_entry const* post)
int64_t utcTime = post->dict_find_int_value("time");
std::string from = post->dict_find_string_value("n");
int k = post->dict_find_int_value("k",-1);
std::string to = item.second.username; // default (old format)
std::string msg = textOut; // default (old format)
bool fromMe = (from == to);
@ -1300,7 +1304,7 @@ bool processReceivedDM(lazy_entry const* post)
if (pDesc && pKey) {
string desc = pDesc->string_value();
string privKey = pKey->string_value();
registerNewGroup(privKey, desc, to, from, utcTime);
registerNewGroup(privKey, desc, to, from, utcTime, k);
}
break;
}
@ -1312,7 +1316,7 @@ bool processReceivedDM(lazy_entry const* post)
for (int i = 0; i < pGroupMembers->list_size(); ++i) {
std::string member = pGroupMembers->list_string_value_at(i);
if (member.empty()) continue;
notifyNewGroupMember(to, member, from, utcTime);
notifyNewGroupMember(to, member, from, utcTime, k);
torrentsToStart.insert(member);
}
break;
@ -1334,6 +1338,7 @@ bool processReceivedDM(lazy_entry const* post)
StoredDirectMsg stoDM;
stoDM.m_fromMe = fromMe;
stoDM.m_from = from;
stoDM.m_k = k;
stoDM.m_text = msg;
stoDM.m_utcTime = utcTime;
@ -2271,6 +2276,7 @@ Value newdirectmsg(const Array& params, bool fHelp)
StoredDirectMsg stoDM;
stoDM.m_fromMe = true;
stoDM.m_from = strFrom;
stoDM.m_k = k;
stoDM.m_text = strMsg;
stoDM.m_utcTime = v["userpost"]["time"].integer();
@ -2533,6 +2539,7 @@ Value getdirectmsgs(const Array& params, bool fHelp)
dmObj.push_back(Pair("text",dmsFromToUser.at(i).m_text));
dmObj.push_back(Pair("fromMe",dmsFromToUser.at(i).m_fromMe));
dmObj.push_back(Pair("from",dmsFromToUser.at(i).m_from));
dmObj.push_back(Pair("k",dmsFromToUser.at(i).m_k));
userMsgs.push_back(dmObj);
}
if( userMsgs.size() ) {
@ -3416,6 +3423,8 @@ Value search(const Array& params, bool fHelp)
vEntry["text"] = item.m_text;
vEntry["time"] = time;
vEntry["fromMe"] = item.m_fromMe;
vEntry["from"] = item.m_from;
vEntry["k"] = item.m_k;
hexcapePost(vEntry);
postsByTime.insert( pair<int64,entry>(time, vEntry) );
}
@ -3594,7 +3603,7 @@ Value creategroup(const Array& params, bool fHelp)
string privKey = CBitcoinSecret(secret).ToString();
string noMember;
registerNewGroup(privKey, strDescription, noMember, noMember, GetTime());
registerNewGroup(privKey, strDescription, noMember, noMember, GetTime(), -1);
return getGroupAliasByKey(privKey);
}

View File

@ -170,6 +170,7 @@ int saveUserData(std::string const& filename, std::map<std::string,UserData> con
dmElem["text"] = stoDm.m_text;
dmElem["fromMe"] = stoDm.m_fromMe;
dmElem["from"] = stoDm.m_from;
dmElem["k"] = stoDm.m_k;
dmList.list().push_back(dmElem);
}
}
@ -256,6 +257,7 @@ int loadUserData(std::string const& filename, std::map<std::string,UserData> &us
stoDm.m_utcTime = dmElem->dict_find_int_value("time");
stoDm.m_fromMe = dmElem->dict_find_int_value("fromMe");
stoDm.m_from = dmElem->dict_find_string_value("from");
stoDm.m_k = dmElem->dict_find_int_value("k",-1);
udata.m_directmsg[dmDict->dict_at(j).first].push_back(stoDm);
}
}

View File

@ -15,6 +15,7 @@ struct StoredDirectMsg {
std::string m_text;
bool m_fromMe;
std::string m_from; // used for group chat
int m_k; // (m_from,m_k) is location of this post in torrent
};
struct GroupChat {