NETWORK REWORK (cont)

pqiperson / pqipersongrp: generally okay, One Nasty BUG.

  * removed pqipersongrp::getPeer() fn. Violated Mutex protections!!!!
  * reworked heartbeat code, which used getPeer() fn.
  * switched all notifyConnect() calls to include remote_addr.
  * added explicit stoplistening() call when removing peer.
  * removed funny DO_NEXT_ATTEMPT callback code.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3216 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2010-06-25 22:00:38 +00:00
parent 00d0d999dc
commit 9f4deb1cf7
3 changed files with 44 additions and 49 deletions

View File

@ -81,7 +81,6 @@ int pqiperson::SendItem(RsItem *i)
out << " Now deleting...";
delete i;
}
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
return 0; // queued.
}
@ -173,7 +172,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
}
/* find the pqi, */
pqiconnect *pqi = NULL;
pqiconnect *pqi = NULL;
uint32_t type = 0;
std::map<uint32_t, pqiconnect *>::iterator it;
@ -184,16 +183,16 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
std::ostringstream out;
out << "pqiperson::connectattempt() Kid# ";
out << i << " of " << kids.size();
out << std::endl;
out << " type: " << (it->first);
out << std::endl;
out << " type: " << (it->first);
out << " ni: " << (it->second)->ni;
out << " in_ni: " << ni;
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
i++;
i++;
if ((it->second)->thisNetInterface(ni))
{
pqi = (it->second);
pqi = (it->second);
type = (it->first);
}
}
@ -203,6 +202,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
pqioutput(PQL_WARNING, pqipersonzone, "Unknown notfyEvent Source!");
return -1;
}
switch(newState)
{
@ -233,11 +233,11 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
pqioutput(PQL_WARNING, pqipersonzone,
"CONNECT_SUCCESS->marking so! (resetting others)");
// mark as active.
// mark as active.
active = true;
lastHeartbeatReceived = 0;
activepqi = pqi;
inConnectAttempt = false;
inConnectAttempt = false;
/* reset all other children? (clear up long UDP attempt) */
for(it = kids.begin(); it != kids.end(); it++)
@ -262,7 +262,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
if (active)
{
if (activepqi->thisNetInterface(ni))
if (activepqi == pqi)
{
pqioutput(PQL_WARNING, pqipersonzone,
"CONNECT_FAILED->marking so!");
@ -280,14 +280,12 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
}
/* notify up (But not if we are actually active: rtn -1 case above) */
if (!active) {
if (pqipg)
pqipg->notifyConnect(PeerId(), type, false);
} else {
if (pqipg)
pqipg->notifyConnect(PeerId(), PQI_CONNECT_DO_NEXT_ATTEMPT, false);
return -1;
}
if (pqipg)
{
struct sockaddr_in raddr;
sockaddr_clear(&raddr);
pqipg->notifyConnect(PeerId(), type, false, raddr);
}
return 1;

View File

@ -290,7 +290,6 @@ void pqipersongrp::statusChange(const std::list<pqipeer> &plist)
if (it->actions & RS_PEER_CONNECT_REQ)
{
connectPeer(it->id);
}
}
@ -366,6 +365,7 @@ int pqipersongrp::removePeer(std::string id)
//RemoveSearchModule(mod);
secpolicy_delete(mod -> sp);
pqiperson *p = (pqiperson *) mod -> pqi;
p -> stoplistening();
p -> reset();
delete p;
mods.erase(it);
@ -373,27 +373,33 @@ int pqipersongrp::removePeer(std::string id)
return 1;
}
pqiperson *pqipersongrp::getPeer(std::string id)
int pqipersongrp::tagHeartbeatRecvd(std::string id)
{
std::map<std::string, SearchModule *>::iterator it;
std::map<std::string, SearchModule *>::iterator it;
#ifdef PGRP_DEBUG
std::cerr << " pqipersongrp::getPeer() id: " << id;
std::cerr << std::endl;
std::cerr << " pqipersongrp::tagHeartbeatRecvd() id: " << id;
std::cerr << std::endl;
#endif
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
it = mods.find(id);
if (it != mods.end())
{
SearchModule *mod = it->second;
pqiperson *p = (pqiperson *) mod -> pqi;
return p;
}
return NULL;
it = mods.find(id);
if (it != mods.end())
{
SearchModule *mod = it->second;
pqiperson *p = (pqiperson *) mod -> pqi;
p->receiveHeartbeat();
return 1;
}
return 0;
}
int pqipersongrp::connectPeer(std::string id)
{
/* get status from p3connectMgr */
@ -489,16 +495,9 @@ int pqipersongrp::connectPeer(std::string id)
return 1;
}
bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success) {
struct sockaddr_in remote_peer_address;
sockaddr_clear(&remote_peer_address);
return notifyConnect(id, ptype, success, remote_peer_address);
}
bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success, struct sockaddr_in remote_peer_address)
bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success, struct sockaddr_in raddr)
{
uint32_t type = 0;
uint32_t type = 0;
if (ptype == PQI_CONNECT_TCP)
{
type = RS_NET_CONN_TCP_ALL;
@ -512,13 +511,9 @@ bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success
type = RS_NET_CONN_TUNNEL;
}
if (mConnMgr) {
if (ptype == PQI_CONNECT_DO_NEXT_ATTEMPT) {
mConnMgr->doNextAttempt(id);
} else {
mConnMgr->connectResult(id, success, type, remote_peer_address);
}
}
if (mConnMgr)
mConnMgr->connectResult(id, success, type, raddr);
return (NULL != mConnMgr);
}

View File

@ -67,13 +67,15 @@ virtual void statusChange(const std::list<pqipeer> &plist);
/******************* Peer Control **************************/
virtual int addPeer(std::string id); /* can be overloaded for testing */
virtual pqiperson *getPeer(std::string id); /* can be overloaded for testing */
int removePeer(std::string id);
int connectPeer(std::string id);
/* Work-around to dodgy pointer stuff */
int tagHeartbeatRecvd(std::string id);
/*** callback from children ****/
bool notifyConnect(std::string id, uint32_t type, bool success, struct sockaddr_in remote_peer_address);
bool notifyConnect(std::string id, uint32_t type, bool success);
//bool notifyConnect(std::string id, uint32_t type, bool success);
// tick interfaces.
virtual int tick();