|
|
@ -1270,57 +1270,70 @@ static void passthrough_add_send(proxy_instance_t *proxi, const char *msg) |
|
|
|
ckmsgq_add(proxi->passsends, pm); |
|
|
|
ckmsgq_add(proxi->passsends, pm); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Cycle through the available proxies and find the first alive one */ |
|
|
|
static bool proxy_alive(ckpool_t *ckp, server_instance_t *si, proxy_instance_t *proxi, |
|
|
|
static proxy_instance_t *live_proxy(ckpool_t *ckp) |
|
|
|
connsock_t *cs, bool pinging) |
|
|
|
{ |
|
|
|
{ |
|
|
|
proxy_instance_t *alive = NULL; |
|
|
|
|
|
|
|
connsock_t *cs; |
|
|
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOGDEBUG("Attempting to connect to proxy"); |
|
|
|
|
|
|
|
retry: |
|
|
|
|
|
|
|
if (!ping_main(ckp)) |
|
|
|
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = ckp->chosen_server; i < ckp->proxies; i++) { |
|
|
|
|
|
|
|
proxy_instance_t *proxi; |
|
|
|
|
|
|
|
server_instance_t *si; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
si = ckp->servers[i]; |
|
|
|
|
|
|
|
proxi = si->data; |
|
|
|
|
|
|
|
cs = proxi->cs; |
|
|
|
|
|
|
|
if (!extract_sockaddr(si->url, &cs->url, &cs->port)) { |
|
|
|
if (!extract_sockaddr(si->url, &cs->url, &cs->port)) { |
|
|
|
LOGWARNING("Failed to extract address from %s", si->url); |
|
|
|
LOGWARNING("Failed to extract address from %s", si->url); |
|
|
|
continue; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!connect_proxy(cs)) { |
|
|
|
if (!connect_proxy(cs)) { |
|
|
|
|
|
|
|
if (!pinging) { |
|
|
|
LOGINFO("Failed to connect to %s:%s in proxy_mode!", |
|
|
|
LOGINFO("Failed to connect to %s:%s in proxy_mode!", |
|
|
|
cs->url, cs->port); |
|
|
|
cs->url, cs->port); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (ckp->passthrough) { |
|
|
|
if (ckp->passthrough) { |
|
|
|
if (!passthrough_stratum(cs, proxi)) { |
|
|
|
if (!passthrough_stratum(cs, proxi)) { |
|
|
|
LOGWARNING("Failed initial passthrough to %s:%s !", |
|
|
|
LOGWARNING("Failed initial passthrough to %s:%s !", |
|
|
|
cs->url, cs->port); |
|
|
|
cs->url, cs->port); |
|
|
|
continue; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
alive = proxi; |
|
|
|
return true; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
/* Test we can connect, authorise and get stratum information */ |
|
|
|
/* Test we can connect, authorise and get stratum information */ |
|
|
|
if (!subscribe_stratum(cs, proxi)) { |
|
|
|
if (!subscribe_stratum(cs, proxi)) { |
|
|
|
|
|
|
|
if (!pinging) { |
|
|
|
LOGINFO("Failed initial subscribe to %s:%s !", |
|
|
|
LOGINFO("Failed initial subscribe to %s:%s !", |
|
|
|
cs->url, cs->port); |
|
|
|
cs->url, cs->port); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!auth_stratum(cs, proxi)) { |
|
|
|
if (!auth_stratum(cs, proxi)) { |
|
|
|
|
|
|
|
if (!pinging) { |
|
|
|
LOGWARNING("Failed initial authorise to %s:%s with %s:%s !", |
|
|
|
LOGWARNING("Failed initial authorise to %s:%s with %s:%s !", |
|
|
|
cs->url, cs->port, si->auth, si->pass); |
|
|
|
cs->url, cs->port, si->auth, si->pass); |
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Cycle through the available proxies and find the first alive one */ |
|
|
|
|
|
|
|
static proxy_instance_t *live_proxy(ckpool_t *ckp) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
proxy_instance_t *alive = NULL; |
|
|
|
|
|
|
|
connsock_t *cs; |
|
|
|
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOGDEBUG("Attempting to connect to proxy"); |
|
|
|
|
|
|
|
retry: |
|
|
|
|
|
|
|
if (!ping_main(ckp)) |
|
|
|
|
|
|
|
goto out; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (i = ckp->chosen_server; i < ckp->proxies; i++) { |
|
|
|
|
|
|
|
proxy_instance_t *proxi; |
|
|
|
|
|
|
|
server_instance_t *si; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
si = ckp->servers[i]; |
|
|
|
|
|
|
|
proxi = si->data; |
|
|
|
|
|
|
|
cs = proxi->cs; |
|
|
|
|
|
|
|
if (proxy_alive(ckp, si, proxi, cs, false)) { |
|
|
|
alive = proxi; |
|
|
|
alive = proxi; |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (!alive) { |
|
|
|
if (!alive) { |
|
|
|
send_proc(ckp->stratifier, "dropall"); |
|
|
|
send_proc(ckp->stratifier, "dropall"); |
|
|
|
send_proc(ckp->connector, "reject"); |
|
|
|
send_proc(ckp->connector, "reject"); |
|
|
|