diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index 5a6ee6afd..af097a33a 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -2236,6 +2236,7 @@ int RsServer::StartupRetroShare() ftserver->connectToTurtleRouter(tr) ; chatSrv->connectToTurtleRouter(tr) ; + msgSrv->connectToTurtleRouter(tr) ; pqih -> addService(ad); pqih -> addService(msgSrv); diff --git a/libretroshare/src/serialiser/rsmsgitems.h b/libretroshare/src/serialiser/rsmsgitems.h index 36dd6a9bd..5e4227fe2 100644 --- a/libretroshare/src/serialiser/rsmsgitems.h +++ b/libretroshare/src/serialiser/rsmsgitems.h @@ -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_RETURN_RECEPT = 0x2000; const uint32_t RS_MSG_FLAGS_ENCRYPTED = 0x4000; +const uint32_t RS_MSG_FLAGS_DISTANT = 0x8000; class RsMsgItem: public RsItem { diff --git a/libretroshare/src/services/p3msgservice.cc b/libretroshare/src/services/p3msgservice.cc index 5b68c804c..a6337c9fd 100644 --- a/libretroshare/src/services/p3msgservice.cc +++ b/libretroshare/src/services/p3msgservice.cc @@ -25,6 +25,7 @@ #include "retroshare/rsiface.h" +#include "retroshare/rspeers.h" #include "pqi/pqibin.h" #include "pqi/pqiarchive.h" @@ -64,7 +65,8 @@ p3MsgService::p3MsgService(p3LinkMgr *lm) :p3Service(RS_SERVICE_TYPE_MSG), p3Config(CONFIG_TYPE_MSGS), mLinkMgr(lm), mMsgMtx("p3MsgService"), mMsgUniqueId(time(NULL)) { - addSerialType(new RsMsgSerialiser()); + _serialiser = new RsMsgSerialiser(); + addSerialType(_serialiser); /* Initialize standard tag types */ if(lm) @@ -275,6 +277,7 @@ int p3MsgService::checkOutgoingMessages() */ bool changed = false ; + std::list output_queue ; { const std::string ownId = mLinkMgr->getOwnId(); @@ -292,18 +295,8 @@ int p3MsgService::checkOutgoingMessages() /* find the certificate */ std::string pid = mit->second->PeerId(); - bool toSend = false; - if(mit->second.msgFlags & RS_MSG_FLAGS_DISTANT || mLinkMgr->isOnline(pid)) - { - toSend = true; - } - else if (pid == ownId) /* FEEDBACK Msg to Ourselves */ - { - toSend = true; - } - - if (toSend) + if(mit->second->msgFlags & RS_MSG_FLAGS_DISTANT || mLinkMgr->isOnline(pid) || pid == ownId) /* FEEDBACK Msg to Ourselves */ { /* send msg */ pqioutput(PQL_DEBUG_BASIC, msgservicezone, @@ -311,7 +304,7 @@ int p3MsgService::checkOutgoingMessages() /* remove the pending flag */ (mit->second)->msgFlags &= ~RS_MSG_FLAGS_PENDING; - checkSizeAndSendMessage(mit->second) ; + output_queue.push_back(mit->second) ; toErase.push_back(mit->first); changed = true ; @@ -345,6 +338,9 @@ int p3MsgService::checkOutgoingMessages() } } + for(std::list::const_iterator it(output_queue.begin());it!=output_queue.end();++it) + checkSizeAndSendMessage(*it) ; + if(changed) rsicontrol->getNotify().notifyListChange(NOTIFY_LIST_MESSAGELIST,NOTIFY_TYPE_MOD); @@ -1633,9 +1629,14 @@ bool p3MsgService::getDistantOfflineMessengingInvites(std::vector::const_iterator it = _messenging_invites.find(hash) ; + if(it != _messenging_invites.end()) + std::cerr << "Responding OK!" << std::endl; + return it != _messenging_invites.end() ; } @@ -1651,8 +1652,12 @@ void p3MsgService::manageDistantPeers() RsStackMutex stack(mMsgMtx); /********** STACK LOCKED MTX ******/ for(std::map::iterator it(_messenging_contacts.begin());it!=_messenging_contacts.end();++it) if(it->second.status == RS_DISTANT_MSG_STATUS_TUNNEL_OK) + { for(uint32_t i=0;isecond.pending_messages.size();++i) to_send.push_back(std::pair(it->first,it->second.pending_messages[i])) ; + + it->second.pending_messages.clear() ; + } } for(uint32_t i=0;i