Merge pull request #1815 from drbob/thewire-get-basics-working

Get the basics of TheWire service working
This commit is contained in:
csoler 2020-03-01 16:40:35 +01:00 committed by GitHub
commit 76596e678e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 2311 additions and 1110 deletions

View file

@ -3,7 +3,7 @@
* *
* libretroshare: retroshare core library *
* *
* Copyright 2012-2012 by Robert Fernie <retroshare@lunamutt.com> *
* Copyright 2012-2020 by Robert Fernie <retroshare@lunamutt.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -45,11 +45,7 @@ class RsWireGroup
/***********************************************************************
* So pulses operate in the following modes.
*
* => Standard, a post to your own group.
* => @User, gets duplicated on each user's group.
* => RT, duplicated as child of original post.
* RsWire - is intended to be a Twitter clone - but fully decentralised.
*
* From Twitter:
* twitter can be: embedded, replied to, favourited, unfavourited,
@ -73,6 +69,36 @@ class RsWirePlace
};
/************************************************************************
* Pulse comes in three flavours.
*
*
* Original Msg Pulse
* - Spontaneous msg, on your own group.
* - mPulseType = WIRE_PULSE_TYPE_ORIGINAL_MSG
* - Ref fields are empty.
*
* Reply to a Pulse (i.e Retweet), has two parts.
* as we want the retweet to reference the original, and the original to know about reply.
* This info will be duplicated in two msgs - but allow data to spread easier.
*
* Reply Msg Pulse, will be Top-Level Msg on Publisher's Group.
* - mPulseMode = WIRE_PULSE_TYPE_REPLY_MSG
* - Ref fields refer to Parent (InReplyTo) Msg.
*
* Reply Reference, is Child Msg of Parent Msg, on Parent Publisher's Group.
* - mPulseMode = WIRE_PULSE_TYPE_REPLY_REFERENCE
* - Ref fields refer to Reply Msg.
* - NB: This Msg requires Parent Msg for complete info, while other two are self-contained.
***********************************************************************/
#define WIRE_PULSE_TYPE_ORIGINAL_MSG (0x0001)
#define WIRE_PULSE_TYPE_REPLY_MSG (0x0002)
#define WIRE_PULSE_TYPE_REPLY_REFERENCE (0x0004)
#define WIRE_PULSE_TYPE_SENTIMENT_POSITIVE (0x0010)
#define WIRE_PULSE_TYPE_SENTIMENT_NEUTRAL (0x0020)
#define WIRE_PULSE_TYPE_SENTIMENT_NEGATIVE (0x0040)
class RsWirePulse
{
@ -80,19 +106,26 @@ class RsWirePulse
RsMsgMetaData mMeta;
std::string mPulseText; // all the text is stored here.
std::string mHashTags;
// Store actual Pulse here.
std::string mPulseText;
// These will be added at some point.
// std::string mInReplyPulse;
uint32_t mPulseType;
// uint32_t mPulseFlags;
// These Ref to the related (parent or reply) if reply (MODE_REPLY_MSG set)
// Mode REPLY_MSG only REPLY_REFERENCE
RsGxsGroupId mRefGroupId; // PARENT_GrpId REPLY_GrpId
std::string mRefGroupName; // PARENT_GrpName REPLY_GrpName
RsGxsMessageId mRefOrigMsgId; // PARENT_OrigMsgId REPLY_OrigMsgId
RsGxsId mRefAuthorId; // PARENT_AuthorId REPLY_AuthorId
rstime_t mRefPublishTs; // PARENT_PublishTs REPLY_PublishTs
std::string mRefPulseText; // PARENT_PulseText REPLY_PulseText
// std::list<std::string> mMentions;
// std::list<std::string> mHashTags;
// std::list<std::string> mUrls;
// RsWirePlace mPlace;
// Open Question. Do we want these additional fields?
// These can potentially be added at some point.
// std::list<std::string> mMentions;
// std::list<std::string> mHashTags;
// std::list<std::string> mUrls;
// RsWirePlace mPlace;
};
@ -107,6 +140,13 @@ class RsWire: public RsGxsIfaceHelper
explicit RsWire(RsGxsIface& gxs) : RsGxsIfaceHelper(gxs) {}
virtual ~RsWire() {}
/*!
* To acquire a handle to token service handler
* needed to make requests to the service
* @return handle to token service for this gxs service
*/
virtual RsTokenService* getTokenService() = 0;
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, std::vector<RsWireGroup> &groups) = 0;
virtual bool getPulseData(const uint32_t &token, std::vector<RsWirePulse> &pulses) = 0;

View file

@ -29,16 +29,16 @@
RsItem *RsGxsWireSerialiser::create_item(uint16_t service,uint8_t item_subtype) const
{
if(service != RS_SERVICE_GXS_TYPE_WIRE)
return NULL ;
if(service != RS_SERVICE_GXS_TYPE_WIRE)
return NULL ;
switch(item_subtype)
{
case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM: return new RsGxsWireGroupItem();
case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM: return new RsGxsWirePulseItem();
default:
return NULL ;
}
switch(item_subtype)
{
case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM: return new RsGxsWireGroupItem();
case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM: return new RsGxsWirePulseItem();
default:
return NULL ;
}
}
void RsGxsWireGroupItem::clear()
@ -48,18 +48,30 @@ void RsGxsWireGroupItem::clear()
void RsGxsWireGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,group.mDescription,"group.mDescription") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,group.mDescription,"group.mDescription") ;
}
void RsGxsWirePulseItem::clear()
{
pulse.mPulseText.clear();
pulse.mHashTags.clear();
pulse.mPulseType = 0;
pulse.mRefGroupId.clear();
pulse.mRefGroupName.clear();
pulse.mRefOrigMsgId.clear();
pulse.mRefAuthorId.clear();
pulse.mRefPulseText.clear();
}
void RsGxsWirePulseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx)
{
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mPulseText,"pulse.mPulseText") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,pulse.mHashTags,"pulse.mHashTags") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mPulseText,"pulse.mPulseText") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_UINT32_PARAM,pulse.mPulseType,"pulse.mPulseType") ;
RsTypeSerializer::serial_process(j,ctx,pulse.mRefGroupId,"pulse.mRefGroupId") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_NAME,pulse.mRefGroupName,"pulse.mRefGroupName") ;
RsTypeSerializer::serial_process(j,ctx,pulse.mRefOrigMsgId,"pulse.mRefOrigMsgId") ;
RsTypeSerializer::serial_process(j,ctx,pulse.mRefAuthorId,"pulse.mRefAuthorId") ;
RsTypeSerializer::serial_process(j,ctx,pulse.mRefPublishTs,"pulse.mRefPublishTs") ;
RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mRefPulseText,"pulse.mRefPulseText") ;
}

View file

@ -1381,8 +1381,7 @@ int RsServer::StartupRetroShare()
#ifdef RS_USE_WIRE
/**** Wire GXS service ****/
RsGeneralDataService* wire_ds = new RsDataService(currGxsDir + "/", "wire_db",
RS_SERVICE_GXS_TYPE_WIRE,
NULL, rsInitConfig->gxs_passwd);
RS_SERVICE_GXS_TYPE_WIRE, NULL, rsInitConfig->gxs_passwd);
p3Wire *mWire = new p3Wire(wire_ds, NULL, mGxsIdService);
@ -1826,7 +1825,7 @@ int RsServer::StartupRetroShare()
startServiceThread(mPhoto, "gxs photo");
#endif
#if RS_USE_WIRE
startServiceThread(mPhoto, "gxs wire");
startServiceThread(mWire, "gxs wire");
#endif
// cores ready start up GXS net servers
@ -1843,7 +1842,7 @@ int RsServer::StartupRetroShare()
startServiceThread(photo_ns, "gxs photo ns");
#endif
#if RS_USE_WIRE
startServiceThread(photo_ns, "gxs wire ns");
startServiceThread(wire_ns, "gxs wire ns");
#endif
# ifdef RS_GXS_TRANS

View file

@ -3,7 +3,7 @@
* *
* libretroshare: retroshare core library *
* *
* Copyright 2012-2012 by Robert Fernie <retroshare@lunamutt.com> *
* Copyright 2012-2020 by Robert Fernie <retroshare@lunamutt.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -83,6 +83,10 @@ void p3Wire::service_tick()
return;
}
RsTokenService* p3Wire::getTokenService() {
return RsGenExchange::getTokenService();
}
void p3Wire::notifyChanges(std::vector<RsGxsNotify*>& changes)
{
@ -175,12 +179,12 @@ bool p3Wire::createGroup(uint32_t &token, RsWireGroup &group)
groupItem->group = group;
groupItem->meta = group.mMeta;
std::cerr << "p3Wire::createGroup(): ";
std::cerr << "p3Wire::createGroup(): ";
std::cerr << std::endl;
std::cerr << group;
std::cerr << std::endl;
std::cerr << "p3Wire::createGroup() pushing to RsGenExchange";
std::cerr << "p3Wire::createGroup() pushing to RsGenExchange";
std::cerr << std::endl;
RsGenExchange::publishGroup(token, groupItem);
@ -193,11 +197,11 @@ bool p3Wire::createPulse(uint32_t &token, RsWirePulse &pulse)
std::cerr << "p3Wire::createPulse(): " << pulse;
std::cerr << std::endl;
RsGxsWirePulseItem* pulseItem = new RsGxsWirePulseItem();
pulseItem->pulse = pulse;
pulseItem->meta = pulse.mMeta;
RsGxsWirePulseItem* pulseItem = new RsGxsWirePulseItem();
pulseItem->pulse = pulse;
pulseItem->meta = pulse.mMeta;
RsGenExchange::publishMsg(token, pulseItem);
RsGenExchange::publishMsg(token, pulseItem);
return true;
}

View file

@ -3,7 +3,7 @@
* *
* libretroshare: retroshare core library *
* *
* Copyright 2012-2012 by Robert Fernie <retroshare@lunamutt.com> *
* Copyright 2012-2020 by Robert Fernie <retroshare@lunamutt.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -34,37 +34,33 @@
*
*/
class p3Wire: public RsGenExchange, public RsWire
{
public:
p3Wire(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs *gixs);
virtual RsServiceInfo getServiceInfo();
static uint32_t wireAuthenPolicy();
p3Wire(RsGeneralDataService* gds, RsNetworkExchangeService* nes, RsGixs *gixs);
virtual RsServiceInfo getServiceInfo();
static uint32_t wireAuthenPolicy();
protected:
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) ;
virtual void notifyChanges(std::vector<RsGxsNotify*>& changes) ;
public:
virtual void service_tick();
virtual void service_tick();
virtual RsTokenService* getTokenService();
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, std::vector<RsWireGroup> &groups);
virtual bool getPulseData(const uint32_t &token, std::vector<RsWirePulse> &pulses);
/* Specific Service Data */
virtual bool getGroupData(const uint32_t &token, std::vector<RsWireGroup> &groups);
virtual bool getPulseData(const uint32_t &token, std::vector<RsWirePulse> &pulses);
virtual bool createGroup(uint32_t &token, RsWireGroup &group);
virtual bool createPulse(uint32_t &token, RsWirePulse &pulse);
virtual bool createGroup(uint32_t &token, RsWireGroup &group);
virtual bool createPulse(uint32_t &token, RsWirePulse &pulse);
private:
virtual void generateDummyData();
std::string genRandomId();
private:
virtual void generateDummyData();
std::string genRandomId();
RsMutex mWireMtx;
};
#endif