Merge pull request #1838 from csoler/v0.6-FT4

Converting GxsMessageFrameWidget to blocking API, removing more TokenQueue from UI
This commit is contained in:
csoler 2020-04-03 18:02:30 +02:00 committed by GitHub
commit a0816c7324
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 572 additions and 1124 deletions

View file

@ -217,7 +217,8 @@ bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType,
mmr->mMsgIds[*lit] = std::set<RsGxsMessageId>();
req = mmr;
}else if(reqType & GXS_REQUEST_TYPE_MSG_DATA)
}
else if(reqType & GXS_REQUEST_TYPE_MSG_DATA)
{
MsgDataReq* mdr = new MsgDataReq();
@ -225,7 +226,8 @@ bool RsGxsDataAccess::requestMsgInfo(uint32_t &token, uint32_t ansType,
mdr->mMsgIds[*lit] = std::set<RsGxsMessageId>();
req = mdr;
}else if(reqType & GXS_REQUEST_TYPE_MSG_IDS)
}
else if(reqType & GXS_REQUEST_TYPE_MSG_IDS)
{
MsgIdReq* mir = new MsgIdReq();

View file

@ -67,14 +67,6 @@ bool PgpAuxUtilsImpl::parseSignature(unsigned char *sign, unsigned int signlen,
return AuthGPG::getAuthGPG()->parseSignature(sign,signlen,issuer);
}
bool PgpAuxUtilsImpl::askForDeferredSelfSignature(const void *data,
const uint32_t len,
unsigned char *sign,
unsigned int *signlen,
int& signature_result , std::string reason)
{
return RsServer::notify()->askForDeferredSelfSignature(data, len, sign, signlen, signature_result, reason);
}

View file

@ -41,10 +41,6 @@ class PgpAuxUtils
virtual bool parseSignature(unsigned char *sign, unsigned int signlen, RsPgpId& issuer) const =0;
virtual bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint) = 0;
/** @deprecated this method depends on retroshare-gui to work */
RS_DEPRECATED_FOR("AuthGPG::SignDataBin")
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason) = 0;
};
class PgpAuxUtilsImpl: public PgpAuxUtils
@ -59,8 +55,6 @@ public:
virtual bool getKeyFingerprint(const RsPgpId& id,PGPFingerprintType& fp) const;
virtual bool VerifySignBin(const void *data, uint32_t len, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint);
virtual bool getGPGAllList(std::list<RsPgpId> &ids);
virtual bool askForDeferredSelfSignature(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason);
};

View file

@ -293,14 +293,6 @@ bool p3Notify::askForPluginConfirmation (const std::string& plugin_filen
return false ;
}
bool p3Notify::askForDeferredSelfSignature (const void * data , const uint32_t len , unsigned char *sign, unsigned int *signlen,int& signature_result, std::string reason /*=""*/)
{
FOR_ALL_NOTIFY_CLIENTS
if( (*it)->askForDeferredSelfSignature(data,len,sign,signlen,signature_result, reason))
return true ;
return false ;
}
void p3Notify::registerNotifyClient(NotifyClient *cl)
{

View file

@ -114,7 +114,6 @@ class p3Notify: public RsNotify
void notifyPeerStatusChangedSummary () ;
void notifyDiscInfoChanged () ;
bool askForDeferredSelfSignature (const void * /* data */, const uint32_t /* len */, unsigned char * /* sign */, unsigned int * /* signlen */, int& signature_result , std::string reason = "") ;
void notifyDownloadComplete (const std::string& /* fileHash */) ;
void notifyDownloadCompleteCount (uint32_t /* count */) ;
void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) ;

View file

@ -68,12 +68,10 @@ struct RsGxsChannelGroup : RsSerializable, RsGxsGenericGroupData
~RsGxsChannelGroup() override;
};
struct RsGxsChannelPost : RsSerializable
struct RsGxsChannelPost : RsSerializable, RsGxsGenericMsgData
{
RsGxsChannelPost() : mCount(0), mSize(0) {}
RsMsgMetaData mMeta;
std::set<RsGxsMessageId> mOlderVersions;
std::string mMsg; // UTF8 encoded.
@ -325,7 +323,20 @@ public:
std::vector<RsGxsChannelGroup>& channelsInfo ) = 0;
/**
* @brief Get channel contents
* @brief Get all channel messages and comments in a given channel
* @jsonapi{development}
* @param[in] channelId id of the channel of which the content is requested
* @param[out] posts storage for posts
* @param[out] comments storage for the comments
* @return false if something failed, true otherwhise
*/
virtual bool getChannelAllContent(const RsGxsGroupId& channelId,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) = 0;
/**
* @brief Get channel messages and comments corresponding to the given message ID list. If the list is empty, nothing is returned. Since
* comments are themselves messages, it is possible to get comments only by only supplying their message IDs.
* @jsonapi{development}
* @param[in] channelId id of the channel of which the content is requested
* @param[in] contentsIds ids of requested contents
@ -333,10 +344,10 @@ public:
* @param[out] comments storage for the comments
* @return false if something failed, true otherwhise
*/
virtual bool getChannelContent( const RsGxsGroupId& channelId,
const std::set<RsGxsMessageId>& contentsIds,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) = 0;
virtual bool getChannelContent(const RsGxsGroupId& channelId,
const std::set<RsGxsMessageId>& contentIds,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) = 0;
/**
* @brief Get channel content summaries

View file

@ -40,14 +40,19 @@
* are necessary, so at this point this workaround seems acceptable.
*/
#define DEBUG_GXSIFACEHELPER 1
enum class TokenRequestType: uint8_t
{
GROUP_INFO = 0x01,
MSG_INFO = 0x02,
MSG_RELATED_INFO = 0x03,
GROUP_STATISTICS = 0x04,
SERVICE_STATISTICS = 0x05,
NO_KILL_TYPE = 0x06,
UNDEFINED = 0x00,
GROUP_DATA = 0x01,
GROUP_META = 0x02,
POSTS = 0x03,
ALL_POSTS = 0x04,
MSG_RELATED_INFO = 0x05,
GROUP_STATISTICS = 0x06,
SERVICE_STATISTICS = 0x07,
NO_KILL_TYPE = 0x08,
};
class RsGxsIfaceHelper
@ -248,12 +253,23 @@ public:
/// @see RsTokenService::requestGroupInfo
bool requestGroupInfo( uint32_t& token, const RsTokReqOptions& opts, const std::list<RsGxsGroupId> &groupIds, bool high_priority_request = false )
{
cancelActiveRequestTokens(TokenRequestType::GROUP_INFO);
TokenRequestType token_request_type;
switch(opts.mReqType)
{
case GXS_REQUEST_TYPE_GROUP_DATA: token_request_type = TokenRequestType::GROUP_DATA; break;
case GXS_REQUEST_TYPE_GROUP_META: token_request_type = TokenRequestType::GROUP_META; break;
default:
RsErr() << __PRETTY_FUNCTION__ << "(EE) Unexpected request type " << opts.mReqType << "!!" << std::endl;
return false;
}
cancelActiveRequestTokens(token_request_type);
if( mTokenService.requestGroupInfo(token, 0, opts, groupIds))
{
RS_STACK_MUTEX(mMtx);
mActiveTokens[token]=high_priority_request? (TokenRequestType::NO_KILL_TYPE) : (TokenRequestType::GROUP_INFO);
mActiveTokens[token]=high_priority_request? (TokenRequestType::NO_KILL_TYPE) : token_request_type;
locked_dumpTokens();
return true;
}
@ -264,12 +280,24 @@ public:
/// @see RsTokenService::requestGroupInfo
bool requestGroupInfo(uint32_t& token, const RsTokReqOptions& opts, bool high_priority_request = false)
{
cancelActiveRequestTokens(TokenRequestType::GROUP_INFO);
TokenRequestType token_request_type;
switch(opts.mReqType)
{
case GXS_REQUEST_TYPE_GROUP_DATA: token_request_type = TokenRequestType::GROUP_DATA; break;
case GXS_REQUEST_TYPE_GROUP_META: token_request_type = TokenRequestType::GROUP_META; break;
default:
RsErr() << __PRETTY_FUNCTION__ << "(EE) Unexpected request type " << opts.mReqType << "!!" << std::endl;
return false;
}
cancelActiveRequestTokens(token_request_type);
if( mTokenService.requestGroupInfo(token, 0, opts))
{
RS_STACK_MUTEX(mMtx);
mActiveTokens[token]=high_priority_request? (TokenRequestType::NO_KILL_TYPE) : (TokenRequestType::GROUP_INFO);
mActiveTokens[token]=high_priority_request? (TokenRequestType::NO_KILL_TYPE) : token_request_type;
locked_dumpTokens();
return true;
}
@ -278,13 +306,13 @@ public:
}
/// @see RsTokenService::requestMsgInfo
bool requestMsgInfo( uint32_t& token,
const RsTokReqOptions& opts, const GxsMsgReq& msgIds )
bool requestMsgInfo( uint32_t& token, const RsTokReqOptions& opts, const GxsMsgReq& msgIds )
{
if(mTokenService.requestMsgInfo(token, 0, opts, msgIds))
{
RS_STACK_MUTEX(mMtx);
mActiveTokens[token]=TokenRequestType::MSG_INFO;
mActiveTokens[token]= (msgIds.size()==1 && msgIds.begin()->second.size()==0) ?(TokenRequestType::ALL_POSTS):(TokenRequestType::POSTS);
locked_dumpTokens();
return true;
}
@ -298,7 +326,7 @@ public:
if(mTokenService.requestMsgInfo(token, 0, opts, grpIds))
{
RS_STACK_MUTEX(mMtx);
mActiveTokens[token]=TokenRequestType::MSG_INFO;
mActiveTokens[token]=TokenRequestType::ALL_POSTS;
locked_dumpTokens();
return true;
}
@ -459,15 +487,15 @@ private:
uint32_t count[7] = {0};
std::cerr << "Service 0x0" << std::hex << service_id
std::cerr << "Service " << std::hex << service_id << std::dec
<< " (" << rsServiceControl->getServiceName(RsServiceInfo::RsServiceInfoUIn16ToFullServiceId(service_id))
<< ") this=0x" << (void*)this << ") Active tokens (per type): " ;
<< ") this=" << std::hex << (void*)this << std::dec << ") Active tokens (per type): " ;
for(auto& it: mActiveTokens) // let's count how many token of each type we've got.
++count[static_cast<int>(it.second)];
for(uint32_t i=0;i<7;++i)
std::cerr /* << i << ":" */ << count[i] << " ";
std::cerr << std::dec /* << i << ":" */ << count[i] << " ";
std::cerr << std::endl;
}
};

View file

@ -184,6 +184,14 @@ struct RsMsgMetaData : RsSerializable
}
};
struct RsGxsGenericMsgData
{
virtual ~RsGxsGenericMsgData() = default; // making the type polymorphic
RsMsgMetaData mMeta;
};
class GxsGroupStatistic
{
public:

View file

@ -237,7 +237,6 @@ public:
virtual void notifyPeerStatusChangedSummary () {}
virtual void notifyDiscInfoChanged () {}
virtual bool askForDeferredSelfSignature (const void * /* data */, const uint32_t /* len */, unsigned char * /* sign */, unsigned int * /* signlen */,int& signature_result , std::string /*reason = ""*/) { signature_result = false ;return true; }
virtual void notifyDownloadComplete (const std::string& /* fileHash */) {}
virtual void notifyDownloadCompleteCount (uint32_t /* count */) {}
virtual void notifyHistoryChanged (uint32_t /* msgId */, int /* type */) {}

View file

@ -46,14 +46,13 @@ struct RsPostedGroup: RsGxsGenericGroupData
RsGxsImage mGroupImage;
};
struct RsPostedPost
struct RsPostedPost: public RsGxsGenericMsgData
{
RsPostedPost(): mHaveVoted(false), mUpVotes(0), mDownVotes(0), mComments(0),
mHotScore(0), mTopScore(0), mNewScore(0) {}
bool calculateScores(rstime_t ref_time);
RsMsgMetaData mMeta;
std::string mLink;
std::string mNotes;
@ -151,6 +150,11 @@ public:
virtual bool getBoardsSummaries(std::list<RsGroupMetaData>& groupInfo) =0;
virtual bool getBoardAllContent(
const RsGxsGroupId& boardId,
std::vector<RsPostedPost>& posts,
std::vector<RsGxsComment>& comments ) = 0;
virtual bool getBoardContent(
const RsGxsGroupId& boardId,
const std::set<RsGxsMessageId>& contentsIds,

View file

@ -1083,20 +1083,34 @@ bool p3GxsChannels::getContentSummaries(
return res;
}
bool p3GxsChannels::getChannelAllContent( const RsGxsGroupId& channelId,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments )
{
uint32_t token;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
if( !requestMsgInfo(token, opts,std::list<RsGxsGroupId>({channelId})) || waitToken(token) != RsTokenService::COMPLETE )
return false;
return getPostData(token, posts, comments);
}
bool p3GxsChannels::getChannelContent( const RsGxsGroupId& channelId,
const std::set<RsGxsMessageId>& contentsIds,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments )
const std::set<RsGxsMessageId>& contentIds,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments )
{
uint32_t token;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
GxsMsgReq msgIds;
msgIds[channelId] = contentsIds;
msgIds[channelId] = contentIds;
if( !requestMsgInfo(token, opts, msgIds) ||
waitToken(token) != RsTokenService::COMPLETE ) return false;
if( !requestMsgInfo(token, opts, msgIds) || waitToken(token) != RsTokenService::COMPLETE )
return false;
return getPostData(token, posts, comments);
}

View file

@ -185,9 +185,14 @@ virtual bool ExtraFileRemove(const RsFileHash &hash);
const std::list<RsGxsGroupId>& chanIds,
std::vector<RsGxsChannelGroup>& channelsInfo ) override;
/// Implementation of @see RsGxsChannels::getChannelContent
bool getChannelContent( const RsGxsGroupId& channelId,
const std::set<RsGxsMessageId>& contentsIds,
/// Implementation of @see RsGxsChannels::getChannelAllMessages
bool getChannelAllContent(const RsGxsGroupId& channelId,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) override;
/// Implementation of @see RsGxsChannels::getChannelMessages
bool getChannelContent(const RsGxsGroupId& channelId,
const std::set<RsGxsMessageId>& contentIds,
std::vector<RsGxsChannelPost>& posts,
std::vector<RsGxsComment>& comments ) override;

View file

@ -3522,25 +3522,7 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(
unsigned int sign_size = MAX_SIGN_SIZE;
memset(signarray,0,MAX_SIGN_SIZE) ; // just in case.
/* -10 is never returned by askForDeferredSelfSignature therefore we can
* use it to properly detect and handle the case libretroshare is being
* used outside retroshare-gui */
int result = -10;
/* This method is DEPRECATED we call it only for retrocompatibility with
* retroshare-gui, when called from something different then
* retroshare-gui for example retroshare-service it miserably fail! */
mPgpUtils->askForDeferredSelfSignature(
static_cast<const void*>(hash.toByteArray()),
hash.SIZE_IN_BYTES, signarray, &sign_size, result,
__PRETTY_FUNCTION__ );
/* If askForDeferredSelfSignature left result untouched it means
* libretroshare is being used by something different then
* retroshare-gui so try calling AuthGPG::getAuthGPG()->SignDataBin
* directly */
if( result == -10 )
result = AuthGPG::getAuthGPG()->SignDataBin(
int result = AuthGPG::getAuthGPG()->SignDataBin(
static_cast<const void*>(hash.toByteArray()),
hash.SIZE_IN_BYTES, signarray, &sign_size,
__PRETTY_FUNCTION__ )

View file

@ -322,6 +322,20 @@ bool p3Posted::getBoardsInfo(
return getGroupData(token, groupsInfo) && !groupsInfo.empty();
}
bool p3Posted::getBoardAllContent( const RsGxsGroupId& groupId,
std::vector<RsPostedPost>& posts,
std::vector<RsGxsComment>& comments )
{
uint32_t token;
RsTokReqOptions opts;
opts.mReqType = GXS_REQUEST_TYPE_MSG_DATA;
if( !requestMsgInfo(token, opts, std::list<RsGxsGroupId>({groupId})) || waitToken(token) != RsTokenService::COMPLETE )
return false;
return getPostData(token, posts, comments);
}
bool p3Posted::getBoardContent( const RsGxsGroupId& groupId,
const std::set<RsGxsMessageId>& contentsIds,
std::vector<RsPostedPost>& posts,

View file

@ -61,6 +61,10 @@ virtual void receiveHelperChanges(std::vector<RsGxsNotify*>& changes)
bool getBoardsInfo(const std::list<RsGxsGroupId>& boardsIds,
std::vector<RsPostedGroup>& groupsInfo ) override;
bool getBoardAllContent(const RsGxsGroupId& groupId,
std::vector<RsPostedPost>& posts,
std::vector<RsGxsComment>& comments ) override;
bool getBoardContent(const RsGxsGroupId& groupId,
const std::set<RsGxsMessageId>& contentsIds,
std::vector<RsPostedPost>& posts,