From 611db96fb994a38c18522e5372f906cea0311e95 Mon Sep 17 00:00:00 2001 From: drbob Date: Fri, 20 Jan 2012 14:41:45 +0000 Subject: [PATCH] Attempt 3 at fixing disconnections :) * Added limit of 10kB for Certificate size. If it is bigger - discard certificate. * Remove certificates for slow / trickle connections (for Relay connections). git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4822 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/authgpg.cc | 24 +++++++++++++++++++++++- libretroshare/src/services/p3disc.cc | 20 ++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index 524ef89e7..52332eca6 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -434,11 +434,33 @@ void AuthGPGimpl::processServices() #endif /* save the certificate to string */ -#define DISABLE_CERTIFICATE_SEND 1 +/***** + * #define DISABLE_CERTIFICATE_SEND 1 + ****/ + +#define LIMIT_CERTIFICATE_SIZE 1 +#define MAX_CERTIFICATE_SIZE 10000 + #ifdef DISABLE_CERTIFICATE_SEND + std::cerr << "AuthGPGimpl::processServices() Certificates Disabled" << std::endl; loadOrSave->m_certGpg = ""; #else loadOrSave->m_certGpg = SaveCertificateToString(loadOrSave->m_certGpgId,true); + std::cerr << "AuthGPGimpl::processServices() Cert for: " << loadOrSave->m_certGpgId; + std::cerr << " is " << loadOrSave->m_certGpg.size() << " bytes"; + std::cerr << std::endl; + + #ifdef LIMIT_CERTIFICATE_SIZE + if (loadOrSave->m_certGpg.size() > MAX_CERTIFICATE_SIZE) + { + std::cerr << "AuthGPGimpl::processServices() Cert for: " << loadOrSave->m_certGpgId; + std::cerr << " is over size limit - removing"; + std::cerr << std::endl; + + loadOrSave->m_certGpg = ""; + } + #endif + #endif } diff --git a/libretroshare/src/services/p3disc.cc b/libretroshare/src/services/p3disc.cc index b9bf0bc98..ed67ce30f 100644 --- a/libretroshare/src/services/p3disc.cc +++ b/libretroshare/src/services/p3disc.cc @@ -975,14 +975,30 @@ void p3disc::setGPGOperation(AuthGPGOperation *operation) } #endif - // Send off message - item->certGPG = loadOrSave->m_certGpg; + /* for Relay Connections (and other slow ones) we don't want to + * to waste bandwidth sending certificates. So don't add it. + */ + + uint32_t linkType = mLinkMgr->getLinkType(item->PeerId()); + if ((linkType & RS_NET_CONN_SPEED_TRICKLE) || + (linkType & RS_NET_CONN_SPEED_LOW)) + { + std::cerr << "p3disc::setGPGOperation() Send DiscReply Packet to: "; + std::cerr << item->PeerId(); + std::cerr << " without Certificate (low bandwidth)" << std::endl; + } + else + { + // Attaching Certificate. + item->certGPG = loadOrSave->m_certGpg; + } #ifdef P3DISC_DEBUG std::cerr << "p3disc::setGPGOperation() About to Send Message:" << std::endl; item->print(std::cerr, 5); #endif + // Send off message sendItem(item); #ifdef P3DISC_DEBUG