[Pkg-privacy-commits] [onioncat] 118/241: SOCKS reconnect speed limited
Intrigeri
intrigeri at moszumanska.debian.org
Wed Aug 26 16:16:47 UTC 2015
This is an automated email from the git hooks/post-receive script.
intrigeri pushed a commit to branch upstream-master
in repository onioncat.
commit 3ad83e1c6a985dcbe7ac96a60f76059e60cd3cbf
Author: eagle <eagle at 58e1ccc2-750e-0410-8d0d-f93ca75ab447>
Date: Sat Jan 17 09:31:18 2009 +0000
SOCKS reconnect speed limited
git-svn-id: https://www.cypherpunk.at/svn/onioncat/trunk@430 58e1ccc2-750e-0410-8d0d-f93ca75ab447
---
src/ocat.h | 4 ++++
src/ocatsocks.c | 17 +++++++++++++++--
2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/src/ocat.h b/src/ocat.h
index a3c44db..00287a4 100644
--- a/src/ocat.h
+++ b/src/ocat.h
@@ -196,6 +196,10 @@
*/
//! retry-delay if connection to TOR's SOCKS port fails
#define TOR_SOCKS_CONN_TIMEOUT 30
+//! number of attempts for MIN_RECONNECT_TIME is measured
+#define RECONN_ATTEMPTS 3
+//! RECONN_ATTEMPTS must not be faster than MIN_RECONNECT_TIME
+#define MIN_RECONNECT_TIME 30
//! copy an IPv6 address from b to a
#define IN6_ADDR_COPY(a,b) *((struct in6_addr*)a)=*(struct in6_addr*)b
diff --git a/src/ocatsocks.c b/src/ocatsocks.c
index b515d46..ca1452a 100644
--- a/src/ocatsocks.c
+++ b/src/ocatsocks.c
@@ -171,7 +171,7 @@ void *socks_connector(void *p)
{
OcatPeer_t *peer;
SocksQueue_t *squeue;
- int i, rc, ps, run = 1;
+ int i, rc, ps, run = 1, t_abs, t_diff;
char thn[THREAD_NAME_LEN] = "cn:", on[ONION_NAME_LEN];
if ((rc = pthread_detach(pthread_self())))
@@ -225,8 +225,21 @@ void *socks_connector(void *p)
// connect via SOCKS if no peer exists
if (!peer)
- for (i = 0, ps = -1; ((i < SOCKS_MAX_RETRY) || squeue->perm) && ps < 0; i++)
+ for (i = 0, ps = -1, t_abs = 0; ((i < SOCKS_MAX_RETRY) || squeue->perm) && ps < 0; i++)
{
+ // every third connection attempt
+ if (!(i % RECONN_ATTEMPTS))
+ {
+ // check that it does not reconnect too fast
+ t_diff = time(NULL) - t_abs;
+ if (t_diff < MIN_RECONNECT_TIME)
+ {
+ // and sleep if necessary
+ log_msg(LOG_WARNING, "reconnecting too fast. sleeping %d seconds", MIN_RECONNECT_TIME - t_diff);
+ sleep(MIN_RECONNECT_TIME - t_diff);
+ }
+ t_abs = time(NULL);
+ }
log_debug("%d. SOCKS connection attempt", i + 1);
ps = socks_connect(squeue);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onioncat.git
More information about the Pkg-privacy-commits
mailing list