From b00f329a31198700827bd074946a07d02a8f8a6d Mon Sep 17 00:00:00 2001 From: Luca Deri Date: Fri, 8 Jun 2018 08:19:06 +0200 Subject: [PATCH] Code cleanup --- Makefile | 6 +++- edge.c | 65 ------------------------------------ egde_utils.c => edge_utils.c | 51 ++++++++++++++++++++++++++++ n2n.h | 4 --- 4 files changed, 56 insertions(+), 70 deletions(-) rename egde_utils.c => edge_utils.c (96%) diff --git a/Makefile b/Makefile index 2e8266d..2eca42d 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ MAN8DIR=$(MANDIR)/man8 N2N_LIB=n2n.a N2N_OBJS=n2n.o n2n_keyfile.o wire.o minilzo.o twofish.o \ - egde_utils.o \ + edge_utils.o \ transform_null.o transform_tf.o transform_aes.o \ tuntap_freebsd.o tuntap_netbsd.o tuntap_linux.o \ tuntap_osx.o version.o @@ -60,6 +60,7 @@ endif APPS=edge APPS+=supernode +APPS+=example_edge_embed DOCS=edge.8.gz supernode.1.gz n2n_v2.7.gz @@ -77,6 +78,9 @@ supernode: sn.c $(N2N_LIB) n2n.h Makefile benchmark: benchmark.c $(N2N_LIB) n2n_wire.h n2n.h Makefile $(CC) $(CFLAGS) benchmark.c $(N2N_LIB) $(LIBS_SN) -o benchmark +example_edge_embed: example_edge_embed.c $(N2N_LIB) n2n.h + $(CC) $(CFLAGS) example_edge_embed.c $(N2N_LIB) $(LIBS_EDGE) -o example_edge_embed + .c.o: n2n.h n2n_keyfile.h n2n_transforms.h n2n_wire.h twofish.h Makefile $(CC) $(CFLAGS) -c $< diff --git a/edge.c b/edge.c index 02c15c0..12da835 100644 --- a/edge.c +++ b/edge.c @@ -222,57 +222,6 @@ static void help() { /* ************************************** */ -/** Start the registration process. - * - * If the peer is already in pending_peers, ignore the request. - * If not in pending_peers, add it and send a REGISTER. - * - * If hdr is for a direct peer-to-peer packet, try to register back to sender - * even if the MAC is in pending_peers. This is because an incident direct - * packet indicates that peer-to-peer exchange should work so more aggressive - * registration can be permitted (once per incoming packet) as this should only - * last for a small number of packets.. - * - * Called from the main loop when Rx a packet for our device mac. - */ -void try_send_register(n2n_edge_t * eee, - uint8_t from_supernode, - const n2n_mac_t mac, - const n2n_sock_t * peer) -{ - /* REVISIT: purge of pending_peers not yet done. */ - struct peer_info * scan = find_peer_by_mac(eee->pending_peers, mac); - macstr_t mac_buf; - n2n_sock_str_t sockbuf; - - if(NULL == scan) - { - scan = calloc(1, sizeof(struct peer_info)); - - memcpy(scan->mac_addr, mac, N2N_MAC_SIZE); - scan->sock = *peer; - scan->last_seen = time(NULL); /* Don't change this it marks the pending peer for removal. */ - - peer_list_add(&(eee->pending_peers), scan); - - traceEvent(TRACE_DEBUG, "=== new pending %s -> %s", - macaddr_str(mac_buf, scan->mac_addr), - sock_to_cstr(sockbuf, &(scan->sock))); - - traceEvent(TRACE_INFO, "Pending peers list size=%u", - (unsigned int)peer_list_size(eee->pending_peers)); - - /* trace Sending REGISTER */ - - send_register(eee, &(scan->sock)); - - /* pending_peers now owns scan. */ - } else { - } -} - -/* ************************************** */ - #if defined(DUMMY_ID_00001) /* Disabled waiting for config option to enable it */ static char gratuitous_arp[] = { @@ -799,17 +748,3 @@ int main(int argc, char* argv[]) { } /* ************************************** */ - -#ifdef QUICK_INIT - -int main(int argc, char* argv[]) { - traceLevel = 10; - return(quick_edge_init("n2n0", - "mynetwork", - "ntop2018", - "DE:AD:BE:EF:01:10", - "192.168.254.10", - "192.12.193.11:7654")); -} - -#endif diff --git a/egde_utils.c b/edge_utils.c similarity index 96% rename from egde_utils.c rename to edge_utils.c index 32a3caf..c9ff1a0 100644 --- a/egde_utils.c +++ b/edge_utils.c @@ -151,6 +151,57 @@ void supernode2addr(n2n_sock_t * sn, const n2n_sn_name_t addrIn) { /* ************************************** */ +/** Start the registration process. + * + * If the peer is already in pending_peers, ignore the request. + * If not in pending_peers, add it and send a REGISTER. + * + * If hdr is for a direct peer-to-peer packet, try to register back to sender + * even if the MAC is in pending_peers. This is because an incident direct + * packet indicates that peer-to-peer exchange should work so more aggressive + * registration can be permitted (once per incoming packet) as this should only + * last for a small number of packets.. + * + * Called from the main loop when Rx a packet for our device mac. + */ +static void try_send_register(n2n_edge_t * eee, + uint8_t from_supernode, + const n2n_mac_t mac, + const n2n_sock_t * peer) +{ + /* REVISIT: purge of pending_peers not yet done. */ + struct peer_info * scan = find_peer_by_mac(eee->pending_peers, mac); + macstr_t mac_buf; + n2n_sock_str_t sockbuf; + + if(NULL == scan) + { + scan = calloc(1, sizeof(struct peer_info)); + + memcpy(scan->mac_addr, mac, N2N_MAC_SIZE); + scan->sock = *peer; + scan->last_seen = time(NULL); /* Don't change this it marks the pending peer for removal. */ + + peer_list_add(&(eee->pending_peers), scan); + + traceEvent(TRACE_DEBUG, "=== new pending %s -> %s", + macaddr_str(mac_buf, scan->mac_addr), + sock_to_cstr(sockbuf, &(scan->sock))); + + traceEvent(TRACE_INFO, "Pending peers list size=%u", + (unsigned int)peer_list_size(eee->pending_peers)); + + /* trace Sending REGISTER */ + + send_register(eee, &(scan->sock)); + + /* pending_peers now owns scan. */ + } else { + } +} + +/* ************************************** */ + /** Update the last_seen time for this peer, or get registered. */ void check_peer(n2n_edge_t * eee, uint8_t from_supernode, diff --git a/n2n.h b/n2n.h index cf11c48..10f1513 100644 --- a/n2n.h +++ b/n2n.h @@ -317,10 +317,6 @@ void check_peer(n2n_edge_t * eee, uint8_t from_supernode, const n2n_mac_t mac, const n2n_sock_t * peer); -void try_send_register(n2n_edge_t * eee, - uint8_t from_supernode, - const n2n_mac_t mac, - const n2n_sock_t * peer); void set_peer_operational(n2n_edge_t * eee, const n2n_mac_t mac, const n2n_sock_t * peer);