first working version of distant messages. Still needs some smoothing.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-GenericTunneling@6348 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-05-01 21:13:40 +00:00
parent 34e6fb6fa2
commit 7708e6cd93
4 changed files with 21 additions and 14 deletions

View File

@ -2236,6 +2236,7 @@ int RsServer::StartupRetroShare()
ftserver->connectToTurtleRouter(tr) ; ftserver->connectToTurtleRouter(tr) ;
chatSrv->connectToTurtleRouter(tr) ; chatSrv->connectToTurtleRouter(tr) ;
msgSrv->connectToTurtleRouter(tr) ;
pqih -> addService(ad); pqih -> addService(ad);
pqih -> addService(msgSrv); pqih -> addService(msgSrv);

View File

@ -408,6 +408,7 @@ const uint32_t RS_MSG_FLAGS_FRIEND_RECOMMENDATION = 0x1000;
const uint32_t RS_MSG_FLAGS_SYSTEM = RS_MSG_FLAGS_USER_REQUEST | RS_MSG_FLAGS_FRIEND_RECOMMENDATION; const uint32_t RS_MSG_FLAGS_SYSTEM = RS_MSG_FLAGS_USER_REQUEST | RS_MSG_FLAGS_FRIEND_RECOMMENDATION;
const uint32_t RS_MSG_FLAGS_RETURN_RECEPT = 0x2000; const uint32_t RS_MSG_FLAGS_RETURN_RECEPT = 0x2000;
const uint32_t RS_MSG_FLAGS_ENCRYPTED = 0x4000; const uint32_t RS_MSG_FLAGS_ENCRYPTED = 0x4000;
const uint32_t RS_MSG_FLAGS_DISTANT = 0x8000;
class RsMsgItem: public RsItem class RsMsgItem: public RsItem
{ {

View File

@ -25,6 +25,7 @@
#include "retroshare/rsiface.h" #include "retroshare/rsiface.h"
#include "retroshare/rspeers.h"
#include "pqi/pqibin.h" #include "pqi/pqibin.h"
#include "pqi/pqiarchive.h" #include "pqi/pqiarchive.h"
@ -64,7 +65,8 @@ p3MsgService::p3MsgService(p3LinkMgr *lm)
:p3Service(RS_SERVICE_TYPE_MSG), p3Config(CONFIG_TYPE_MSGS), :p3Service(RS_SERVICE_TYPE_MSG), p3Config(CONFIG_TYPE_MSGS),
mLinkMgr(lm), mMsgMtx("p3MsgService"), mMsgUniqueId(time(NULL)) mLinkMgr(lm), mMsgMtx("p3MsgService"), mMsgUniqueId(time(NULL))
{ {
addSerialType(new RsMsgSerialiser()); _serialiser = new RsMsgSerialiser();
addSerialType(_serialiser);
/* Initialize standard tag types */ /* Initialize standard tag types */
if(lm) if(lm)
@ -275,6 +277,7 @@ int p3MsgService::checkOutgoingMessages()
*/ */
bool changed = false ; bool changed = false ;
std::list<RsMsgItem*> output_queue ;
{ {
const std::string ownId = mLinkMgr->getOwnId(); const std::string ownId = mLinkMgr->getOwnId();
@ -292,18 +295,8 @@ int p3MsgService::checkOutgoingMessages()
/* find the certificate */ /* find the certificate */
std::string pid = mit->second->PeerId(); std::string pid = mit->second->PeerId();
bool toSend = false;
if(mit->second.msgFlags & RS_MSG_FLAGS_DISTANT || mLinkMgr->isOnline(pid)) if(mit->second->msgFlags & RS_MSG_FLAGS_DISTANT || mLinkMgr->isOnline(pid) || pid == ownId) /* FEEDBACK Msg to Ourselves */
{
toSend = true;
}
else if (pid == ownId) /* FEEDBACK Msg to Ourselves */
{
toSend = true;
}
if (toSend)
{ {
/* send msg */ /* send msg */
pqioutput(PQL_DEBUG_BASIC, msgservicezone, pqioutput(PQL_DEBUG_BASIC, msgservicezone,
@ -311,7 +304,7 @@ int p3MsgService::checkOutgoingMessages()
/* remove the pending flag */ /* remove the pending flag */
(mit->second)->msgFlags &= ~RS_MSG_FLAGS_PENDING; (mit->second)->msgFlags &= ~RS_MSG_FLAGS_PENDING;
checkSizeAndSendMessage(mit->second) ; output_queue.push_back(mit->second) ;
toErase.push_back(mit->first); toErase.push_back(mit->first);
changed = true ; changed = true ;
@ -345,6 +338,9 @@ int p3MsgService::checkOutgoingMessages()
} }
} }
for(std::list<RsMsgItem*>::const_iterator it(output_queue.begin());it!=output_queue.end();++it)
checkSizeAndSendMessage(*it) ;
if(changed) if(changed)
rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD); rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD);
@ -1633,9 +1629,14 @@ bool p3MsgService::getDistantOfflineMessengingInvites(std::vector<DistantOffline
} }
bool p3MsgService::handleTunnelRequest(const std::string& hash,const std::string& peer_id) bool p3MsgService::handleTunnelRequest(const std::string& hash,const std::string& peer_id)
{ {
std::cerr << "p3MsgService::handleTunnelRequest: received TR for hash " << hash << std::endl;
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
std::map<std::string,DistantMessengingInvite>::const_iterator it = _messenging_invites.find(hash) ; std::map<std::string,DistantMessengingInvite>::const_iterator it = _messenging_invites.find(hash) ;
if(it != _messenging_invites.end())
std::cerr << "Responding OK!" << std::endl;
return it != _messenging_invites.end() ; return it != _messenging_invites.end() ;
} }
@ -1651,8 +1652,12 @@ void p3MsgService::manageDistantPeers()
RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/
for(std::map<std::string,DistantMessengingContact>::iterator it(_messenging_contacts.begin());it!=_messenging_contacts.end();++it) for(std::map<std::string,DistantMessengingContact>::iterator it(_messenging_contacts.begin());it!=_messenging_contacts.end();++it)
if(it->second.status == RS_DISTANT_MSG_STATUS_TUNNEL_OK) if(it->second.status == RS_DISTANT_MSG_STATUS_TUNNEL_OK)
{
for(uint32_t i=0;i<it->second.pending_messages.size();++i) for(uint32_t i=0;i<it->second.pending_messages.size();++i)
to_send.push_back(std::pair<std::string,RsMsgItem*>(it->first,it->second.pending_messages[i])) ; to_send.push_back(std::pair<std::string,RsMsgItem*>(it->first,it->second.pending_messages[i])) ;
it->second.pending_messages.clear() ;
}
} }
for(uint32_t i=0;i<to_send.size();++i) for(uint32_t i=0;i<to_send.size();++i)

View File

@ -1235,7 +1235,7 @@ bool MessageComposer::sendMessage_internal(bool bDraftbox)
} }
} }
} else { } else {
if (std::find(peers.begin(), peers.end(), id) == peers.end()) { if (_distant_peers.find(id)==_distant_peers.end() && std::find(peers.begin(), peers.end(), id) == peers.end()) {
// no friend // no friend
continue; continue;
} }