Browse Source

Added termination variable to edge loop

pull/26/head
Luca Deri 7 years ago
parent
commit
b6fdae38b9
  1. 3
      edge.c
  2. 18
      edge_utils.c
  3. 4
      example_edge_embed.c
  4. 5
      n2n.h

3
edge.c

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

18
edge_utils.c

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

4
example_edge_embed.c

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

5
n2n.h

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

Loading…
Cancel
Save