fixed bug due to passing shared_ptr to RsThread::async() without making an explicit copy before

This commit is contained in:
csoler 2020-11-08 18:25:20 +01:00
commit d2bd947252
31 changed files with 632 additions and 443 deletions

View file

@ -416,7 +416,7 @@ bool p3HistoryMgr::loadList(std::list<RsItem*>& load)
}
// have to convert to virtual peer id, to be able to use existing serialiser and file format
bool p3HistoryMgr::chatIdToVirtualPeerId(ChatId chat_id, RsPeerId &peer_id)
bool p3HistoryMgr::chatIdToVirtualPeerId(const ChatId& chat_id, RsPeerId &peer_id)
{
if (chat_id.isBroadcast()) {
peer_id = RsPeerId();

View file

@ -68,9 +68,9 @@ public:
virtual void saveDone();
virtual bool loadList(std::list<RsItem*>& load);
private:
static bool chatIdToVirtualPeerId(ChatId chat_id, RsPeerId& peer_id);
static bool chatIdToVirtualPeerId(const ChatId& chat_id, RsPeerId& peer_id);
private:
uint32_t nextMsgId;
std::map<RsPeerId, std::map<uint32_t, RsHistoryMsgItem*> > mMessages;

View file

@ -1876,7 +1876,9 @@ bool p3PeerMgrIMPL::getExtAddressReportedByFriends(sockaddr_storage &addr, uint8
static bool cleanIpList(std::list<pqiIpAddress>& lst,const RsPeerId& pid,p3LinkMgr *link_mgr)
{
bool changed = false ;
#ifdef PEER_DEBUG
rstime_t now = time(NULL) ;
#endif
for(std::list<pqiIpAddress>::iterator it2(lst.begin());it2 != lst.end();)
{

View file

@ -70,15 +70,17 @@ public:
class RsHistory
{
public:
virtual bool getMessages(const ChatId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount) = 0;
virtual bool chatIdToVirtualPeerId(const ChatId &chat_id, RsPeerId &peer_id) = 0;
virtual bool getMessages(const ChatId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount) = 0;
virtual bool getMessage(uint32_t msgId, HistoryMsg &msg) = 0;
virtual void removeMessages(const std::list<uint32_t> &msgIds) = 0;
virtual void clear(const ChatId &chatPeerId) = 0;
virtual void clear(const ChatId &chatPeerId) = 0;
virtual bool getEnable(uint32_t chat_type) = 0;
virtual void setEnable(uint32_t chat_type, bool enable) = 0;
virtual uint32_t getMaxStorageDuration() = 0 ;
virtual void setMaxStorageDuration(uint32_t seconds) = 0 ;
virtual uint32_t getMaxStorageDuration() = 0;
virtual void setMaxStorageDuration(uint32_t seconds) = 0;
// 0 = no limit, >0 count of saved messages
virtual uint32_t getSaveCount(uint32_t chat_type) = 0;

View file

@ -6,7 +6,7 @@
* Copyright (c) 2004-2009 Marcelo Roberto Jimenez ( phoenix@amule.org ) *
* Copyright (c) 2006-2009 aMule Team ( admin@amule.org / http://www.amule.org)*
* Copyright (c) 2009-2010 Retroshare Team *
* Copyright (C) 2019 Gioacchino Mazzurco <gio@eigenlab.org> *
* Copyright (C) 2019-2020 Gioacchino Mazzurco <gio@eigenlab.org> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -35,6 +35,7 @@
#include "util/rsstring.h"
#include "rs_upnp/upnp18_retrocompat.h"
#include "util/rstime.h"
#include "util/rsdebug.h"
#ifdef __GNUC__
#if __GNUC__ >= 4
@ -923,16 +924,18 @@ m_WanService(NULL)
#endif
// Pointer to self
s_CtrlPoint = this;
// Start UPnP
int ret;
char *ipAddress = NULL;
unsigned short port = 0;
#ifdef UPNP_DEBUG
int resLog = UpnpInitLog();
std::cerr << "UPnPControlPoint::CUPnPControlPoint() Init log : " << resLog << std::endl;
#endif
ret = UpnpInit(ipAddress, udpPort);
#if UPNP_VERSION < 11400
int ret = UpnpInit(nullptr, udpPort);
#else
int ret = UpnpInit2(nullptr, udpPort);
#endif
#ifdef UPNP_DEBUG
std::cerr << "CUPnPControlPoint Constructor UpnpInit finished" << std::endl;
#endif
@ -942,15 +945,8 @@ m_WanService(NULL)
#endif
goto error;
}
port = UpnpGetServerPort();
ipAddress = UpnpGetServerIpAddress();
#ifdef UPNP_DEBUG
std::cerr << "UPnPControlPoint::CUPnPControlPoint() bound to " << ipAddress << ":" <<
port << "." << std::endl;
#else
// unused variable
(void)port;
#endif
RS_INFO("bound to ", UpnpGetServerIpAddress(), ":", UpnpGetServerPort());
ret = UpnpRegisterClient(
reinterpret_cast<Upnp_FunPtr>(&CUPnPControlPoint::Callback),
@ -1022,7 +1018,6 @@ error:
#ifdef UPNP_DEBUG
std::cerr << "UPnPControlPoint::CUPnPControlPoint() UpnpFinish called within CUPnPControlPoint constructor." << std::endl;
#endif
return;
}

View file

@ -31,6 +31,11 @@ p3History::~p3History()
{
}
bool p3History::chatIdToVirtualPeerId(const ChatId &chat_id, RsPeerId &peer_id)
{
return mHistoryMgr->chatIdToVirtualPeerId(chat_id, peer_id);
}
void p3History::setMaxStorageDuration(uint32_t seconds)
{
mHistoryMgr->setMaxStorageDuration(seconds) ;

View file

@ -37,16 +37,21 @@ public:
p3History(p3HistoryMgr* historyMgr);
virtual ~p3History();
virtual bool getMessages(const ChatId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount);
virtual bool chatIdToVirtualPeerId(const ChatId &chat_id, RsPeerId &peer_id);
virtual bool getMessages(const ChatId &chatPeerId, std::list<HistoryMsg> &msgs, uint32_t loadCount);
virtual bool getMessage(uint32_t msgId, HistoryMsg &msg);
virtual void removeMessages(const std::list<uint32_t> &msgIds);
virtual void clear(const ChatId &chatPeerId);
virtual void clear(const ChatId &chatPeerId);
virtual bool getEnable(uint32_t chat_type);
virtual void setEnable(uint32_t chat_type, bool enable);
virtual uint32_t getMaxStorageDuration();
virtual void setMaxStorageDuration(uint32_t seconds);
// 0 = no limit, >0 count of saved messages
virtual uint32_t getSaveCount(uint32_t chat_type);
virtual void setSaveCount(uint32_t chat_type, uint32_t count);
virtual void setMaxStorageDuration(uint32_t seconds) ;
virtual uint32_t getMaxStorageDuration() ;
virtual void setSaveCount(uint32_t chat_type, uint32_t count);
private:
p3HistoryMgr* mHistoryMgr;