Added termination variable to edge loop

This commit is contained in:
Luca Deri 2018-06-08 12:01:03 +02:00
parent 828ae8316c
commit b6fdae38b9
4 changed files with 18 additions and 14 deletions

3
edge.c
View File

@ -394,6 +394,7 @@ static void daemonize() {
/** Entry point to program from kernel. */
int main(int argc, char* argv[]) {
int opt;
int keep_on_running = 1;
int local_port = 0 /* any port */;
int mgmt_port = N2N_EDGE_MGMT_PORT; /* 5644 by default */
char tuntap_dev_name[N2N_IFNAMSIZ] = "edge0";
@ -744,7 +745,7 @@ int main(int argc, char* argv[]) {
update_supernode_reg(&eee, time(NULL));
return run_edge_loop(&eee);
return run_edge_loop(&eee, &keep_on_running);
}
/* ************************************** */

View File

@ -1394,8 +1394,7 @@ static void readFromIPSocket(n2n_edge_t * eee) {
/* ************************************** */
int run_edge_loop(n2n_edge_t * eee) {
int keep_running=1;
int run_edge_loop(n2n_edge_t * eee, int *keep_running) {
size_t numPurged;
time_t lastIfaceCheck=0;
time_t lastTransop=0;
@ -1404,6 +1403,8 @@ int run_edge_loop(n2n_edge_t * eee) {
startTunReadThread(eee);
#endif
*keep_running = 1;
/* Main loop
*
* select() is used to wait for input on either the TAP fd or the UDP/TCP
@ -1450,16 +1451,14 @@ int run_edge_loop(n2n_edge_t * eee) {
readFromIPSocket(eee);
}
if(FD_ISSET(eee->udp_mgmt_sock, &socket_mask))
{
if(FD_ISSET(eee->udp_mgmt_sock, &socket_mask)) {
/* Read a cooked socket from the internet socket. Writes on the TAP
* socket. */
readFromMgmtSocket(eee, &keep_running);
readFromMgmtSocket(eee, keep_running);
}
#ifndef WIN32
if(FD_ISSET(eee->device.fd, &socket_mask))
{
if(FD_ISSET(eee->device.fd, &socket_mask)) {
/* Read an ethernet frame from the TAP socket. Write on the IP
* socket. */
readFromTAPSocket(eee);
@ -1583,7 +1582,8 @@ void edge_term(n2n_edge_t * eee) {
int quick_edge_init(char *device_name, char *community_name,
char *encrypt_key, char *device_mac,
char *local_ip_address,
char *supernode_ip_address_port) {
char *supernode_ip_address_port,
int *keep_on_running) {
n2n_edge_t eee;
edge_init(&eee);
@ -1610,5 +1610,5 @@ int quick_edge_init(char *device_name, char *community_name,
update_supernode_reg(&eee, time(NULL));
return(run_edge_loop(&eee));
return(run_edge_loop(&eee, keep_on_running));
}

View File

@ -30,7 +30,8 @@ int main(int argc, char* argv[]) {
char *my_mac_address = (char*)"DE:AD:BE:EF:01:10";
char *my_ipv4_addr = (char*)"1.2.3.4";
char *supernode = (char*)"7.8.9.10:1234";
int keep_on_running = 1;
/* Increase tracelevel to see what's happening */
traceLevel = 10;
@ -45,5 +46,6 @@ int main(int argc, char* argv[]) {
secret_key,
my_mac_address,
my_ipv4_addr,
supernode));
supernode,
&keep_on_running));
}

5
n2n.h
View File

@ -323,11 +323,12 @@ void set_peer_operational(n2n_edge_t * eee,
const char * supernode_ip(const n2n_edge_t * eee);
int edge_init_twofish(n2n_edge_t * eee, uint8_t *encrypt_pwd,
uint32_t encrypt_pwd_len);
int run_edge_loop(n2n_edge_t * eee);
int run_edge_loop(n2n_edge_t * eee, int *keep_running);
void edge_term(n2n_edge_t * eee);
int quick_edge_init(char *device_name, char *community_name,
char *encrypt_key, char *device_mac,
char *local_ip_address,
char *supernode_ip_address_port);
char *supernode_ip_address_port,
int *keep_on_running);
#endif /* _N2N_H_ */