Instantly share code, notes, and snippets.
Created
August 3, 2015 13:56
-
Save sehraf/3121fd8b8a5e38e9072f to your computer and use it in GitHub Desktop.
this patch allows tor proxy/tor hidden service to run on a different machine than the rs hidden node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: libretroshare/src/pqi/p3linkmgr.cc | |
=================================================================== | |
--- libretroshare/src/pqi/p3linkmgr.cc (Revision 8611) | |
+++ libretroshare/src/pqi/p3linkmgr.cc (Arbeitskopie) | |
@@ -1797,7 +1797,12 @@ | |
std::cerr << std::endl; | |
#endif | |
- if (sockaddr_storage_samenet(mLocalAddress, addr)) | |
+ struct sockaddr_storage localHost; | |
+ struct sockaddr_in *localHostv4p = (struct sockaddr_in *) &localHost; | |
+ localHostv4p->sin_family = AF_INET; | |
+ localHostv4p->sin_addr.s_addr = inet_addr("127.0.0.1"); | |
+ | |
+ if (sockaddr_storage_samenet(mLocalAddress, addr) || sockaddr_storage_sameip(addr, localHost)) | |
{ | |
#ifdef LINKMGR_DEBUG | |
std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialAddr() ACCEPTING - PRIVATE & sameNET"; | |
@@ -1816,7 +1821,86 @@ | |
} | |
+bool p3LinkMgrIMPL::locked_CheckPotentialProxyAddr(const struct sockaddr_storage &addr) | |
+{ | |
+#ifdef LINKMGR_DEBUG | |
+ std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialProxyAddr("; | |
+ std::cerr << sockaddr_storage_tostring(addr); | |
+ std::cerr << ", " << age << ")"; | |
+ std::cerr << std::endl; | |
+#endif | |
+ bool isValid = sockaddr_storage_isValidNet(addr); | |
+ bool isLoopback = sockaddr_storage_isLoopbackNet(addr); | |
+ bool isPrivate = sockaddr_storage_isPrivateNet(addr); | |
+ bool isExternal = sockaddr_storage_isExternalNet(addr); | |
+ | |
+ /* if invalid - quick rejection */ | |
+ if (!isValid) | |
+ { | |
+#ifdef LINKMGR_DEBUG | |
+ std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialProxyAddr() REJECTING - INVALID"; | |
+ std::cerr << std::endl; | |
+#endif | |
+ return false; | |
+ } | |
+ | |
+ /* if it is an external address, we'll reject it. | |
+ */ | |
+ if (isExternal) | |
+ { | |
+#ifdef LINKMGR_DEBUG | |
+ std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialProxyAddr() REJECTING - EXTERNAL"; | |
+ std::cerr << std::endl; | |
+#endif | |
+ return false; | |
+ } | |
+ | |
+ | |
+ /* if loopback, then okay - probably proxy connection (or local testing). | |
+ */ | |
+ if (isLoopback) | |
+ { | |
+#ifdef LINKMGR_DEBUG | |
+ std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialProxyAddr() ACCEPTING - LOOPBACK"; | |
+ std::cerr << std::endl; | |
+#endif | |
+ return true; | |
+ } | |
+ | |
+ | |
+ /* get here, it is private | |
+ * - can only connect to these addresses if we are on the same subnet or loopback. | |
+ - check net against our local address. | |
+ */ | |
+ | |
+#ifdef LINKMGR_DEBUG | |
+ std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialProxyAddr() Checking if PRIVATE and 127.0.0.1 = "; | |
+ std::cerr << sockaddr_storage_iptostring(mLocalAddress); | |
+ std::cerr << ")"; | |
+ std::cerr << std::endl; | |
+#endif | |
+ | |
+ if (isPrivate && sockaddr_storage_isLoopbackNet(mLocalAddress)) | |
+ { | |
+#ifdef LINKMGR_DEBUG | |
+ std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialProxyAddr() ACCEPTING - PRIVATE & isLoopbackNet(mLocalAddress)"; | |
+ std::cerr << std::endl; | |
+#endif | |
+ return true; | |
+ } | |
+ | |
+#ifdef LINKMGR_DEBUG | |
+ std::cerr << "p3LinkMgrIMPL::locked_CheckPotentialProxyAddr() REJECTING - PRIVATE & !isLoopbackNet(mLocalAddress)"; | |
+ std::cerr << std::endl; | |
+#endif | |
+ | |
+ /* else it fails */ | |
+ return false; | |
+ | |
+} | |
+ | |
+ | |
void p3LinkMgrIMPL::locked_ConnectAttempt_SpecificAddress(peerConnectState *peer, const struct sockaddr_storage &remoteAddr) | |
{ | |
#ifdef LINKMGR_DEBUG | |
@@ -2041,7 +2125,7 @@ | |
pca.domain_port = domain_port; | |
/* check address validity */ | |
- if (locked_CheckPotentialAddr(pca.addr, 0)) | |
+ if (locked_CheckPotentialProxyAddr(pca.addr)) | |
{ | |
addAddressIfUnique(peer->connAddrs, pca, true); | |
} | |
Index: libretroshare/src/pqi/p3linkmgr.h | |
=================================================================== | |
--- libretroshare/src/pqi/p3linkmgr.h (Revision 8611) | |
+++ libretroshare/src/pqi/p3linkmgr.h (Arbeitskopie) | |
@@ -307,6 +307,7 @@ | |
bool locked_ConnectAttempt_Complete(peerConnectState *peer); | |
bool locked_CheckPotentialAddr(const struct sockaddr_storage &addr, time_t age); | |
+bool locked_CheckPotentialProxyAddr(const struct sockaddr_storage &addr); | |
bool addAddressIfUnique(std::list<peerConnectAddress> &addrList, peerConnectAddress &pca, bool pushFront); | |
Index: libretroshare/src/pqi/pqissllistener.cc | |
=================================================================== | |
--- libretroshare/src/pqi/pqissllistener.cc (Revision 8611) | |
+++ libretroshare/src/pqi/pqissllistener.cc (Arbeitskopie) | |
@@ -192,7 +192,7 @@ | |
#ifdef OPEN_UNIVERSAL_PORT | |
struct sockaddr_storage tmpaddr = laddr; | |
- if (!mPeerMgr->isHidden()) sockaddr_storage_zeroip(tmpaddr); | |
+ sockaddr_storage_zeroip(tmpaddr); | |
if (0 != (err = universal_bind(lsock, (struct sockaddr *) &tmpaddr, sizeof(tmpaddr)))) | |
#else | |
if (0 != (err = universal_bind(lsock, (struct sockaddr *) &laddr, sizeof(laddr)))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment