"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/n2n.c" between
n2n-3.0.tar.gz and n2n-3.1.1.tar.gz

About: n2n is a layer-two peer-to-peer virtual private network (VPN) which allows bypassing intermediate firewalls.
Pre-release.

n2n.c  (n2n-3.0):n2n.c  (n2n-3.1.1)
/** /**
* (C) 2007-21 - ntop.org and contributors * (C) 2007-22 - ntop.org and contributors
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 148 skipping to change at line 148
#ifndef WIN32 #ifndef WIN32
if(useSyslog) { if(useSyslog) {
if(!syslog_opened) { if(!syslog_opened) {
openlog("n2n", LOG_PID, LOG_DAEMON); openlog("n2n", LOG_PID, LOG_DAEMON);
syslog_opened = 1; syslog_opened = 1;
} }
snprintf(out_buf, sizeof(out_buf), "%s%s", extra_msg, buf); snprintf(out_buf, sizeof(out_buf), "%s%s", extra_msg, buf);
syslog(LOG_INFO, "%s", out_buf); syslog(LOG_INFO, "%s", out_buf);
} else { } else {
#endif
for(i = strlen(file) - 1; i > 0; i--) { for(i = strlen(file) - 1; i > 0; i--) {
if(file[i] == '/') { if((file[i] == '/') || (file[i] == '\\')) {
i++; i++;
break; break;
} }
} }
snprintf(out_buf, sizeof(out_buf), "%s [%s:%d] %s%s", theDate, &file [i], line, extra_msg, buf); snprintf(out_buf, sizeof(out_buf), "%s [%s:%d] %s%s", theDate, &file [i], line, extra_msg, buf);
fprintf(traceFile, "%s\n", out_buf); fprintf(traceFile, "%s\n", out_buf);
fflush(traceFile); fflush(traceFile);
#ifndef WIN32
} }
#else
/* this is the WIN32 code */
for(i = strlen(file) - 1; i > 0; i--) {
if(file[i] == '\\') {
i++;
break;
}
}
snprintf(out_buf, sizeof(out_buf), "%s [%s:%d] %s%s", theDate, &file[i],
line, extra_msg, buf);
fprintf(traceFile, "%s\n", out_buf);
fflush(traceFile);
#endif #endif
} }
} }
/* *********************************************** */ /* *********************************************** */
/* addr should be in network order. Things are so much simpler that way. */ /* addr should be in network order. Things are so much simpler that way. */
char* intoa (uint32_t /* host order */ addr, char* buf, uint16_t buf_len) { char* intoa (uint32_t /* host order */ addr, char* buf, uint16_t buf_len) {
skipping to change at line 309 skipping to change at line 300
traceEvent(TRACE_WARNING, "supernode2sock sees malformed supernode param eter (-l <host:port>) %s", traceEvent(TRACE_WARNING, "supernode2sock sees malformed supernode param eter (-l <host:port>) %s",
addrIn); addrIn);
rv = -4; rv = -4;
} }
ainfo = NULL; ainfo = NULL;
return rv; return rv;
} }
#ifdef HAVE_PTHREAD
N2N_THREAD_RETURN_DATATYPE resolve_thread(N2N_THREAD_PARAMETER_DATATYPE p) { N2N_THREAD_RETURN_DATATYPE resolve_thread(N2N_THREAD_PARAMETER_DATATYPE p) {
#ifdef HAVE_PTHREAD
n2n_resolve_parameter_t *param = (n2n_resolve_parameter_t*)p; n2n_resolve_parameter_t *param = (n2n_resolve_parameter_t*)p;
n2n_resolve_ip_sock_t *entry, *tmp_entry; n2n_resolve_ip_sock_t *entry, *tmp_entry;
time_t rep_time = N2N_RESOLVE_INTERVAL / 10; time_t rep_time = N2N_RESOLVE_INTERVAL / 10;
time_t now; time_t now;
while(1) { while(1) {
sleep(N2N_RESOLVE_INTERVAL / 60); /* wake up in-between to check for sig naled requests */ sleep(N2N_RESOLVE_INTERVAL / 60); /* wake up in-between to check for sig naled requests */
// what's the time? // what's the time?
now = time(NULL); now = time(NULL);
skipping to change at line 356 skipping to change at line 347
if(entry->error_code) { if(entry->error_code) {
rep_time = N2N_RESOLVE_INTERVAL / 10; rep_time = N2N_RESOLVE_INTERVAL / 10;
break; break;
} }
} }
} }
// unlock access // unlock access
pthread_mutex_unlock(&param->access); pthread_mutex_unlock(&param->access);
} }
#endif
} }
#endif
int resolve_create_thread (n2n_resolve_parameter_t **param, struct peer_info *sn _list) { int resolve_create_thread (n2n_resolve_parameter_t **param, struct peer_info *sn _list) {
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
struct peer_info *sn, *tmp_sn; struct peer_info *sn, *tmp_sn;
n2n_resolve_ip_sock_t *entry; n2n_resolve_ip_sock_t *entry;
int ret; int ret;
// create parameter structure // create parameter structure
*param = (n2n_resolve_parameter_t*)calloc(1, sizeof(n2n_resolve_parameter_t) ); *param = (n2n_resolve_parameter_t*)calloc(1, sizeof(n2n_resolve_parameter_t) );
skipping to change at line 398 skipping to change at line 389
// create thread // create thread
ret = pthread_create(&((*param)->id), NULL, resolve_thread, (void *)*param); ret = pthread_create(&((*param)->id), NULL, resolve_thread, (void *)*param);
if(ret) { if(ret) {
traceEvent(TRACE_WARNING, "resolve_create_thread failed to create resolv er thread with error number %d", ret); traceEvent(TRACE_WARNING, "resolve_create_thread failed to create resolv er thread with error number %d", ret);
return -1; return -1;
} }
pthread_mutex_init(&((*param)->access), NULL); pthread_mutex_init(&((*param)->access), NULL);
return 0; return 0;
#else
return -1;
#endif #endif
} }
void resolve_cancel_thread (n2n_resolve_parameter_t *param) { void resolve_cancel_thread (n2n_resolve_parameter_t *param) {
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
pthread_cancel(param->id); pthread_cancel(param->id);
free(param); free(param);
#endif #endif
} }
skipping to change at line 575 skipping to change at line 568
printf("\n"); printf("\n");
printf("-----------------------------------------------\n"); printf("-----------------------------------------------\n");
} }
/* *********************************************** */ /* *********************************************** */
void print_n2n_version () { void print_n2n_version () {
printf("Welcome to n2n v.%s for %s\n" printf("Welcome to n2n v.%s for %s\n"
"Built on %s\n" "Built on %s\n"
"Copyright 2007-2021 - ntop.org and contributors\n\n", "Copyright 2007-2022 - ntop.org and contributors\n\n",
GIT_RELEASE, PACKAGE_OSNAME, PACKAGE_BUILDDATE); PACKAGE_VERSION, PACKAGE_OSNAME, PACKAGE_BUILDDATE);
} }
/* *********************************************** */ /* *********************************************** */
size_t purge_expired_nodes (struct peer_info **peer_list, size_t purge_expired_nodes (struct peer_info **peer_list,
SOCKET socket_not_to_close, SOCKET socket_not_to_close,
n2n_tcp_connection_t **tcp_connections, n2n_tcp_connection_t **tcp_connections,
time_t *p_last_purge, time_t *p_last_purge,
int frequency, int timeout) { int frequency, int timeout) {
skipping to change at line 629 skipping to change at line 622
HASH_FIND_INT(*tcp_connections, &scan->socket_fd, conn); HASH_FIND_INT(*tcp_connections, &scan->socket_fd, conn);
if(conn) { if(conn) {
HASH_DEL(*tcp_connections, conn); HASH_DEL(*tcp_connections, conn);
free(conn); free(conn);
} }
shutdown(scan->socket_fd, SHUT_RDWR); shutdown(scan->socket_fd, SHUT_RDWR);
closesocket(scan->socket_fd); closesocket(scan->socket_fd);
} }
} }
HASH_DEL(*peer_list, scan); HASH_DEL(*peer_list, scan);
mgmt_event_post(N2N_EVENT_PEER,N2N_EVENT_PEER_PURGE,scan);
/* FIXME: generates events for more than just p2p */
retval++; retval++;
free(scan); free(scan);
} }
} }
return retval; return retval;
} }
/** Purge all items from the peer_list and return the number of items that were removed. */ /** Purge all items from the peer_list and return the number of items that were removed. */
size_t clear_peer_list (struct peer_info ** peer_list) { size_t clear_peer_list (struct peer_info ** peer_list) {
struct peer_info *scan, *tmp; struct peer_info *scan, *tmp;
size_t retval = 0; size_t retval = 0;
HASH_ITER(hh, *peer_list, scan, tmp) { HASH_ITER(hh, *peer_list, scan, tmp) {
HASH_DEL(*peer_list, scan); HASH_DEL(*peer_list, scan);
mgmt_event_post(N2N_EVENT_PEER,N2N_EVENT_PEER_CLEAR,scan);
/* FIXME: generates events for more than just p2p */
retval++; retval++;
free(scan); free(scan);
} }
return retval; return retval;
} }
static uint8_t hex2byte (const char * s) { static uint8_t hex2byte (const char * s) {
char tmp[3]; char tmp[3];
 End of changes. 13 change blocks. 
18 lines changed or deleted 14 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)