Browse Source

de-nested one if block

pull/768/head
Logan oos Even 3 years ago
committed by GitHub
parent
commit
c5eb756840
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 75
      src/n2n.c

75
src/n2n.c

@ -428,47 +428,48 @@ uint8_t resolve_check (n2n_resolve_parameter_t *param, uint8_t requires_resoluti
uint8_t ret = requires_resolution; /* if trylock fails, it still requires resolution */
#ifdef HAVE_PTHREAD
if(param != NULL) {
n2n_resolve_ip_sock_t *entry, *tmp_entry;
n2n_sock_str_t sock_buf;
// check_interval and last_check do not need to be guarded by the mutex because
// their values get changed and evaluated only here
if((now - param->last_checked > param->check_interval) || (requires_resolution)) {
// try to lock access
if(pthread_mutex_trylock(&param->access) == 0) {
// any changes?
if(param->changed) {
// reset flag
param->changed = 0;
// unselectively copy all socks (even those with error code, that would be the old one because
// sockets do not get overwritten in case of error in resolve_thread) from list to supernode list
HASH_ITER(hh, param->list, entry, tmp_entry) {
memcpy(entry->org_sock, &entry->sock, sizeof(n2n_sock_t));
traceEvent(TRACE_INFO, "resolve_check renews ip address of supernode '%s' to %s",
entry->org_ip, sock_to_cstr(sock_buf, &(entry->sock)));
}
}
n2n_resolve_ip_sock_t *entry, *tmp_entry;
n2n_sock_str_t sock_buf;
if(NULL == param)
return ret;
// check_interval and last_check do not need to be guarded by the mutex because
// their values get changed and evaluated only here
if((now - param->last_checked > param->check_interval) || (requires_resolution)) {
// try to lock access
if(pthread_mutex_trylock(&param->access) == 0) {
// any changes?
if(param->changed) {
// reset flag
param->changed = 0;
// unselectively copy all socks (even those with error code, that would be the old one because
// sockets do not get overwritten in case of error in resolve_thread) from list to supernode list
HASH_ITER(hh, param->list, entry, tmp_entry) {
memcpy(entry->org_sock, &entry->sock, sizeof(n2n_sock_t));
traceEvent(TRACE_INFO, "resolve_check renews ip address of supernode '%s' to %s",
entry->org_ip, sock_to_cstr(sock_buf, &(entry->sock)));
}
}
// let the resolver thread know eventual difficulties in reaching the supernode
if(requires_resolution) {
param->request = 1;
ret = 0;
}
// let the resolver thread know eventual difficulties in reaching the supernode
if(requires_resolution) {
param->request = 1;
ret = 0;
}
param->last_checked = now;
param->last_checked = now;
// next appointment
if(param->request)
// earlier if resolver still working on fulfilling a request
param->check_interval = N2N_RESOLVE_CHECK_INTERVAL / 10;
else
param->check_interval = N2N_RESOLVE_CHECK_INTERVAL;
// next appointment
if(param->request)
// earlier if resolver still working on fulfilling a request
param->check_interval = N2N_RESOLVE_CHECK_INTERVAL / 10;
else
param->check_interval = N2N_RESOLVE_CHECK_INTERVAL;
// unlock access
pthread_mutex_unlock(&param->access);
}
// unlock access
pthread_mutex_unlock(&param->access);
}
}
#endif

Loading…
Cancel
Save