don't send details to an unsigned gpg friends

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2330 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
joss17 2010-02-15 15:31:06 +00:00
parent 10906fe047
commit 5d128e77e9

View File

@ -96,16 +96,6 @@ p3disc::p3disc(p3ConnectMgr *cm, pqipersongrp *pqih)
int p3disc::tick() int p3disc::tick()
{ {
#ifdef P3DISC_DEBUG
static int count = 0;
if (++count % 10 == 0)
{
idServers();
}
#endif
//send a heartbeat to all connected peers //send a heartbeat to all connected peers
if (time(NULL) - lastSentHeartbeatTime > HEARTBEAT_REPEAT_TIME) { if (time(NULL) - lastSentHeartbeatTime > HEARTBEAT_REPEAT_TIME) {
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
@ -128,8 +118,7 @@ int p3disc::handleIncoming()
RsItem *item = NULL; RsItem *item = NULL;
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "p3disc::handleIncoming()"; std::cerr << "p3disc::handleIncoming()" << std::endl;
std::cerr << std::endl;
#endif #endif
bool discOn; bool discOn;
@ -140,13 +129,9 @@ int p3disc::handleIncoming()
while(NULL != (item = recvItem())) while(NULL != (item = recvItem()))
{ {
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::ostringstream out; std::cerr << "p3disc::handleIncoming() Deleting - Cos RemoteDisc Off!" << std::endl;
out << "p3disc::handleIncoming()"; item -> print(std::cerr);
out << " Deleting - Cos RemoteDisc Off!" << std::endl; std::cerr << std::endl;
item -> print(out);
std::cerr << out.str() << std::endl;
#endif #endif
delete item; delete item;
@ -164,13 +149,11 @@ int p3disc::handleIncoming()
RsDiscVersion *dvi = NULL; RsDiscVersion *dvi = NULL;
RsDiscHeartbeat *dta = NULL; RsDiscHeartbeat *dta = NULL;
{
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "p3disc::handleIncoming() Received Message!" << std::endl; std::cerr << "p3disc::handleIncoming() Received Message!" << std::endl;
item -> print(std::cerr); item -> print(std::cerr);
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
}
// if discovery reply then respond if haven't already. // if discovery reply then respond if haven't already.
@ -193,6 +176,9 @@ int p3disc::handleIncoming()
} }
delete item; delete item;
} }
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::handleIncoming() finished." << std::endl;
#endif
return nhandled; return nhandled;
} }
@ -202,8 +188,7 @@ int p3disc::handleIncoming()
void p3disc::statusChange(const std::list<pqipeer> &plist) void p3disc::statusChange(const std::list<pqipeer> &plist)
{ {
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "p3disc::statusChange()"; std::cerr << "p3disc::statusChange()" << std::endl;
std::cerr << std::endl;
#endif #endif
std::list<pqipeer>::const_iterator pit; std::list<pqipeer>::const_iterator pit;
@ -219,6 +204,10 @@ void p3disc::statusChange(const std::list<pqipeer> &plist)
this->askInfoToAllPeers(pit->id); this->askInfoToAllPeers(pit->id);
} }
} }
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::statusChange() finished." << std::endl;
#endif
return;
} }
void p3disc::sendAllInfoToJustConnectedPeer(std::string id) void p3disc::sendAllInfoToJustConnectedPeer(std::string id)
@ -226,9 +215,17 @@ void p3disc::sendAllInfoToJustConnectedPeer(std::string id)
/* get a peer lists */ /* get a peer lists */
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() id: " << id; std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() id: " << id << std::endl;
std::cerr << std::endl;
#endif #endif
RsPeerDetails pd;
rsPeers->getPeerDetails(id, pd);
if (!pd.accept_connection || !pd.ownsign) {
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() we're not sending the info because the destination gpg key is not signed or not accepted." << std::cerr << std::endl;
#endif
return;
}
std::list<std::string> friendIds; std::list<std::string> friendIds;
std::list<std::string>::iterator friendIdsIt; std::list<std::string>::iterator friendIdsIt;
@ -258,6 +255,10 @@ void p3disc::sendAllInfoToJustConnectedPeer(std::string id)
for (gpgIdsIt = gpgIds.begin(); gpgIdsIt != gpgIds.end(); gpgIdsIt++) { for (gpgIdsIt = gpgIds.begin(); gpgIdsIt != gpgIds.end(); gpgIdsIt++) {
sendPeerDetails(id, *gpgIdsIt); sendPeerDetails(id, *gpgIdsIt);
} }
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::sendAllInfoToJustConnectedPeer() finished." << std::endl;
#endif
} }
void p3disc::sendJustConnectedPeerInfoToAllPeer(std::string connectedPeerId) void p3disc::sendJustConnectedPeerInfoToAllPeer(std::string connectedPeerId)
@ -281,16 +282,21 @@ void p3disc::sendJustConnectedPeerInfoToAllPeer(std::string connectedPeerId)
/* (dest (to), source (cert)) */ /* (dest (to), source (cert)) */
void p3disc::sendPeerDetails(std::string to, std::string about) { void p3disc::sendPeerDetails(std::string to, std::string about) {
{
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::ostringstream out; std::cerr << "p3disc::sendPeerDetails() called. Sending details of: " << about << " to: " << to << std::endl;
out << "p3disc::sendPeerDetails()";
out << " Sending details of: " << about;
out << " to: " << to << std::endl;
std::cerr << out.str() << std::endl;
#endif #endif
RsPeerDetails pd;
rsPeers->getPeerDetails(to, pd);
if (!pd.accept_connection || !pd.ownsign) {
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::sendPeerDetails() we're not sending the info because the destination gpg key is not signed or not accepted." << std::cerr << std::endl;
#endif
return;
} }
// if off discard item. // if off discard item.
peerConnectState detail; peerConnectState detail;
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) { if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
@ -305,6 +311,14 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
return; return;
} }
peerConnectState detailAbout;
if (mConnMgr->getFriendNetStatus(about, detailAbout) && detailAbout.visState & RS_VIS_STATE_NODISC) {
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::sendPeerDetails() don't send info about this peer because he has no disc enabled." << std::endl;
#endif
return;
}
// Construct a message // Construct a message
RsDiscReply *di = new RsDiscReply(); RsDiscReply *di = new RsDiscReply();
@ -380,20 +394,15 @@ void p3disc::sendPeerDetails(std::string to, std::string about) {
sendItem(di); sendItem(di);
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "Sent DI Message" << std::endl; std::cerr << "p3disc::sendPeerDetails() discovery reply sent." << std::endl;
#endif #endif
} }
void p3disc::sendOwnVersion(std::string to) void p3disc::sendOwnVersion(std::string to)
{
{ {
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::ostringstream out; std::cerr << "p3disc::sendOwnVersion() Sending rs version to: " << to << std::endl;
out << "p3disc::sendOwnVersion()";
out << " Sending rs version to: " << to << std::endl;
std::cerr << out.str() << std::endl;
#endif #endif
}
RsDiscVersion *di = new RsDiscVersion(); RsDiscVersion *di = new RsDiscVersion();
di->PeerId(to); di->PeerId(to);
@ -403,7 +412,7 @@ void p3disc::sendOwnVersion(std::string to)
sendItem(di); sendItem(di);
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "Sent DI Message" << std::endl; std::cerr << "p3disc::sendOwnVersion() finished." << std::endl;
#endif #endif
} }
@ -431,12 +440,18 @@ void p3disc::sendHeartbeat(std::string to)
void p3disc::askInfoToAllPeers(std::string about) void p3disc::askInfoToAllPeers(std::string about)
{ {
{
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::ostringstream out; std::cerr <<"p3disc::askInfoToAllPeers() about " << about << std::endl;
out << "p3disc::askInfoToAllPeers()" << " about " << about;
std::cerr << out.str() << std::endl;
#endif #endif
peerConnectState connectState;
if (!mConnMgr->getFriendNetStatus(about, connectState) || (connectState.visState & RS_VIS_STATE_NODISC)) {
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::askInfoToAllPeers() friend disc is off, don't send the request." << std::endl;
#endif
return;
} }
about = rsPeers->getGPGId(about); about = rsPeers->getGPGId(about);
@ -447,8 +462,7 @@ void p3disc::askInfoToAllPeers(std::string about)
} }
// if off discard item. // if off discard item.
peerConnectState detail; if (!mConnMgr->getOwnNetStatus(connectState) || (connectState.visState & RS_VIS_STATE_NODISC)) {
if (!mConnMgr->getOwnNetStatus(detail) || (detail.visState & RS_VIS_STATE_NODISC)) {
return; return;
} }
@ -457,15 +471,26 @@ void p3disc::askInfoToAllPeers(std::string about)
rsPeers->getOnlineList(onlineIds); rsPeers->getOnlineList(onlineIds);
/* send them a list of all friend's details */ /* ask info to trusted friends */
for(onlineIdsIt = onlineIds.begin(); onlineIdsIt != onlineIds.end(); onlineIdsIt++) { for(onlineIdsIt = onlineIds.begin(); onlineIdsIt != onlineIds.end(); onlineIdsIt++) {
RsPeerDetails details;
rsPeers->getPeerDetails(*onlineIdsIt, details);
if (!details.accept_connection || !details.ownsign) {
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::askInfoToAllPeers() don't ask info message to untrusted peer." << std::endl;
#endif
continue;
}
RsDiscAskInfo *di = new RsDiscAskInfo(); RsDiscAskInfo *di = new RsDiscAskInfo();
di->PeerId(*onlineIdsIt); di->PeerId(*onlineIdsIt);
di->gpg_id = about; di->gpg_id = about;
sendItem(di); sendItem(di);
#ifdef P3DISC_DEBUG
std::cerr << "p3disc::askInfoToAllPeers() question sent to : " << *onlineIdsIt << std::endl;
#endif
} }
#ifdef P3DISC_DEBUG #ifdef P3DISC_DEBUG
std::cerr << "Sent ask info message to all connected peers." << std::endl; std::cerr << "p3disc::askInfoToAllPeers() finished." << std::endl;
#endif #endif
} }