* Improvements to Link Cloud Service. You can now vote anonymously on a Link,

this will spread it to your friends anonymously.
 
 * Completed Mutex Locking on Connection Manager.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@551 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-05-13 15:41:40 +00:00
parent ffe371c4e5
commit d48205286a
6 changed files with 124 additions and 124 deletions

View File

@ -245,7 +245,7 @@ void p3ConnectMgr::netStartup()
/* decide which net setup mode we're going into
*/
connMtx.lock(); /* LOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
mNetInitTS = time(NULL);
@ -283,12 +283,6 @@ void p3ConnectMgr::netStartup()
mNetStatus = RS_NET_UPNP_INIT;
break;
}
connMtx.unlock(); /* UNLOCK MUTEX */
/* add Bootstrap Peers ALWAYs (get stuck on the end) */
addBootstrapStunPeers();
}
@ -663,7 +657,8 @@ void p3ConnectMgr::netUnreachableCheck()
#endif
std::map<std::string, peerConnectState>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{
/* get last contact detail */
@ -725,7 +720,6 @@ void p3ConnectMgr::netUnreachableCheck()
}
}
connMtx.unlock(); /* UNLOCK MUTEX */
}
@ -756,9 +750,10 @@ bool p3ConnectMgr::udpExtAddressCheck()
if (0 < tou_extaddr((struct sockaddr *) &addr, &len, &stable))
{
/* update UDP information */
connMtx.lock(); /* LOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* update UDP information */
mStunExtAddr = addr;
mStunAddrValid = true;
mStunAddrStable = (stable != 0);
@ -771,9 +766,6 @@ bool p3ConnectMgr::udpExtAddressCheck()
std::cerr << std::endl;
#endif
connMtx.unlock(); /* UNLOCK MUTEX */
return true;
}
return false;
@ -805,7 +797,7 @@ void p3ConnectMgr::netStunInit()
void p3ConnectMgr::stunInit()
{
connMtx.lock(); /* LOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* push stun list to DHT */
std::list<std::string>::iterator it;
@ -816,8 +808,6 @@ void p3ConnectMgr::stunInit()
mStunStatus = RS_STUN_DHT;
mStunFound = 0;
mStunMoreRequired = true;
connMtx.unlock(); /* UNLOCK MUTEX */
}
bool p3ConnectMgr::stunCheck()
@ -851,12 +841,10 @@ bool p3ConnectMgr::stunCheck()
/* set external UDP address */
mDhtMgr->doneStun();
connMtx.lock(); /* LOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
mStunStatus = RS_STUN_DONE;
connMtx.unlock(); /* UNLOCK MUTEX */
return true;
}
return false;
@ -911,8 +899,7 @@ OTHER
void p3ConnectMgr::stunCollect(std::string id, struct sockaddr_in addr, uint32_t flags)
{
/* if peer is online - move to the top */
connMtx.lock(); /* LOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::stunCollect() id: " << RsUtil::BinToHex(id) << std::endl;
@ -966,7 +953,6 @@ void p3ConnectMgr::stunCollect(std::string id, struct sockaddr_in addr, uint32_t
}
}
connMtx.unlock(); /* UNLOCK MUTEX */
}
/******************************** Network Status *********************************
@ -976,10 +962,8 @@ void p3ConnectMgr::stunCollect(std::string id, struct sockaddr_in addr, uint32_t
void p3ConnectMgr::addMonitor(pqiMonitor *mon)
{
/*
*/
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
std::list<pqiMonitor *>::iterator it;
it = std::find(clients.begin(), clients.end(), mon);
if (it != clients.end())
@ -994,10 +978,8 @@ void p3ConnectMgr::addMonitor(pqiMonitor *mon)
void p3ConnectMgr::removeMonitor(pqiMonitor *mon)
{
/*
*/
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
std::list<pqiMonitor *>::iterator it;
it = std::find(clients.begin(), clients.end(), mon);
if (it == clients.end())
@ -1013,16 +995,18 @@ void p3ConnectMgr::removeMonitor(pqiMonitor *mon)
void p3ConnectMgr::tickMonitors()
{
bool doStatusChange = false;
std::list<pqipeer> actionList;
std::map<std::string, peerConnectState>::iterator it;
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
if (mStatusChanged)
{
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::tickMonitors() StatusChanged! List:" << std::endl;
#endif
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
/* assemble list */
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{
@ -1121,7 +1105,18 @@ void p3ConnectMgr::tickMonitors()
}
}
mStatusChanged = false;
doStatusChange = true;
}
} /****** UNLOCK STACK MUTEX ******/
/* NOTE - clients is accessed without mutex protection!!!!
* At the moment this is okay - as they are only added at the start.
* IF this changes ---- must fix with second Mutex.
*/
if (doStatusChange)
{
#ifdef CONN_DEBUG
std::cerr << "Sending to " << clients.size() << " monitorClients";
std::cerr << std::endl;
@ -1153,25 +1148,23 @@ const std::string p3ConnectMgr::getOwnId()
bool p3ConnectMgr::getOwnNetStatus(peerConnectState &state)
{
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
state = ownState;
return true;
}
bool p3ConnectMgr::isFriend(std::string id)
{
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
return (mFriendList.end() != mFriendList.find(id));
}
bool p3ConnectMgr::getFriendNetStatus(std::string id, peerConnectState &state)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */
std::map<std::string, peerConnectState>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
it = mFriendList.find(id);
if (it == mFriendList.end())
{
@ -1185,10 +1178,10 @@ bool p3ConnectMgr::getFriendNetStatus(std::string id, peerConnectState &state)
bool p3ConnectMgr::getOthersNetStatus(std::string id, peerConnectState &state)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */
std::map<std::string, peerConnectState>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
it = mOthersList.find(id);
if (it == mOthersList.end())
{
@ -1202,10 +1195,10 @@ bool p3ConnectMgr::getOthersNetStatus(std::string id, peerConnectState &state)
void p3ConnectMgr::getOnlineList(std::list<std::string> &peers)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */
std::map<std::string, peerConnectState>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{
if (it->second.state & RS_PEER_S_CONNECTED)
@ -1218,10 +1211,10 @@ void p3ConnectMgr::getOnlineList(std::list<std::string> &peers)
void p3ConnectMgr::getFriendList(std::list<std::string> &peers)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */
std::map<std::string, peerConnectState>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
for(it = mFriendList.begin(); it != mFriendList.end(); it++)
{
peers.push_back(it->first);
@ -1232,10 +1225,10 @@ void p3ConnectMgr::getFriendList(std::list<std::string> &peers)
void p3ConnectMgr::getOthersList(std::list<std::string> &peers)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */
std::map<std::string, peerConnectState>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
for(it = mOthersList.begin(); it != mOthersList.end(); it++)
{
peers.push_back(it->first);
@ -1249,10 +1242,10 @@ bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
uint32_t &delay, uint32_t &period, uint32_t &type)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */
std::map<std::string, peerConnectState>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
it = mFriendList.find(id);
if (it == mFriendList.end())
{
@ -1306,10 +1299,10 @@ bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* check for existing */
std::map<std::string, peerConnectState>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
it = mFriendList.find(id);
if (it == mFriendList.end())
{
@ -1396,6 +1389,22 @@ void p3ConnectMgr::peerStatus(std::string id,
struct sockaddr_in laddr, struct sockaddr_in raddr,
uint32_t type, uint32_t flags, uint32_t source)
{
std::map<std::string, peerConnectState>::iterator it;
bool isFriend = true;
time_t now = time(NULL);
peerAddrInfo details;
details.type = type;
details.found = true;
details.laddr = laddr;
details.raddr = raddr;
details.ts = now;
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
std::cerr << "p3ConnectMgr::peerStatus()";
std::cerr << " id: " << id;
std::cerr << " laddr: " << inet_ntoa(laddr.sin_addr);
@ -1408,10 +1417,6 @@ void p3ConnectMgr::peerStatus(std::string id,
std::cerr << std::endl;
/* look up the id */
std::map<std::string, peerConnectState>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
bool isFriend = true;
it = mFriendList.find(id);
if (it == mFriendList.end())
{
@ -1434,14 +1439,6 @@ void p3ConnectMgr::peerStatus(std::string id,
std::cerr << std::endl;
/* update the status */
time_t now = time(NULL);
peerAddrInfo details;
details.type = type;
details.found = true;
details.laddr = laddr;
details.raddr = raddr;
details.ts = now;
/* if source is DHT */
if (source == RS_CB_DHT)
@ -1693,14 +1690,18 @@ void p3ConnectMgr::peerStatus(std::string id,
#endif // P3CONNMGR_NO_TCP_CONNECTIONS
} /****** STACK UNLOCK MUTEX *******/
/* notify if they say we can, or we cannot connect ! */
if (details.type & RS_NET_CONN_UDP_DHT_SYNC)
{
retryConnectNotify(id);
}
#else
} // P3CONNMGR_NO_AUTO_CONNECTION /****** STACK UNLOCK MUTEX *******/
#endif // P3CONNMGR_NO_AUTO_CONNECTION
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
if (it->second.inConnAttempt)
{
@ -1760,6 +1761,8 @@ void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in radd
/******************** UDP PART *****************************/
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
if (ownState.netMode & RS_NET_MODE_UNREACHABLE)
{
std::cerr << "p3ConnectMgr::peerConnectRequest() Unreachable - no UDP connection";
@ -1769,8 +1772,6 @@ void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in radd
/* look up the id */
std::map<std::string, peerConnectState>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
bool isFriend = true;
it = mFriendList.find(id);
if (it == mFriendList.end())
@ -1864,9 +1865,6 @@ void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in radd
//void p3ConnectMgr::stunStatus(std::string id, struct sockaddr_in addr)
/*******************************************************************/
/*******************************************************************/
@ -1883,7 +1881,7 @@ bool p3ConnectMgr::addFriend(std::string id, uint32_t netMode, uint32_t visState
std::cerr << std::endl;
#endif
connMtx.lock(); /* LOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
std::map<std::string, peerConnectState>::iterator it;
@ -1894,8 +1892,6 @@ bool p3ConnectMgr::addFriend(std::string id, uint32_t netMode, uint32_t visState
std::cerr << std::endl;
#endif
/* (1) already exists */
connMtx.unlock(); /* UNLOCK MUTEX */
return true;
}
@ -1907,8 +1903,6 @@ bool p3ConnectMgr::addFriend(std::string id, uint32_t netMode, uint32_t visState
std::cerr << std::endl;
#endif
/* no auth */
connMtx.unlock(); /* UNLOCK MUTEX */
return false;
}
@ -1948,8 +1942,6 @@ bool p3ConnectMgr::addFriend(std::string id, uint32_t netMode, uint32_t visState
mDhtMgr->findPeer(id);
}
connMtx.unlock(); /* UNLOCK MUTEX */
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
@ -1964,8 +1956,6 @@ bool p3ConnectMgr::addFriend(std::string id, uint32_t netMode, uint32_t visState
std::cerr << std::endl;
#endif
/* ERROR: no details */
connMtx.unlock(); /* UNLOCK MUTEX */
return false;
}
@ -1996,8 +1986,6 @@ bool p3ConnectMgr::addFriend(std::string id, uint32_t netMode, uint32_t visState
/* expect it to be a standard DHT */
mDhtMgr->findPeer(id);
connMtx.unlock(); /* UNLOCK MUTEX */
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return true;
@ -2014,7 +2002,7 @@ bool p3ConnectMgr::removeFriend(std::string id)
mDhtMgr->dropPeer(id);
connMtx.lock(); /* LOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* move to othersList */
bool success = false;
@ -2037,8 +2025,6 @@ bool p3ConnectMgr::removeFriend(std::string id)
success = true;
}
connMtx.unlock(); /* UNLOCK MUTEX */
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
return success;
@ -2060,20 +2046,18 @@ bool p3ConnectMgr::addNeighbour(std::string id)
* (3) is non-existant -> create new one.
*/
connMtx.lock(); /* LOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
std::map<std::string, peerConnectState>::iterator it;
if (mFriendList.end() == mFriendList.find(id))
{
/* (1) already exists */
connMtx.unlock(); /* UNLOCK MUTEX */
return false;
}
if (mOthersList.end() == mOthersList.find(id))
{
/* (2) already exists */
connMtx.unlock(); /* UNLOCK MUTEX */
return true;
}
@ -2081,7 +2065,6 @@ bool p3ConnectMgr::addNeighbour(std::string id)
if (!mAuthMgr->isValid(id))
{
/* no auth */
connMtx.unlock(); /* UNLOCK MUTEX */
return false;
}
@ -2090,7 +2073,6 @@ bool p3ConnectMgr::addNeighbour(std::string id)
if (!mAuthMgr->getDetails(id, detail))
{
/* no details */
connMtx.unlock(); /* UNLOCK MUTEX */
return false;
}
@ -2106,14 +2088,8 @@ bool p3ConnectMgr::addNeighbour(std::string id)
pstate.netMode = RS_NET_MODE_UNKNOWN;
/* addr & timestamps -> auto cleared */
mOthersList[id] = pstate;
// Nothing to notify anyone about... as no new information
//mStatusChanged = true;
connMtx.unlock(); /* UNLOCK MUTEX */
return true;
}
@ -2132,6 +2108,8 @@ bool p3ConnectMgr::retryConnect(std::string id)
bool p3ConnectMgr::retryConnectTCP(std::string id)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* push addresses onto stack */
std::cerr << "p3ConnectMgr::retryConnectTCP()";
std::cerr << " id: " << id;
@ -2139,9 +2117,6 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
/* look up the id */
std::map<std::string, peerConnectState>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
if (mFriendList.end() == (it = mFriendList.find(id)))
{
std::cerr << "p3ConnectMgr::retryConnectTCP() Peer is not Friend";
@ -2300,6 +2275,8 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
bool p3ConnectMgr::retryConnectNotify(std::string id)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* push addresses onto stack */
std::cerr << "p3ConnectMgr::retryConnectNotify()";
std::cerr << " id: " << id;
@ -2307,8 +2284,6 @@ bool p3ConnectMgr::retryConnectNotify(std::string id)
/* look up the id */
std::map<std::string, peerConnectState>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
if (mFriendList.end() == (it = mFriendList.find(id)))
{
@ -2353,8 +2328,8 @@ bool p3ConnectMgr::retryConnectNotify(std::string id)
bool p3ConnectMgr::setLocalAddress(std::string id, struct sockaddr_in addr)
{
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
if (id == mAuthMgr->OwnId())
{
ownState.localaddr = addr;
@ -2381,8 +2356,9 @@ bool p3ConnectMgr::setLocalAddress(std::string id, struct sockaddr_in addr)
bool p3ConnectMgr::setExtAddress(std::string id, struct sockaddr_in addr)
{
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
if (id == mAuthMgr->OwnId())
{
ownState.serveraddr = addr;
@ -2417,6 +2393,8 @@ bool p3ConnectMgr::setNetworkMode(std::string id, uint32_t netMode)
return true;
}
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* check if it is a friend */
std::map<std::string, peerConnectState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id)))
@ -2431,9 +2409,6 @@ bool p3ConnectMgr::setNetworkMode(std::string id, uint32_t netMode)
it->second.netMode = netMode;
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
return false;
}
@ -2447,6 +2422,8 @@ bool p3ConnectMgr::setVisState(std::string id, uint32_t visState)
return true;
}
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
/* check if it is a friend */
std::map<std::string, peerConnectState>::iterator it;
bool isFriend = false;
@ -2480,9 +2457,6 @@ bool p3ConnectMgr::setVisState(std::string id, uint32_t visState)
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
return false;
}
@ -2515,8 +2489,8 @@ bool p3ConnectMgr::checkNetAddress()
std::list<std::string> addrs = getLocalInterfaces();
std::list<std::string>::iterator it;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
bool found = false;
for(it = addrs.begin(); (!found) && (it != addrs.end()); it++)
{
@ -2608,8 +2582,7 @@ std::list<RsItem *> p3ConnectMgr::saveList(bool &cleanup)
std::list<RsItem *> saveData;
cleanup = true;
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
RsPeerNetItem *item = new RsPeerNetItem();
item->clear();
@ -2694,6 +2667,7 @@ bool p3ConnectMgr::loadList(std::list<RsItem *> load)
std::cerr << std::endl;
#endif
/* load the list of peers */
std::list<RsItem *>::iterator it;
for(it = load.begin(); it != load.end(); it++)
@ -2732,6 +2706,7 @@ bool p3ConnectMgr::loadList(std::list<RsItem *> load)
}
else if (sitem)
{
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
#ifdef CONN_DEBUG
std::cerr << "p3ConnectMgr::loadList() Stun Config Item:";
std::cerr << std::endl;
@ -2746,8 +2721,6 @@ bool p3ConnectMgr::loadList(std::list<RsItem *> load)
}
}
connMtx.lock(); /* LOCK MUTEX */
connMtx.unlock(); /* UNLOCK MUTEX */
delete (*it);
}
return true;

View File

@ -89,7 +89,7 @@ virtual bool getRankDetails(std::string rid, RsRankDetails &details) = 0;
virtual std::string newRankMsg(std::wstring link, std::wstring title, std::wstring comment, int32_t score) = 0;
virtual bool updateComment(std::string rid, std::wstring comment, int32_t score) = 0;
virtual std::string anonRankMsg(std::wstring link, std::wstring title) = 0;
virtual std::string anonRankMsg(std::string rid, std::wstring link, std::wstring title) = 0;
};

View File

@ -97,8 +97,8 @@ bool p3Rank::updateComment(std::string rid, std::wstring comment, int32_t score)
return mRank->updateComment(rid, comment, score);
}
std::string p3Rank::anonRankMsg(std::wstring link, std::wstring title)
std::string p3Rank::anonRankMsg(std::string rid, std::wstring link, std::wstring title)
{
return mRank->anonRankMsg(link, title);
return mRank->anonRankMsg(rid, link, title);
}

View File

@ -54,7 +54,7 @@ virtual bool getRankDetails(std::string rid, RsRankDetails &details);
/* Add New Comment / Msg */
virtual std::string newRankMsg(std::wstring link, std::wstring title, std::wstring comment, int32_t score);
virtual bool updateComment(std::string rid, std::wstring comment, int32_t score);
virtual std::string anonRankMsg(std::wstring link, std::wstring title);
virtual std::string anonRankMsg(std::string rid, std::wstring link, std::wstring title);
private:

View File

@ -997,10 +997,16 @@ bool p3Ranking::updateComment(std::string rid, std::wstring comment, int32_t sco
/*************************************************************************/
/****************************** LINK SPECIFIC ****************************/
/*************************************************************************/
std::string p3Ranking::anonRankMsg(std::wstring link, std::wstring title)
std::string p3Ranking::anonRankMsg(std::string rid, std::wstring link, std::wstring title)
{
bool alreadyExists = true;
if (rid == "")
{
alreadyExists = false;
/* generate an id */
std::string rid = generateRandomLinkId();
rid = generateRandomLinkId();
}
RsRankLinkMsg *msg1 = new RsRankLinkMsg();
RsRankLinkMsg *msg2 = new RsRankLinkMsg();
@ -1034,7 +1040,15 @@ std::string p3Ranking::anonRankMsg(std::wstring link, std::wstring title)
msg2->linktype = RS_LINK_TYPE_WEB;
msg2->link = link;
if (alreadyExists)
{
delete msg1;
}
else
{
addRankMsg(msg1);
}
addAnonToList(msg2);
return rid;
@ -1202,6 +1216,19 @@ bool p3Ranking::addAnonToList(RsRankLinkMsg *msg)
{
{
RsStackMutex stack(mRankMtx); /********** STACK LOCKED MTX ******/
std::list<RsRankLinkMsg *>::iterator it;
for(it = mAnon.begin(); it != mAnon.end(); it++)
{
if (msg->rid == (*it)->rid)
break;
}
if (it != mAnon.end())
{
delete msg;
return false;
}
mAnon.push_back(msg);
mRepublishFriends = true;
}

View File

@ -103,7 +103,7 @@ virtual bool getRankDetails(std::string rid, RsRankDetails &details);
/* Add New Comment / Msg */
virtual std::string newRankMsg(std::wstring link, std::wstring title, std::wstring comment, int32_t score);
virtual bool updateComment(std::string rid, std::wstring comment, int32_t score);
virtual std::string anonRankMsg(std::wstring link, std::wstring title);
virtual std::string anonRankMsg(std::string rid, std::wstring link, std::wstring title);
void tick();