|
|
@ -67,11 +67,11 @@ static int load_allowed_sn_community (n2n_sn_t *sss, char *path) { |
|
|
|
while((line = fgets(buffer, sizeof(buffer), fd)) != NULL) { |
|
|
|
int len = strlen(line); |
|
|
|
|
|
|
|
if(((len < 2) || line[0]) == '#') { |
|
|
|
if((len < 2) || line[0] == '#') { |
|
|
|
continue; |
|
|
|
} |
|
|
|
len--; |
|
|
|
|
|
|
|
len--; |
|
|
|
while(len > 0) { |
|
|
|
if((line[len] == '\n') || (line[len] == '\r')) { |
|
|
|
line[len] = '\0'; |
|
|
@ -186,6 +186,7 @@ static void help () { |
|
|
|
printf("-p <local port> "); |
|
|
|
printf("-c <path> "); |
|
|
|
printf("-l <supernode:port> "); |
|
|
|
|
|
|
|
#if defined(N2N_HAVE_DAEMON) |
|
|
|
printf("[-f] "); |
|
|
|
#endif |
|
|
@ -282,6 +283,7 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) { |
|
|
|
} |
|
|
|
|
|
|
|
if(sss->federation != NULL) { |
|
|
|
|
|
|
|
skip_add = SN_ADD; |
|
|
|
anchor_sn = add_sn_to_list_by_mac_or_sock(&(sss->federation->edges), socket, (n2n_mac_t*) null_mac, &skip_add); |
|
|
|
|
|
|
@ -293,6 +295,7 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) { |
|
|
|
memcpy(&(anchor_sn->mac_addr), null_mac, sizeof(n2n_mac_t)); |
|
|
|
anchor_sn->purgeable = SN_UNPURGEABLE; |
|
|
|
anchor_sn->last_valid_time_stamp = initial_time_stamp(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -354,6 +357,7 @@ static int setOption (int optkey, char *_optarg, n2n_sn_t *sss) { |
|
|
|
#endif |
|
|
|
|
|
|
|
case 'F': { /* federation name */ |
|
|
|
|
|
|
|
snprintf(sss->federation->community, N2N_COMMUNITY_SIZE - 1 ,"*%s", _optarg); |
|
|
|
sss->federation->community[N2N_COMMUNITY_SIZE - 1] = '\0'; |
|
|
|
|
|
|
@ -464,6 +468,7 @@ static int loadFromFile (const char *path, n2n_sn_t *sss) { |
|
|
|
} |
|
|
|
|
|
|
|
while((line = fgets(buffer, sizeof(buffer), fd)) != NULL) { |
|
|
|
|
|
|
|
line = trim(line); |
|
|
|
value = NULL; |
|
|
|
|
|
|
@ -499,12 +504,8 @@ static int loadFromFile (const char *path, n2n_sn_t *sss) { |
|
|
|
} |
|
|
|
} else if(line[0] == '-') { /* short opt */ |
|
|
|
key = &line[1], line_len--; |
|
|
|
if(line_len > 1) { |
|
|
|
key[1] = '\0'; |
|
|
|
} |
|
|
|
if(line_len > 2) { |
|
|
|
value = trim(&key[2]); |
|
|
|
} |
|
|
|
if(line_len > 1) key[1] = '\0'; |
|
|
|
if(line_len > 2) value = trim(&key[2]); |
|
|
|
|
|
|
|
// traceEvent(TRACE_NORMAL, "key: %c value: %s", key[0], value);
|
|
|
|
setOption(key[0], value, sss); |
|
|
@ -528,7 +529,9 @@ static int add_federation_to_communities (n2n_sn_t *sss) { |
|
|
|
|
|
|
|
if(sss->federation != NULL) { |
|
|
|
HASH_ADD_STR(sss->communities, community, sss->federation); |
|
|
|
|
|
|
|
num_communities = HASH_COUNT(sss->communities); |
|
|
|
|
|
|
|
traceEvent(TRACE_INFO, "Added federation '%s' to the list of communities [total: %u]", |
|
|
|
(char*)sss->federation->community, num_communities); |
|
|
|
} |
|
|
@ -605,6 +608,7 @@ BOOL WINAPI term_handler (DWORD sig) |
|
|
|
int main (int argc, char * const argv[]) { |
|
|
|
|
|
|
|
int rc; |
|
|
|
|
|
|
|
#ifndef WIN32 |
|
|
|
struct passwd *pw = NULL; |
|
|
|
#endif |
|
|
@ -620,6 +624,7 @@ int main (int argc, char * const argv[]) { |
|
|
|
} else if(argc > 1) { |
|
|
|
rc = loadFromCLI(argc, argv, &sss_node); |
|
|
|
} else |
|
|
|
|
|
|
|
#ifdef WIN32 |
|
|
|
/* Load from current directory */ |
|
|
|
rc = loadFromFile("supernode.conf", &sss_node); |
|
|
@ -631,6 +636,7 @@ int main (int argc, char * const argv[]) { |
|
|
|
help(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if defined(N2N_HAVE_DAEMON) |
|
|
|
if(sss_node.daemon) { |
|
|
|
setUseSyslog(1); /* traceEvent output now goes to syslog. */ |
|
|
@ -659,6 +665,7 @@ int main (int argc, char * const argv[]) { |
|
|
|
} else { |
|
|
|
traceEvent(TRACE_NORMAL, "supernode is listening on UDP %u (management)", sss_node.mport); |
|
|
|
} |
|
|
|
|
|
|
|
#ifndef WIN32 |
|
|
|
if(((pw = getpwnam ("n2n")) != NULL) || ((pw = getpwnam ("nobody")) != NULL)) { |
|
|
|
sss_node.userid = sss_node.userid == 0 ? pw->pw_uid : 0; |
|
|
|