From 8680cf76bfee0fe21529d6f4747801d246be177f Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 4 Aug 2013 23:01:11 +0200 Subject: [PATCH 1/4] Make private functions in core/net_crypto.c static --- core/net_crypto.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/net_crypto.c b/core/net_crypto.c index 561ba866..4ce173c5 100644 --- a/core/net_crypto.c +++ b/core/net_crypto.c @@ -126,7 +126,7 @@ int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, } /* increment the given nonce by 1 */ -void increment_nonce(uint8_t *nonce) +static void increment_nonce(uint8_t *nonce) { uint32_t i; for (i = 0; i < crypto_box_NONCEBYTES; ++i) { @@ -243,7 +243,7 @@ int handle_request(uint8_t *public_key, uint8_t *data, uint8_t *packet, uint16_t /* Send a crypto handshake packet containing an encrypted secret nonce and session public key to peer with connection_id and public_key the packet is encrypted with a random nonce which is sent in plain text with the packet */ -int send_cryptohandshake(int connection_id, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key) +static int send_cryptohandshake(int connection_id, uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key) { uint8_t temp_data[MAX_DATA_SIZE]; uint8_t temp[crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES]; @@ -266,7 +266,7 @@ int send_cryptohandshake(int connection_id, uint8_t *public_key, uint8_t *secret /* Extract secret nonce, session public key and public_key from a packet(data) with length length return 1 if successful return 0 if failure */ -int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce, +static int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce, uint8_t *session_key, uint8_t *data, uint16_t length) { int pad = (- crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES); @@ -295,7 +295,7 @@ int handle_cryptohandshake(uint8_t *public_key, uint8_t *secret_nonce, /* get crypto connection id from public key of peer return -1 if there are no connections like we are looking for return id if it found it */ -int getcryptconnection_id(uint8_t *public_key) +static int getcryptconnection_id(uint8_t *public_key) { uint32_t i; for (i = 0; i < MAX_CRYPTO_CONNECTIONS; ++i) { @@ -465,7 +465,7 @@ void load_keys(uint8_t *keys) adds an incoming connection to the incoming_connection list. returns 0 if successful returns 1 if failure */ -int new_incoming(int id) +static int new_incoming(int id) { uint32_t i; for (i = 0; i < MAX_INCOMING; ++i) { From 2a9fedc08f4ebaa210f94041a99eb6d11c0ce45c Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 4 Aug 2013 22:47:16 +0200 Subject: [PATCH 2/4] Make private functions in core/Lossless_UDP.c static --- core/Lossless_UDP.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/core/Lossless_UDP.c b/core/Lossless_UDP.c index a753e5ff..8538f76c 100644 --- a/core/Lossless_UDP.c +++ b/core/Lossless_UDP.c @@ -149,7 +149,7 @@ static uint32_t randtable[6][256]; * * TODO: make this better */ -uint32_t handshake_id(IP_Port source) +static uint32_t handshake_id(IP_Port source) { uint32_t id = 0, i; for (i = 0; i < 6; ++i) { @@ -168,7 +168,7 @@ uint32_t handshake_id(IP_Port source) * * TODO: make this better */ -void change_handshake(IP_Port source) +static void change_handshake(IP_Port source) { uint8_t rand = random_int() % 4; randtable[rand][((uint8_t *)&source)[rand]] = random_int(); @@ -234,7 +234,7 @@ int new_connection(IP_Port ip_port) * Returns an integer corresponding to the connection id. * Return -1 if it could not initialize the connection. */ -int new_inconnection(IP_Port ip_port) +static int new_inconnection(IP_Port ip_port) { if (getconnection_id(ip_port) != -1) return -1; @@ -470,7 +470,7 @@ uint32_t missing_packets(int connection_id, uint32_t * requested) * see http://wiki.tox.im/index.php/Lossless_UDP for more information. */ -int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2) +static int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_id2) { uint8_t packet[1 + 4 + 4]; uint32_t temp; @@ -484,7 +484,7 @@ int send_handshake(IP_Port ip_port, uint32_t handshake_id1, uint32_t handshake_i return sendpacket(ip_port, packet, sizeof(packet)); } -int send_SYNC(uint32_t connection_id) +static int send_SYNC(uint32_t connection_id) { uint8_t packet[(BUFFER_PACKET_NUM*4 + 4 + 4 + 2)]; uint16_t index = 0; @@ -511,7 +511,7 @@ int send_SYNC(uint32_t connection_id) } -int send_data_packet(uint32_t connection_id, uint32_t packet_num) +static int send_data_packet(uint32_t connection_id, uint32_t packet_num) { uint32_t index = packet_num % MAX_QUEUE_NUM; uint32_t temp; @@ -526,7 +526,7 @@ int send_data_packet(uint32_t connection_id, uint32_t packet_num) } /* sends 1 data packet */ -int send_DATA(uint32_t connection_id) +static int send_DATA(uint32_t connection_id) { int ret; uint32_t buffer[BUFFER_PACKET_NUM]; @@ -555,7 +555,7 @@ int send_DATA(uint32_t connection_id) /* Return 0 if handled correctly, 1 if packet is bad. */ -int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source) +static int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source) { if (length != (1 + 4 + 4)) return 1; @@ -591,7 +591,7 @@ int handle_handshake(uint8_t * packet, uint32_t length, IP_Port source) } /* returns 1 if sync packet is valid 0 if not. */ -int SYNC_valid(uint32_t length) +static int SYNC_valid(uint32_t length) { if (length < 4 + 4 + 2) return 0; @@ -602,7 +602,7 @@ int SYNC_valid(uint32_t length) } /* case 1 in handle_SYNC: */ -int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnum) +static int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnum) { if (handshake_id(source) == recv_packetnum) { int x = new_inconnection(source); @@ -622,7 +622,7 @@ int handle_SYNC1(IP_Port source, uint32_t recv_packetnum, uint32_t sent_packetnu } /* case 2 in handle_SYNC: */ -int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum) +static int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum) { if (recv_packetnum == connections[connection_id].orecv_packetnum) { /* && sent_packetnum == connections[connection_id].osent_packetnum) */ @@ -635,7 +635,7 @@ int handle_SYNC2(int connection_id, uint8_t counter, uint32_t recv_packetnum, ui return 1; } /* case 3 in handle_SYNC: */ -int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum, uint32_t * req_packets, +static int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, uint32_t sent_packetnum, uint32_t * req_packets, uint16_t number) { uint8_t comp_counter = (counter - connections[connection_id].recv_counter ); @@ -669,7 +669,7 @@ int handle_SYNC3(int connection_id, uint8_t counter, uint32_t recv_packetnum, ui return 1; } -int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source) +static int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source) { if (!SYNC_valid(length)) @@ -708,7 +708,7 @@ int handle_SYNC(uint8_t *packet, uint32_t length, IP_Port source) * Add a packet to the received buffer and set the recv_packetnum of the * connection to its proper value. Return 1 if data was too big, 0 if not. */ -int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size) +static int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size) { if (size > MAX_DATA_SIZE) return 1; @@ -742,7 +742,7 @@ int add_recv(int connection_id, uint32_t data_num, uint8_t *data, uint16_t size) return 0; } -int handle_data(uint8_t *packet, uint32_t length, IP_Port source) +static int handle_data(uint8_t *packet, uint32_t length, IP_Port source) { int connection = getconnection_id(source); @@ -793,7 +793,7 @@ int LosslessUDP_handlepacket(uint8_t *packet, uint32_t length, IP_Port source) * Send handshake requests * handshake packets are sent at the same rate as SYNC packets */ -void doNew() +static void doNew() { uint32_t i; uint64_t temp_time = current_time(); @@ -817,7 +817,7 @@ void doNew() } } -void doSYNC() +static void doSYNC() { uint32_t i; uint64_t temp_time = current_time(); @@ -830,7 +830,7 @@ void doSYNC() } } -void doData() +static void doData() { uint32_t i; uint64_t j; @@ -851,7 +851,7 @@ void doData() * * TODO: flow control. */ -void adjustRates() +static void adjustRates() { uint32_t i; uint64_t temp_time = current_time(); From c387de52b2a711f05ae2c9c8652e441038289c3d Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 4 Aug 2013 22:38:46 +0200 Subject: [PATCH 3/4] Make private functions in core/LAN_discovery.c static --- core/LAN_discovery.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/LAN_discovery.c b/core/LAN_discovery.c index 72e00d32..67cbfe9a 100644 --- a/core/LAN_discovery.c +++ b/core/LAN_discovery.c @@ -29,7 +29,7 @@ /* get the first working broadcast address that's not from "lo" * returns higher than 0 on success * returns 0 on error */ -uint32_t get_broadcast(void) +static uint32_t get_broadcast(void) { /* not sure how many platforms this will * run on, so it's wrapped in __linux for now */ @@ -76,7 +76,7 @@ uint32_t get_broadcast(void) #endif /* Return the broadcast ip */ -IP broadcast_ip() +static IP broadcast_ip() { IP ip; #ifdef __linux @@ -92,7 +92,7 @@ IP broadcast_ip() /*return 0 if ip is a LAN ip return -1 if it is not */ -int LAN_ip(IP ip) +static int LAN_ip(IP ip) { if (ip.c[0] == 127)/* Loopback */ return 0; @@ -107,7 +107,7 @@ int LAN_ip(IP ip) return -1; } -int handle_LANdiscovery(uint8_t *packet, uint32_t length, IP_Port source) +static int handle_LANdiscovery(uint8_t *packet, uint32_t length, IP_Port source) { if (LAN_ip(source.ip) == -1) return 1; From 7567e0a1c4a73731856639f3133d9ffa8a771bc0 Mon Sep 17 00:00:00 2001 From: Florian Hahn Date: Sun, 4 Aug 2013 22:31:26 +0200 Subject: [PATCH 4/4] Make private functions in core/DHT.c static --- core/DHT.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/core/DHT.c b/core/DHT.c index 08b4710e..68ec95d7 100644 --- a/core/DHT.c +++ b/core/DHT.c @@ -119,7 +119,7 @@ static Pinged send_nodes[LSEND_NODES_ARRAY]; * return 1 if client_id1 is closer * return 2 if client_id2 is closer */ -int id_closest(uint8_t * id, uint8_t * id1, uint8_t * id2) +static int id_closest(uint8_t * id, uint8_t * id1, uint8_t * id2) { size_t i; uint8_t distance1, distance2; @@ -137,17 +137,17 @@ int id_closest(uint8_t * id, uint8_t * id1, uint8_t * id2) return 0; } -int ipport_equal(IP_Port a, IP_Port b) +static int ipport_equal(IP_Port a, IP_Port b) { return (a.ip.i == b.ip.i) && (a.port == b.port); } -int id_equal(uint8_t* a, uint8_t* b) +static int id_equal(uint8_t* a, uint8_t* b) { return memcmp(a, b, CLIENT_ID_SIZE) == 0; } -int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout) +static int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout) { return timestamp + timeout <= time_now; } @@ -159,7 +159,7 @@ int is_timeout(uint64_t time_now, uint64_t timestamp, uint64_t timeout) * * TODO: maybe optimize this. */ -int client_in_list(Client_data * list, uint32_t length, uint8_t * client_id, IP_Port ip_port) +static int client_in_list(Client_data * list, uint32_t length, uint8_t * client_id, IP_Port ip_port) { uint32_t i; uint64_t temp_time = unix_time(); @@ -184,7 +184,7 @@ int client_in_list(Client_data * list, uint32_t length, uint8_t * client_id, IP_ /* check if client with client_id is already in node format list of length length. * return True(1) or False(0) */ -int client_in_nodelist(Node_format * list, uint32_t length, uint8_t * client_id) +static int client_in_nodelist(Node_format * list, uint32_t length, uint8_t * client_id) { uint32_t i; @@ -215,7 +215,7 @@ static int friend_number(uint8_t * client_id) * * TODO: For the love of based Allah make this function cleaner and much more efficient. */ -int get_close_nodes(uint8_t * client_id, Node_format * nodes_list) +static int get_close_nodes(uint8_t * client_id, Node_format * nodes_list) { uint32_t i, j, k; uint64_t temp_time = unix_time(); @@ -301,7 +301,7 @@ int get_close_nodes(uint8_t * client_id, Node_format * nodes_list) * return 0 if successful * return 1 if not (list contains no bad nodes) */ -int replace_bad( Client_data * list, +static int replace_bad( Client_data * list, uint32_t length, uint8_t * client_id, IP_Port ip_port ) @@ -325,7 +325,7 @@ int replace_bad( Client_data * list, } /* replace the first good node that is further to the comp_client_id than that of the client_id in the list */ -int replace_good( Client_data * list, +static int replace_good( Client_data * list, uint32_t length, uint8_t * client_id, IP_Port ip_port, @@ -351,7 +351,7 @@ int replace_good( Client_data * list, /* Attempt to add client with ip_port and client_id to the friends client list * and close_clientlist */ -void addto_lists(IP_Port ip_port, uint8_t * client_id) +static void addto_lists(IP_Port ip_port, uint8_t * client_id) { uint32_t i; @@ -393,7 +393,7 @@ void addto_lists(IP_Port ip_port, uint8_t * client_id) /* If client_id is a friend or us, update ret_ip_port * nodeclient_id is the id of the node that sent us this info */ -void returnedip_ports(IP_Port ip_port, uint8_t * client_id, uint8_t * nodeclient_id) +static void returnedip_ports(IP_Port ip_port, uint8_t * client_id, uint8_t * nodeclient_id) { uint32_t i, j; uint64_t temp_time = unix_time(); @@ -431,7 +431,7 @@ void returnedip_ports(IP_Port ip_port, uint8_t * client_id, uint8_t * nodeclient * * TODO: optimize this */ -int is_pinging(IP_Port ip_port, uint64_t ping_id) +static int is_pinging(IP_Port ip_port, uint64_t ping_id) { uint32_t i; uint8_t pinging; @@ -456,7 +456,7 @@ int is_pinging(IP_Port ip_port, uint64_t ping_id) } /* Same as last function but for get_node requests. */ -int is_gettingnodes(IP_Port ip_port, uint64_t ping_id) +static int is_gettingnodes(IP_Port ip_port, uint64_t ping_id) { uint32_t i; uint8_t pinging; @@ -486,7 +486,7 @@ int is_gettingnodes(IP_Port ip_port, uint64_t ping_id) * * TODO: optimize this */ -uint64_t add_pinging(IP_Port ip_port) +static uint64_t add_pinging(IP_Port ip_port) { uint32_t i, j; uint64_t ping_id = ((uint64_t)random_int() << 32) + random_int(); @@ -507,7 +507,7 @@ uint64_t add_pinging(IP_Port ip_port) } /* Same but for get node requests */ -uint64_t add_gettingnodes(IP_Port ip_port) +static uint64_t add_gettingnodes(IP_Port ip_port) { uint32_t i, j; uint64_t ping_id = ((uint64_t)random_int() << 32) + random_int(); @@ -676,7 +676,7 @@ static int sendnodes(IP_Port ip_port, uint8_t * public_key, uint8_t * client_id, /* Packet handling functions, one to handle each types of packets we receive * Returns 0 if handled correctly, 1 if packet is bad. */ -int handle_pingreq(uint8_t * packet, uint32_t length, IP_Port source) +static int handle_pingreq(uint8_t * packet, uint32_t length, IP_Port source) { uint64_t ping_id; if(length != 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) + ENCRYPTION_PADDING) @@ -702,7 +702,7 @@ int handle_pingreq(uint8_t * packet, uint32_t length, IP_Port source) return 0; } -int handle_pingres(uint8_t * packet, uint32_t length, IP_Port source) +static int handle_pingres(uint8_t * packet, uint32_t length, IP_Port source) { uint64_t ping_id; if(length != 1 + CLIENT_ID_SIZE + crypto_box_NONCEBYTES + sizeof(ping_id) + ENCRYPTION_PADDING) @@ -729,7 +729,7 @@ int handle_pingres(uint8_t * packet, uint32_t length, IP_Port source) return 1; } -int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source) +static int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source) { uint64_t ping_id; @@ -761,7 +761,7 @@ int handle_getnodes(uint8_t * packet, uint32_t length, IP_Port source) return 0; } -int handle_sendnodes(uint8_t * packet, uint32_t length, IP_Port source) +static int handle_sendnodes(uint8_t * packet, uint32_t length, IP_Port source) { uint64_t ping_id; uint32_t cid_size = 1 + CLIENT_ID_SIZE; @@ -1029,7 +1029,7 @@ int route_tofriend(uint8_t * friend_id, uint8_t * packet, uint32_t length) /* Send the following packet to one random person who tells us they are connected to friend_id * returns the number of nodes it sent the packet to */ -int routeone_tofriend(uint8_t * friend_id, uint8_t * packet, uint32_t length) +static int routeone_tofriend(uint8_t * friend_id, uint8_t * packet, uint32_t length) { int num = friend_number(friend_id); if (num == -1) @@ -1079,7 +1079,7 @@ int friend_ips(IP_Port * ip_portlist, uint8_t * friend_id) /*----------------------------------------------------------------------------------*/ /*---------------------BEGINNING OF NAT PUNCHING FUNCTIONS--------------------------*/ -int send_NATping(uint8_t * public_key, uint64_t ping_id, uint8_t type) +static int send_NATping(uint8_t * public_key, uint64_t ping_id, uint8_t type) { uint8_t data[sizeof(uint64_t) + 1]; uint8_t packet[MAX_DATA_SIZE]; @@ -1105,7 +1105,7 @@ int send_NATping(uint8_t * public_key, uint64_t ping_id, uint8_t type) } /* Handle a recieved ping request for */ -int handle_NATping(uint8_t * packet, uint32_t length, IP_Port source) +static int handle_NATping(uint8_t * packet, uint32_t length, IP_Port source) { if (length < crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + ENCRYPTION_PADDING && length > MAX_DATA_SIZE + ENCRYPTION_PADDING)