pull/254/merge
amyangfei 2018-08-24 02:07:59 +00:00 committed by GitHub
commit 3dd1aa6a6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 9 deletions

View File

@ -559,7 +559,8 @@ static int chain_step(int ns, proxy_data * pfrom, proxy_data * pto) {
int connect_proxy_chain(int sock, ip_type target_ip,
unsigned short target_port, proxy_data * pd,
unsigned int proxy_count, chain_type ct, unsigned int max_chain) {
unsigned int proxy_count, chain_type ct, unsigned int max_chain,
unsigned int max_retry) {
proxy_data p4;
proxy_data *p1, *p2, *p3;
int ns = -1;
@ -567,9 +568,7 @@ int connect_proxy_chain(int sock, ip_type target_ip,
unsigned int offset = 0;
unsigned int alive_count = 0;
unsigned int curr_len = 0;
unsigned int curr_pos = 0;
unsigned int looped = 0; // went back to start of list in RR mode
int rr_loop_max = 14;
p3 = &p4;
@ -606,17 +605,17 @@ int connect_proxy_chain(int sock, ip_type target_ip,
case ROUND_ROBIN_TYPE:
alive_count = calc_alive(pd, proxy_count);
curr_pos = offset = proxychains_proxy_offset;
offset = proxychains_proxy_offset;
if(alive_count < max_chain)
goto error_more;
PDEBUG("1:rr_offset = %d, curr_pos = %d\n", offset, curr_pos);
PDEBUG("1:rr_offset = %d\n", offset);
/* Check from current RR offset til end */
for (;rc != SUCCESS;) {
if (!(p1 = select_proxy(FIFOLY, pd, proxy_count, &offset))) {
/* We've reached the end of the list, go to the start */
offset = 0;
looped++;
if (looped > rr_loop_max) {
if (looped > max_retry) {
proxychains_proxy_offset = 0;
goto error_more;
} else {

View File

@ -79,7 +79,7 @@ typedef struct {
int connect_proxy_chain (int sock, ip_type target_ip, unsigned short target_port,
proxy_data * pd, unsigned int proxy_count, chain_type ct,
unsigned int max_chain );
unsigned int max_chain, unsigned int max_retry);
void proxychains_write_log(char *str, ...);

View File

@ -73,6 +73,7 @@ int proxychains_resolver = 0;
localaddr_arg localnet_addr[MAX_LOCALNET];
size_t num_localnet_addr = 0;
unsigned int remote_dns_subnet = 224;
unsigned int proxychains_max_retry = 14;
pthread_once_t init_once = PTHREAD_ONCE_INIT;
@ -399,6 +400,16 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
}
len = atoi(++pc);
proxychains_max_chain = (len ? len : 1);
} else if(strstr(buff, "max_retry")) {
char *pc;
int len;
pc = strchr(buff, '=');
if(!pc) {
fprintf(stderr, "error: missing equals sign '=' in max_retry directive.\n");
exit(1);
}
len = atoi(++pc);
proxychains_max_retry = (len >= 0 ? len : proxychains_max_retry);
} else if(strstr(buff, "quiet_mode")) {
proxychains_quiet_mode = 1;
} else if(strstr(buff, "proxy_dns")) {
@ -499,7 +510,8 @@ int connect(int sock, const struct sockaddr *addr, unsigned int len) {
ret = connect_proxy_chain(sock,
dest_ip,
htons(port),
proxychains_pd, proxychains_proxy_count, proxychains_ct, proxychains_max_chain);
proxychains_pd, proxychains_proxy_count, proxychains_ct,
proxychains_max_chain, proxychains_max_retry);
fcntl(sock, F_SETFL, flags);
if(ret != SUCCESS)

View File

@ -32,7 +32,7 @@ strict_chain
# the start of the current proxy chain is the proxy after the last
# proxy in the previously invoked proxy chain.
# if the end of the proxy chain is reached while looking for proxies
# start at the beginning again.
# start at the beginning again and retry max_retry times at most.
# otherwise EINTR is returned to the app
# These semantics are not guaranteed in a multithreaded environment.
#
@ -45,6 +45,10 @@ strict_chain
# Make sense only if random_chain or round_robin_chain
#chain_len = 2
# Make sense only if round_robin_chain, should be an unsigned int.
# default value is 14, 0 value means no retry
#max_retry = 14
# Quiet mode (no output from library)
#quiet_mode