From b16af69d9252faf730d12d3a452bcd76b2cc686f Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sun, 13 Apr 2014 20:40:48 -0400 Subject: TCP_client pretty much done? Now next step is integrating it in tox. Added TCP server functionality to bootstrap server (define TCP_RELAY_ENABLED to enable it.) --- other/DHT_bootstrap.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'other') diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 291d6589..50d473a9 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -31,6 +31,10 @@ #include "../toxcore/friend_requests.h" #include "../toxcore/util.h" +#ifdef TCP_RELAY_ENABLED +#include "../toxcore/TCP_server.h" +#endif + #include "../testing/misc_tools.c" #ifdef DHT_NODE_EXTRA_PACKETS @@ -129,6 +133,18 @@ int main(int argc, char *argv[]) printf("Public key: "); uint32_t i; +#ifdef TCP_RELAY_ENABLED +#define NUM_PORTS 3 + uint16_t ports[NUM_PORTS] = {443, 3389, PORT}; + TCP_Server *tcp_s = new_TCP_server(ipv6enabled, NUM_PORTS, ports, dht->self_public_key, dht->self_secret_key, onion); + + if (tcp_s == NULL) { + printf("TCP server failed to initialize.\n"); + exit(1); + } + +#endif + FILE *file; file = fopen("PUBLIC_ID.txt", "w"); @@ -177,6 +193,9 @@ int main(int argc, char *argv[]) last_LANdiscovery = unix_time(); } +#ifdef TCP_RELAY_ENABLED + do_TCP_server(tcp_s); +#endif networking_poll(dht->c->lossless_udp->net); c_sleep(1); -- cgit v1.2.3 From 6578d930f8b3d4961c33283d1ece981af5c41586 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 16 Apr 2014 07:19:40 -0400 Subject: DHT_bootstrap.c now has TCP server functionality enabled. Fixed a regression (same type as last commit). --- other/DHT_bootstrap.c | 2 ++ toxcore/onion_client.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'other') diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 50d473a9..738c2a0c 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -31,6 +31,8 @@ #include "../toxcore/friend_requests.h" #include "../toxcore/util.h" +#define TCP_RELAY_ENABLED + #ifdef TCP_RELAY_ENABLED #include "../toxcore/TCP_server.h" #endif diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 439a80c7..ca3ec560 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -660,11 +660,16 @@ static int send_fakeid_announce(Onion_Client *onion_c, uint16_t friend_num, uint memcpy(data + 1 + sizeof(uint64_t), onion_c->dht->self_public_key, crypto_box_PUBLICKEYBYTES); Node_format nodes[MAX_SENT_NODES]; uint16_t num_nodes = closelist_nodes(onion_c->dht, nodes, MAX_SENT_NODES); - int nodes_len = pack_nodes(data + FAKEID_DATA_MIN_LENGTH, FAKEID_DATA_MAX_LENGTH - FAKEID_DATA_MIN_LENGTH, nodes, + + int nodes_len = 0; + + if (num_nodes != 0) { + nodes_len = pack_nodes(data + FAKEID_DATA_MIN_LENGTH, FAKEID_DATA_MAX_LENGTH - FAKEID_DATA_MIN_LENGTH, nodes, num_nodes); - if (nodes_len <= 0) - return -1; + if (nodes_len <= 0) + return -1; + } int num1 = -1, num2 = -1; -- cgit v1.2.3 From cf33c2f9ad98edc50d50e018e214bb0b6180d96d Mon Sep 17 00:00:00 2001 From: "Carlos E. Garcia" Date: Wed, 16 Apr 2014 12:08:44 -0400 Subject: multiple spelling fixes --- docs/Group-Chats.md | 8 ++++---- docs/Prevent_Tracking.txt | 5 +++-- docs/TCP_Network.txt | 4 ++-- docs/av_api.md | 2 +- docs/updates/Crypto.md | 2 +- m4/pkg.m4 | 2 +- other/DHTnodes | 2 +- other/fun/cracker.c | 2 +- toxav/msi.c | 24 ++++++++++++------------ toxav/msi.h | 6 +++--- toxav/phone.c | 4 ++-- toxcore/DHT.c | 18 +++++++++--------- toxcore/DHT.h | 2 +- toxcore/Lossless_UDP.c | 2 +- toxcore/Lossless_UDP.h | 2 +- toxcore/Messenger.c | 2 +- toxcore/Messenger.h | 4 ++-- toxcore/TCP_server.c | 2 +- toxcore/TCP_server.h | 2 +- toxcore/assoc.c | 2 +- toxcore/net_crypto.c | 2 +- toxcore/net_crypto.h | 2 +- toxcore/onion_client.c | 6 +++--- toxcore/onion_client.h | 4 ++-- toxcore/tox.c | 2 +- toxcore/tox.h | 10 +++++----- 26 files changed, 62 insertions(+), 61 deletions(-) (limited to 'other') diff --git a/docs/Group-Chats.md b/docs/Group-Chats.md index e318613d..5e00b550 100644 --- a/docs/Group-Chats.md +++ b/docs/Group-Chats.md @@ -21,18 +21,18 @@ See DHT, currently uses the IPv6 Node_format. Get nodes (Request): Packet contents: ``` -[char with a value of 48][Bob's (The reciever's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][Random nonce (24 bytes)][Encrypted with the nonce, private key of the sender and public key of the reciever:[char with a value of 48][random 8 byte (ping_id)] +[char with a value of 48][Bob's (The receiver's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][Random nonce (24 bytes)][Encrypted with the nonce, private key of the sender and public key of the receiver:[char with a value of 48][random 8 byte (ping_id)] ``` Valid replies: a send_nodes packet Send_nodes (response): ``` -[char with a value of 48][Bob's (The reciever's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][Random nonce (24 bytes)][Encrypted with the nonce, private key of the sender and public key of the reciever:[char with a value of 49][random 8 byte (ping_id)][Nodes in node format, length=40 * (number of nodes (maximum of 6 nodes)) bytes]] +[char with a value of 48][Bob's (The receiver's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][Random nonce (24 bytes)][Encrypted with the nonce, private key of the sender and public key of the receiver:[char with a value of 49][random 8 byte (ping_id)][Nodes in node format, length=40 * (number of nodes (maximum of 6 nodes)) bytes]] ``` Broadcast packet: ``` -[char with a value of 48][Bob's (The reciever's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][nonce][Encrypted with the nonce, private key of the sender and public key of the reciever:[char with a value of 50][Data to send to everyone]] +[char with a value of 48][Bob's (The receiver's) Public key (client_id) (32 bytes))][Alice's (The sender's) Public key (client_id) (32 bytes)][nonce][Encrypted with the nonce, private key of the sender and public key of the receiver:[char with a value of 50][Data to send to everyone]] ``` @@ -68,4 +68,4 @@ Ban a peer [uint8_t message[messagelen]] 65 - action (/me) -[uint8_t message[messagelen]] \ No newline at end of file +[uint8_t message[messagelen]] diff --git a/docs/Prevent_Tracking.txt b/docs/Prevent_Tracking.txt index c5f33e96..d170103f 100644 --- a/docs/Prevent_Tracking.txt +++ b/docs/Prevent_Tracking.txt @@ -110,7 +110,8 @@ encrypted with that temporary private key and the nonce and the public key from (if Node D contains the ret data for the node, it sends the stuff in this packet as a data to route response packet to the right node) The data in the previous packet is in format: [real public key of sender] -encrypted with real private key of the sender, the nonce in the data packet and the real public key of the reciever:[[uint8_t id][data (optional)]] +encrypted with real private key of the sender, the nonce in the data packet and +the real public key of the receiver:[[uint8_t id][data (optional)]] Data sent to us: announce response packet: @@ -153,5 +154,5 @@ Data packets: To tell our friend what our DHT public key is so that he can connect to us we send a data packet with id 156 and the data being:[uint64_t (in network byte order) no_replay, the packet will only be -accepted if this number is bigger than the last one recieved] [our dht public key][Node_Format * ( +accepted if this number is bigger than the last one received] [our dht public key][Node_Format * ( maximum of 8) nodes closest to us so that the friend can find us faster] diff --git a/docs/TCP_Network.txt b/docs/TCP_Network.txt index 775ccc88..9841329c 100644 --- a/docs/TCP_Network.txt +++ b/docs/TCP_Network.txt @@ -81,7 +81,7 @@ received client sent the server the public key and the public key we sent to the client, the next with base nonce + 1...) -The connection is set to an unconfirmed state until a packet is recieved and +The connection is set to an unconfirmed state until a packet is received and decrypted correctly using the information in the handshake. each packet sent to/from the server has an id (the first byte of the plain text @@ -135,7 +135,7 @@ responses must be sent to the proper client. Ping responses must have the same ping_id as the request. -If the server recieves a ping packet he must respond with a ping response. +If the server receives a ping packet he must respond with a ping response. The server will send a ping packet to clients every 30 seconds, they have 30 seconds to respond, if they don't the connection is deleted. diff --git a/docs/av_api.md b/docs/av_api.md index 17930144..2f536ade 100644 --- a/docs/av_api.md +++ b/docs/av_api.md @@ -34,7 +34,7 @@ msi_session_t* - pointer to a newly created msi session handler. ###msi_session_t reference: How to handle msi session: -Controling is done via callbacks and action handlers. +Controlling is done via callbacks and action handlers. First register callbacks for every state/action received and make sure NOT TO PLACE SOMETHING LIKE LOOPS THAT TAKES A LOT OF TIME TO EXECUTE; every callback is being called directly from event loop. You can find examples in phone.c. diff --git a/docs/updates/Crypto.md b/docs/updates/Crypto.md index a6c701d3..939c15e2 100644 --- a/docs/updates/Crypto.md +++ b/docs/updates/Crypto.md @@ -74,4 +74,4 @@ Crypto request packets The encrypted message is encrypted with crypto_box() (using Bobs public key, Alice's private key and the nonce (randomly generated 24 bytes)) and is a message from Alice in which she tells Bob who she is. -Each node can route the request to the reciever if they are connected to him. This is to bypass bad NATs. +Each node can route the request to the receiver if they are connected to him. This is to bypass bad NATs. diff --git a/m4/pkg.m4 b/m4/pkg.m4 index f26f84c9..260e1fb9 100644 --- a/m4/pkg.m4 +++ b/m4/pkg.m4 @@ -53,7 +53,7 @@ fi[]dnl # to PKG_CHECK_MODULES(), but does not set variables or print errors. # # Please remember that m4 expands AC_REQUIRE([PKG_PROG_PKG_CONFIG]) -# only at the first occurence in configure.ac, so if the first place +# only at the first occurrence in configure.ac, so if the first place # it's called might be skipped (such as if it is within an "if", you # have to call PKG_CHECK_EXISTS manually # -------------------------------------------------------------- diff --git a/other/DHTnodes b/other/DHTnodes index 35509931..0abdbbd9 100644 --- a/other/DHTnodes +++ b/other/DHTnodes @@ -1,3 +1,3 @@ -As maintaining 2 seperate lists of the same information seemed redundant, this list has been phased out. +As maintaining 2 separate lists of the same information seemed redundant, this list has been phased out. For a current DHT node list please visit http://wiki.tox.im/nodes diff --git a/other/fun/cracker.c b/other/fun/cracker.c index 9921df31..7b7000de 100644 --- a/other/fun/cracker.c +++ b/other/fun/cracker.c @@ -32,7 +32,7 @@ void print_key(uint8_t *client_id) int main(int argc, char *argv[]) { if (argc < 2) { - printf("usage: ./cracker public_key(or beggining of one in hex format)\n"); + printf("usage: ./cracker public_key(or beginning of one in hex format)\n"); return 0; } diff --git a/toxav/msi.c b/toxav/msi.c index 26e301d3..3ffb44b2 100755 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -206,7 +206,7 @@ static inline__ const uint8_t *stringify_response ( MSIResponse response ) #define ON_HEADER(iterator, header, descriptor, size_const) \ ( memcmp(iterator, descriptor, size_const) == 0){ /* Okay */ \ - iterator += size_const; /* Set iterator at begining of value part */ \ + iterator += size_const; /* Set iterator at beginning of value part */ \ if ( *iterator != value_byte ) { assert(0); return -1; }\ iterator ++;\ uint16_t _value_size = (uint16_t) *(iterator ) << 8 | \ @@ -225,7 +225,7 @@ static inline__ const uint8_t *stringify_response ( MSIResponse response ) * @param msg Container. * @param data The data. * @return int - * @retval -1 Error occured. + * @retval -1 Error occurred. * @retval 0 Success. */ int parse_raw_data ( MSIMessage *msg, const uint8_t *data, uint16_t length ) @@ -338,7 +338,7 @@ void free_message ( MSIMessage *msg ) * @param type Request or response. * @param type_id Type of request/response. * @return MSIMessage* Created message. - * @retval NULL Error occured. + * @retval NULL Error occurred. */ MSIMessage *msi_new_message ( uint8_t type, const uint8_t *type_id ) { @@ -367,7 +367,7 @@ MSIMessage *msi_new_message ( uint8_t type, const uint8_t *type_id ) * * @param data The data. * @return MSIMessage* Parsed message. - * @retval NULL Error occured. + * @retval NULL Error occurred. */ MSIMessage *parse_message ( const uint8_t *data, uint16_t length ) { @@ -422,7 +422,7 @@ uint8_t *append_header_to_string ( *dest = field_byte; /* Set the first byte */ - uint8_t *_getback_byte = dest + 1; /* remeber the byte we were on */ + uint8_t *_getback_byte = dest + 1; /* remember the byte we were on */ dest += 3; /* swith to 4th byte where field value starts */ /* Now set the field value and calculate it's length */ @@ -604,7 +604,7 @@ static inline__ const uint8_t *stringify_error_code ( MSICallError error_code ) * @param msg The message. * @param to Where to. * @return int - * @retval -1 Error occured. + * @retval -1 Error occurred. * @retval 0 Success. */ int send_message ( MSISession *session, MSIMessage *msg, uint32_t to ) @@ -721,7 +721,7 @@ int handle_error ( MSISession *session, MSICallError errid, uint32_t to ) * @param msg The message. * @return int * @retval -1 No error. - * @retval 0 Error occured and response sent. + * @retval 0 Error occurred and response sent. */ int has_call_error ( MSISession *session, MSIMessage *msg ) { @@ -830,7 +830,7 @@ MSICall *init_call ( MSISession *session, int peers, int ringing_timeout ) * * @param session Control session. * @return int - * @retval -1 Error occured. + * @retval -1 Error occurred. * @retval 0 Success. */ int terminate_call ( MSISession *session ) @@ -882,7 +882,7 @@ int handle_recv_invite ( MSISession *session, MSIMessage *msg ) * B calls A. Who has advantage is set bey calculating * 'bigger' Call id and then that call id is being used in * future. User with 'bigger' Call id has the advantage - * as in he will wait the reponse from the other. + * as in he will wait the response from the other. */ if ( call_id_bigger (session->call->id, msg->callid.header_value) == 1 ) { /* Peer has advantage */ @@ -1250,7 +1250,7 @@ void msi_register_callback ( MSICallback callback, MSICallbackID id, void* userd * @param messenger Tox* object. * @param user_agent User agent, i.e. 'Venom'; 'QT-gui' * @return MSISession* The created session. - * @retval NULL Error occured. + * @retval NULL Error occurred. */ MSISession *msi_init_session ( Messenger* messenger ) { @@ -1351,7 +1351,7 @@ int msi_invite ( MSISession *session, MSICallType call_type, uint32_t rngsec, ui * * @param session Control session. * @return int - * @retval -1 Error occured. + * @retval -1 Error occurred. * @retval 0 Success. */ int msi_hangup ( MSISession *session ) @@ -1485,4 +1485,4 @@ int msi_stopcall ( MSISession *session ) terminate_call ( session ); return 0; -} \ No newline at end of file +} diff --git a/toxav/msi.h b/toxav/msi.h index 37fc07a3..39a9c792 100755 --- a/toxav/msi.h +++ b/toxav/msi.h @@ -82,7 +82,7 @@ typedef struct _MSICall { /* Call info structure */ int ringing_timer_id; /* Timer id for ringing timeout */ pthread_mutex_t mutex; /* It's to be assumed that call will have - * seperate thread so add mutex + * separate thread so add mutex */ uint32_t *peers; uint16_t peer_count; @@ -152,7 +152,7 @@ void msi_register_callback(MSICallback callback, MSICallbackID id, void* userdat * * @param messenger Tox* object. * @return MSISession* The created session. - * @retval NULL Error occured. + * @retval NULL Error occurred. */ MSISession *msi_init_session ( Messenger *messenger ); @@ -183,7 +183,7 @@ int msi_invite ( MSISession *session, MSICallType call_type, uint32_t rngsec, ui * * @param session Control session. * @return int - * @retval -1 Error occured. + * @retval -1 Error occurred. * @retval 0 Success. */ int msi_hangup ( MSISession *session ); diff --git a/toxav/phone.c b/toxav/phone.c index 2b33f7e9..74f743f7 100755 --- a/toxav/phone.c +++ b/toxav/phone.c @@ -5,7 +5,7 @@ * This file is for testing/reference purposes only, hence * it is _poorly_ designed and it does not fully reflect the * quaility of msi nor rtp. Although toxmsi* and toxrtp* are tested - * there is always possiblity of crashes. If crash occures, + * there is always possibility of crashes. If crash occures, * contact me ( mannol ) on either irc channel #tox-dev @ freenode.net:6667 * or eniz_vukovic@hotmail.com * @@ -612,7 +612,7 @@ void *decode_video_thread(void *arg) } //else { - /* TODO: request the sender to create a new i-frame immediatly */ + /* TODO: request the sender to create a new i-frame immediately */ //printf("Bad video packet\n"); //} //} diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 1089e2ff..ad496f7d 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -164,7 +164,7 @@ void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, uint8_t *secr } /* Copy shared_key to decrypt DHT packet from client_id into shared_key - * for packets that we recieve. + * for packets that we receive. */ void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, uint8_t *client_id) { @@ -600,7 +600,7 @@ static int replace_possible_bad( Client_data *list, sort_list(list, length, comp_client_id); - /* TODO: decide if the folowing lines should stay commented or not. + /* TODO: decide if the following lines should stay commented or not. if (id_closest(comp_client_id, list[0].client_id, client_id) == 1) return 0;*/ @@ -861,20 +861,20 @@ static int getnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *cli uint64_t temp_time = unix_time(); memcpy(plain_message, &temp_time, sizeof(temp_time)); - Node_format reciever; - memcpy(reciever.client_id, public_key, CLIENT_ID_SIZE); - reciever.ip_port = ip_port; - memcpy(plain_message + sizeof(temp_time), &reciever, sizeof(reciever)); + Node_format receiver; + memcpy(receiver.client_id, public_key, CLIENT_ID_SIZE); + receiver.ip_port = ip_port; + memcpy(plain_message + sizeof(temp_time), &receiver, sizeof(receiver)); if (sendback_node != NULL) - memcpy(plain_message + sizeof(temp_time) + sizeof(reciever), sendback_node, sizeof(Node_format)); + memcpy(plain_message + sizeof(temp_time) + sizeof(receiver), sendback_node, sizeof(Node_format)); else - memset(plain_message + sizeof(temp_time) + sizeof(reciever), 0, sizeof(Node_format)); + memset(plain_message + sizeof(temp_time) + sizeof(receiver), 0, sizeof(Node_format)); int len_m = encrypt_data_symmetric(dht->secret_symmetric_key, nonce, plain_message, - sizeof(temp_time) + sizeof(reciever) + sizeof(Node_format), + sizeof(temp_time) + sizeof(receiver) + sizeof(Node_format), encrypted_message + crypto_secretbox_NONCEBYTES); if (len_m != NODES_ENCRYPTED_MESSAGE_LENGTH - crypto_secretbox_NONCEBYTES) diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 3d2722f8..81f1f560 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h @@ -192,7 +192,7 @@ typedef struct { void get_shared_key(Shared_Keys *shared_keys, uint8_t *shared_key, uint8_t *secret_key, uint8_t *client_id); /* Copy shared_key to decrypt DHT packet from client_id into shared_key - * for packets that we recieve. + * for packets that we receive. */ void DHT_get_shared_key_recv(DHT *dht, uint8_t *shared_key, uint8_t *client_id); diff --git a/toxcore/Lossless_UDP.c b/toxcore/Lossless_UDP.c index c0db8a10..9a7cdcb2 100644 --- a/toxcore/Lossless_UDP.c +++ b/toxcore/Lossless_UDP.c @@ -292,7 +292,7 @@ static int new_inconnection(Lossless_UDP *ludp, IP_Port ip_port) } /* - * return an integer corresponding to the next connection in our incoming connection list with at least numpackets in the recieve queue. + * return an integer corresponding to the next connection in our incoming connection list with at least numpackets in the receive queue. * return -1 if there are no new incoming connections in the list. */ int incoming_connection(Lossless_UDP *ludp, uint32_t numpackets) diff --git a/toxcore/Lossless_UDP.h b/toxcore/Lossless_UDP.h index b23d602a..01ce05f9 100644 --- a/toxcore/Lossless_UDP.h +++ b/toxcore/Lossless_UDP.h @@ -156,7 +156,7 @@ int new_connection(Lossless_UDP *ludp, IP_Port ip_port); int getconnection_id(Lossless_UDP *ludp, IP_Port ip_port); /* - * return an integer corresponding to the next connection in our incoming connection list with at least numpackets in the recieve queue. + * return an integer corresponding to the next connection in our incoming connection list with at least numpackets in the receive queue. * return -1 if there are no new incoming connections in the list. */ int incoming_connection(Lossless_UDP *ludp, uint32_t numpackets); diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index db5390c0..752b164d 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -2172,7 +2172,7 @@ void do_friends(Messenger *m) } if (m->friendlist[i].ping_lastrecv + FRIEND_CONNECTION_TIMEOUT < temp_time) { - /* If we stopped recieving ping packets, kill it. */ + /* If we stopped receiving ping packets, kill it. */ crypto_kill(m->net_crypto, m->friendlist[i].crypt_connection_id); m->friendlist[i].crypt_connection_id = -1; set_friend_status(m, i, FRIEND_CONFIRMED); diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index c29b6594..43cc48f9 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h @@ -90,7 +90,7 @@ enum { /* Interval between the sending of ping packets. */ #define FRIEND_PING_INTERVAL 5 -/* If no packets are recieved from friend in this time interval, kill the connection. */ +/* If no packets are received from friend in this time interval, kill the connection. */ #define FRIEND_CONNECTION_TIMEOUT (FRIEND_PING_INTERVAL * 2) /* USERSTATUS - @@ -354,7 +354,7 @@ int setname(Messenger *m, uint8_t *name, uint16_t length); /* * Get your nickname. - * m - The messanger context to use. + * m - The messenger context to use. * name needs to be a valid memory location with a size of at least MAX_NAME_LENGTH bytes. * * return length of the name. diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 410111f4..7ad5ff7e 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -224,7 +224,7 @@ int read_TCP_packet(sock_t sock, uint8_t *data, uint16_t length) return -1; } -/* return length of recieved packet on success. +/* return length of received packet on success. * return 0 if could not read any packet. * return -1 on failure (connection must be killed). */ diff --git a/toxcore/TCP_server.h b/toxcore/TCP_server.h index 498b1147..5046b8eb 100644 --- a/toxcore/TCP_server.h +++ b/toxcore/TCP_server.h @@ -140,7 +140,7 @@ uint16_t read_TCP_length(sock_t sock); */ int read_TCP_packet(sock_t sock, uint8_t *data, uint16_t length); -/* return length of recieved packet on success. +/* return length of received packet on success. * return 0 if could not read any packet. * return -1 on failure (connection must be killed). */ diff --git a/toxcore/assoc.c b/toxcore/assoc.c index 2c1f0bad..50bc3a3e 100644 --- a/toxcore/assoc.c +++ b/toxcore/assoc.c @@ -28,7 +28,7 @@ * Candidates are kept in buckets of hash tables. The hash * function is calculated from the client_id. Up to * HASH_COLLIDE_COUNT alternative positions are tried if - * the inital position is already used by a different entry. + * the initial position is already used by a different entry. * The collision function is multiplicative, not additive. * * A new candidate can bump an existing candidate, if it is diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 17d2e8ff..6e5b8c82 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -284,7 +284,7 @@ int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uin /* Create a request to peer. * send_public_key and send_secret_key are the pub/secret keys of the sender. - * recv_public_key is public key of reciever. + * recv_public_key is public key of receiver. * packet must be an array of MAX_DATA_SIZE big. * Data represents the data we send with the request with length being the length of the data. * request_id is the id of the request (32 = friend request, 254 = ping request). diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index da776527..86668058 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h @@ -162,7 +162,7 @@ int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uin /* Create a request to peer. * send_public_key and send_secret_key are the pub/secret keys of the sender. - * recv_public_key is public key of reciever. + * recv_public_key is public key of receiver. * packet must be an array of MAX_DATA_SIZE big. * Data represents the data we send with the request with length being the length of the data. * request_id is the id of the request (32 = friend request, 254 = ping request). diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 329b1d13..c9f60b2b 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -513,9 +513,9 @@ static int handle_fakeid_announce(void *object, uint8_t *source_pubkey, uint8_t return 0; } /* Send data of length length to friendnum. - * This data will be recieved by the friend using the Onion_Data_Handlers callbacks. + * This data will be received by the friend using the Onion_Data_Handlers callbacks. * - * Even if this function succeeds, the friend might not recieve any data. + * Even if this function succeeds, the friend might not receive any data. * * return the number of packets sent on success * return -1 on failure. @@ -578,7 +578,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, uint8_t *data, uint32 /* Try to send the fakeid via the DHT instead of onion * - * Even if this function succeeds, the friend might not recieve any data. + * Even if this function succeeds, the friend might not receive any data. * * return the number of packets sent on success * return -1 on failure. diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 4045cc0e..9c89afe5 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h @@ -172,9 +172,9 @@ int onion_getfriendip(Onion_Client *onion_c, int friend_num, IP_Port *ip_port); /* Send data of length length to friendnum. - * This data will be recieved by the friend using the Onion_Data_Handlers callbacks. + * This data will be received by the friend using the Onion_Data_Handlers callbacks. * - * Even if this function succeeds, the friend might not recieve any data. + * Even if this function succeeds, the friend might not receive any data. * * return the number of packets sent on success * return -1 on failure. diff --git a/toxcore/tox.c b/toxcore/tox.c index c07473dd..ec21407f 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -186,7 +186,7 @@ int tox_set_name(Tox *tox, uint8_t *name, uint16_t length) } /* Get your nickname. - * m - The messanger context to use. + * m - The messenger context to use. * name - Pointer to a string for the name. (must be at least MAX_NAME_LENGTH) * * return length of the name. diff --git a/toxcore/tox.h b/toxcore/tox.h index d94c0e13..c344d366 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -210,7 +210,7 @@ int tox_set_name(Tox *tox, uint8_t *name, uint16_t length); /* * Get your nickname. - * m - The messanger context to use. + * m - The messenger context to use. * name - needs to be a valid memory location with a size of at least MAX_NAME_LENGTH (128) bytes. * * return length of name. @@ -515,11 +515,11 @@ uint32_t tox_get_chatlist(Tox *tox, int *out_list, uint32_t list_size); * tox_file_data_remaining(...) can be used to know how many bytes are left to send/receive. * * If the connection breaks during file sending (The other person goes offline without pausing the sending and then comes back) - * the reciever must send a control packet with receive_send == 0 message_id = TOX_FILECONTROL_RESUME_BROKEN and the data being - * a uint64_t (in host byte order) containing the number of bytes recieved. + * the receiver must send a control packet with receive_send == 0 message_id = TOX_FILECONTROL_RESUME_BROKEN and the data being + * a uint64_t (in host byte order) containing the number of bytes received. * - * If the sender recieves this packet, he must send a control packet with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT - * then he must start sending file data from the position (data , uint64_t in host byte order) recieved in the TOX_FILECONTROL_RESUME_BROKEN packet. + * If the sender receives this packet, he must send a control packet with receive_send == 1 and control_type == TOX_FILECONTROL_ACCEPT + * then he must start sending file data from the position (data , uint64_t in host byte order) received in the TOX_FILECONTROL_RESUME_BROKEN packet. * * More to come... */ -- cgit v1.2.3 From 0559904ea28c026baed4a62ff39b8280cd63e58a Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 23 Apr 2014 12:29:24 -0400 Subject: Updated some files so that they could build with latest core. Fixed some issues. --- auto_tests/onion_test.c | 34 +++++++++++++++++----------------- other/DHT_bootstrap.c | 23 +++++++++-------------- testing/DHT_test.c | 6 ++---- toxcore/DHT.h | 4 ++++ toxcore/net_crypto.h | 3 --- toxcore/onion_announce.c | 2 +- toxcore/onion_client.c | 4 ++-- 7 files changed, 35 insertions(+), 41 deletions(-) (limited to 'other') diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index cd060b1f..b8145cc2 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -80,7 +80,7 @@ static int handle_test_3(void *object, IP_Port source, uint8_t *packet, uint32_t uint8_t plain[1 + crypto_hash_sha256_BYTES]; //print_client_id(packet, length); - int len = decrypt_data(test_3_pub_key, onion->dht->c->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, + int len = decrypt_data(test_3_pub_key, onion->dht->self_secret_key, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH, packet + 1 + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + crypto_box_NONCEBYTES, 1 + crypto_hash_sha256_BYTES + crypto_box_MACBYTES, plain); @@ -111,7 +111,7 @@ static int handle_test_4(void *object, IP_Port source, uint8_t *packet, uint32_t if (memcmp(nonce, packet + 1, crypto_box_NONCEBYTES) != 0) return 1; - int len = decrypt_data(packet + 1 + crypto_box_NONCEBYTES, onion->dht->c->self_secret_key, packet + 1, + int len = decrypt_data(packet + 1 + crypto_box_NONCEBYTES, onion->dht->self_secret_key, packet + 1, packet + 1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES, sizeof("Install gentoo") + crypto_box_MACBYTES, plain); if (len == -1) @@ -129,8 +129,8 @@ START_TEST(test_basic) IP ip; ip_init(&ip, 1); ip.ip6.uint8[15] = 1; - Onion *onion1 = new_onion(new_DHT(new_net_crypto(new_networking(ip, 34567)))); - Onion *onion2 = new_onion(new_DHT(new_net_crypto(new_networking(ip, 34568)))); + Onion *onion1 = new_onion(new_DHT(new_networking(ip, 34567))); + Onion *onion2 = new_onion(new_DHT(new_networking(ip, 34568))); ck_assert_msg((onion1 != NULL) && (onion2 != NULL), "Onion failed initializing."); networking_registerhandler(onion2->net, 'I', &handle_test_1, onion2); @@ -177,9 +177,9 @@ START_TEST(test_basic) uint8_t zeroes[64] = {0}; randombytes(sb_data, sizeof(sb_data)); memcpy(test_3_pub_key, nodes[3].client_id, crypto_box_PUBLICKEYBYTES); - ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->c->self_public_key, - onion1->dht->c->self_secret_key, - zeroes, onion1->dht->c->self_public_key, onion1->dht->c->self_public_key, sb_data); + ret = send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, + onion1->dht->self_secret_key, + zeroes, onion1->dht->self_public_key, onion1->dht->self_public_key, sb_data); ck_assert_msg(ret == 0, "Failed to create/send onion announce_request packet."); handled_test_3 = 0; @@ -193,10 +193,10 @@ START_TEST(test_basic) memcpy(onion2_a->entries[1].public_key, onion2->dht->self_public_key, crypto_box_PUBLICKEYBYTES); onion2_a->entries[1].time = unix_time(); networking_registerhandler(onion1->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_test_4, onion1); - send_announce_request(onion1->net, &path, nodes[3], onion1->dht->c->self_public_key, onion1->dht->c->self_secret_key, - test_3_ping_id, onion1->dht->c->self_public_key, onion1->dht->c->self_public_key, sb_data); + send_announce_request(onion1->net, &path, nodes[3], onion1->dht->self_public_key, onion1->dht->self_secret_key, + test_3_ping_id, onion1->dht->self_public_key, onion1->dht->self_public_key, sb_data); - while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->c->self_public_key, + while (memcmp(onion2_a->entries[ONION_ANNOUNCE_MAX_ENTRIES - 2].public_key, onion1->dht->self_public_key, crypto_box_PUBLICKEYBYTES) != 0) { do_onion(onion1); do_onion(onion2); @@ -204,12 +204,12 @@ START_TEST(test_basic) } c_sleep(1000); - Onion *onion3 = new_onion(new_DHT(new_net_crypto(new_networking(ip, 34569)))); + Onion *onion3 = new_onion(new_DHT(new_networking(ip, 34569))); ck_assert_msg((onion3 != NULL), "Onion failed initializing."); new_nonce(nonce); - ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->c->self_public_key, - onion1->dht->c->self_public_key, + ret = send_data_request(onion3->net, &path, nodes[3].ip_port, onion1->dht->self_public_key, + onion1->dht->self_public_key, nonce, (uint8_t *)"Install gentoo", sizeof("Install gentoo")); ck_assert_msg(ret == 0, "Failed to create/send onion data_request packet."); handled_test_4 = 0; @@ -234,10 +234,10 @@ Onions *new_onions(uint16_t port) ip_init(&ip, 1); ip.ip6.uint8[15] = 1; Onions *on = malloc(sizeof(Onions)); - DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port))); + DHT *dht = new_DHT(new_networking(ip, port)); on->onion = new_onion(dht); on->onion_a = new_onion_announce(dht); - on->onion_c = new_onion_client(dht); + on->onion_c = new_onion_client(new_net_crypto(dht)); if (on->onion && on->onion_a && on->onion_c) return on; @@ -298,8 +298,8 @@ START_TEST(test_announce) c_sleep(50); } - onion_addfriend(onions[7]->onion_c, onions[37]->onion->dht->c->self_public_key); - int frnum = onion_addfriend(onions[37]->onion_c, onions[7]->onion->dht->c->self_public_key); + onion_addfriend(onions[7]->onion_c, onions[37]->onion_c->c->self_public_key); + int frnum = onion_addfriend(onions[37]->onion_c, onions[7]->onion_c->c->self_public_key); int ok = -1; diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 738c2a0c..462360c3 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -75,11 +75,12 @@ void manage_keys(DHT *dht) exit(1); } - load_keys(dht->c, keys); + memcpy(dht->self_public_key, keys, crypto_box_PUBLICKEYBYTES); + memcpy(dht->self_secret_key, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES); printf("Keys loaded successfully.\n"); } else { - new_keys(dht->c); - save_keys(dht->c, keys); + memcpy(keys, dht->self_public_key, crypto_box_PUBLICKEYBYTES); + memcpy(keys + crypto_box_PUBLICKEYBYTES, dht->self_secret_key, crypto_box_SECRETKEYBYTES); keys_file = fopen("key", "w"); if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) { @@ -113,7 +114,7 @@ int main(int argc, char *argv[]) IP ip; ip_init(&ip, ipv6enabled); - DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); + DHT *dht = new_DHT(new_networking(ip, PORT)); Onion *onion = new_onion(dht); Onion_Announce *onion_a = new_onion_announce(dht); @@ -129,9 +130,6 @@ int main(int argc, char *argv[]) perror("Initialization"); manage_keys(dht); - /* We want our DHT public key to be the same as our internal one since this is a bootstrap node */ - memcpy(dht->self_public_key, dht->c->self_public_key, crypto_box_PUBLICKEYBYTES); - memcpy(dht->self_secret_key, dht->c->self_secret_key, crypto_box_SECRETKEYBYTES); printf("Public key: "); uint32_t i; @@ -151,17 +149,14 @@ int main(int argc, char *argv[]) file = fopen("PUBLIC_ID.txt", "w"); for (i = 0; i < 32; i++) { - if (dht->c->self_public_key[i] < 16) - printf("0"); - - printf("%hhX", dht->c->self_public_key[i]); - fprintf(file, "%hhX", dht->c->self_public_key[i]); + printf("%02hhX", dht->self_public_key[i]); + fprintf(file, "%02hhX", dht->self_public_key[i]); } fclose(file); printf("\n"); - printf("Port: %u\n", ntohs(dht->c->lossless_udp->net->port)); + printf("Port: %u\n", ntohs(dht->net->port)); if (argc > argvoffset + 3) { printf("Trying to bootstrap into the network...\n"); @@ -198,7 +193,7 @@ int main(int argc, char *argv[]) #ifdef TCP_RELAY_ENABLED do_TCP_server(tcp_s); #endif - networking_poll(dht->c->lossless_udp->net); + networking_poll(dht->net); c_sleep(1); } diff --git a/testing/DHT_test.c b/testing/DHT_test.c index 3f8b58bd..2636ed02 100644 --- a/testing/DHT_test.c +++ b/testing/DHT_test.c @@ -187,9 +187,7 @@ int main(int argc, char *argv[]) IP ip; ip_init(&ip, ipv6enabled); - DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); - - new_keys(dht->c); + DHT *dht = new_DHT(new_networking(ip, PORT)); printf("OUR ID: "); uint32_t i; @@ -245,7 +243,7 @@ int main(int argc, char *argv[]) } } */ - networking_poll(dht->c->lossless_udp->net); + networking_poll(dht->net); print_clientlist(dht); print_friendlist(dht); diff --git a/toxcore/DHT.h b/toxcore/DHT.h index c08b498c..c0731a3a 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h @@ -337,6 +337,10 @@ int route_packet(DHT *dht, uint8_t *client_id, uint8_t *packet, uint32_t length) */ int route_tofriend(DHT *dht, uint8_t *friend_id, uint8_t *packet, uint32_t length); +/* Function to handle crypto packets. + */ +void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_callback cb, void *object); + /* NAT PUNCHING FUNCTIONS */ /* Puts all the different ips returned by the nodes for a friend_id into array ip_portlist. diff --git a/toxcore/net_crypto.h b/toxcore/net_crypto.h index ef56b304..b2b9f4f5 100644 --- a/toxcore/net_crypto.h +++ b/toxcore/net_crypto.h @@ -87,9 +87,6 @@ uint32_t crypto_num_free_sendqueue_slots(Net_Crypto *c, int crypt_connection_id) */ int write_cryptpacket(Net_Crypto *c, int crypt_connection_id, uint8_t *data, uint32_t length); -/* Function to call when request beginning with byte is received. */ -void cryptopacket_registerhandler(Net_Crypto *c, uint8_t byte, cryptopacket_handler_callback cb, void *object); - /* Start a secure connection with other peer who has public_key and ip_port. * * return -1 if failure. diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index 1e73aef9..abe72486 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -90,7 +90,7 @@ int send_announce_request(Networking_Core *net, Onion_Path *path, Node_format de int send_data_request(Networking_Core *net, Onion_Path *path, IP_Port dest, uint8_t *public_key, uint8_t *encrypt_public_key, uint8_t *nonce, uint8_t *data, uint16_t length) { - if (DATA_REQUEST_MIN_SIZE + length > ONION_MAX_DATA_SIZE) + if ((unsigned int)DATA_REQUEST_MIN_SIZE + length > ONION_MAX_DATA_SIZE) return -1; uint8_t packet[DATA_REQUEST_MIN_SIZE + length]; diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 35fb4423..ee902d99 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -1007,7 +1007,7 @@ Onion_Client *new_onion_client(Net_Crypto *c) networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_announce_response, onion_c); networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, &handle_data_response, onion_c); oniondata_registerhandler(onion_c, FAKEID_DATA_ID, &handle_fakeid_announce, onion_c); - cryptopacket_registerhandler(onion_c->c, FAKEID_DATA_ID, &handle_dht_fakeid, onion_c); + cryptopacket_registerhandler(onion_c->dht, FAKEID_DATA_ID, &handle_dht_fakeid, onion_c); return onion_c; } @@ -1021,7 +1021,7 @@ void kill_onion_client(Onion_Client *onion_c) networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, NULL, NULL); networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, NULL, NULL); oniondata_registerhandler(onion_c, FAKEID_DATA_ID, NULL, NULL); - cryptopacket_registerhandler(onion_c->c, FAKEID_DATA_ID, NULL, NULL); + cryptopacket_registerhandler(onion_c->dht, FAKEID_DATA_ID, NULL, NULL); memset(onion_c, 0, sizeof(Onion_Client)); free(onion_c); } -- cgit v1.2.3 From 2aa3cdfc6908bd56bc8797017ae1c3a399e73c9f Mon Sep 17 00:00:00 2001 From: irungentoo Date: Wed, 23 Apr 2014 12:47:57 -0400 Subject: Fixed the DHT bootstrap daemon. --- other/bootstrap_daemon/tox_bootstrap_daemon.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'other') diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index 66f6436d..abad7760 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -36,9 +36,9 @@ #include "config.h" #endif -#include "../../toxcore/DHT.h" -#include "../../toxcore/friend_requests.h" +#include "../../toxcore/onion_announce.h" #include "../../toxcore/LAN_discovery.h" +#include "../../toxcore/util.h" #include "../../testing/misc_tools.c" @@ -75,11 +75,12 @@ int manage_keys(DHT *dht, char *keys_file_path) return 0; } - load_keys(dht->c, keys); + memcpy(dht->self_public_key, keys, crypto_box_PUBLICKEYBYTES); + memcpy(dht->self_secret_key, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES); } else { // Otherwise save new keys - new_keys(dht->c); - save_keys(dht->c, keys); + memcpy(keys, dht->self_public_key, crypto_box_PUBLICKEYBYTES); + memcpy(keys + crypto_box_PUBLICKEYBYTES, dht->self_secret_key, crypto_box_SECRETKEYBYTES); keys_file = fopen(keys_file_path, "w"); @@ -92,10 +93,6 @@ int manage_keys(DHT *dht, char *keys_file_path) fclose(keys_file); - // We want our DHT public key to be the same as our internal one since this is a bootstrap node - memcpy(dht->self_public_key, dht->c->self_public_key, crypto_box_PUBLICKEYBYTES); - memcpy(dht->self_secret_key, dht->c->self_secret_key, crypto_box_SECRETKEYBYTES); - return 1; } @@ -351,7 +348,7 @@ int main(int argc, char *argv[]) IP ip; ip_init(&ip, enable_ipv6); - DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port))); + DHT *dht = new_DHT(new_networking(ip, port)); if (dht == NULL) { syslog(LOG_ERR, "Couldn't initialize Tox DHT instance. Exiting.\n"); @@ -384,7 +381,7 @@ int main(int argc, char *argv[]) return 1; } - print_public_key(dht->c->self_public_key); + print_public_key(dht->self_public_key); // Write the PID file FILE *pidf = fopen(pid_file_path, "w"); -- cgit v1.2.3 From ceaeae8cffad13403618c2b4ffaf90d854e36cbe Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sat, 17 May 2014 20:36:16 -0400 Subject: Added TCP server functionality --- other/bootstrap_daemon/conf | 6 ++ other/bootstrap_daemon/tox_bootstrap_daemon.c | 141 ++++++++++++++++++++++++-- 2 files changed, 140 insertions(+), 7 deletions(-) (limited to 'other') diff --git a/other/bootstrap_daemon/conf b/other/bootstrap_daemon/conf index 28e638c1..fb524754 100644 --- a/other/bootstrap_daemon/conf +++ b/other/bootstrap_daemon/conf @@ -20,6 +20,12 @@ enable_ipv6 = false // Automatically bootstrap with nodes on local area network. enable_lan_discovery = true +enable_tcp_relay = true + +// Tox uses 443 and 3389 ports by default, so it's highly recommended to keep +// them +tcp_relay_ports = [443, 3389] + // Any number of nodes the daemon will bootstrap itself from. // Remember to replace the provided example with your own node list. // There is a maintained list of bootstrap nodes on Tox's wiki, if you need it. diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index abad7760..8d3ed94a 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -21,25 +21,33 @@ * */ -#include +// system provided +#include +#include #include +#include #include -#include +// C #include #include -#include -#include #include +// 3rd party +#include + +// ./configure #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include "../../toxcore/onion_announce.h" +// toxcore #include "../../toxcore/LAN_discovery.h" +#include "../../toxcore/onion_announce.h" +#include "../../toxcore/TCP_server.h" #include "../../toxcore/util.h" +// misc #include "../../testing/misc_tools.c" #define DAEMON_NAME "tox_bootstrap_daemon" @@ -52,6 +60,7 @@ #define DEFAULT_PORT 33445 #define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false #define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false +#define DEFAULT_ENABLE_TCP_RELAY 1 // Uses the already existing key or creates one if it didn't exist @@ -96,15 +105,79 @@ int manage_keys(DHT *dht, char *keys_file_path) return 1; } +// Parses tcp relay ports from `cfg` and puts them into `tcp_relay_ports` array +// +// Supposed to be called from get_general_config only +// +// Important: iff `tcp_relay_port_count` > 0, then you are responsible for freeing `tcp_relay_ports` + +void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int *tcp_relay_port_count) +{ + const char *NAME_TCP_RELAY_PORTS = "tcp_relay_ports"; + + *tcp_relay_port_count = 0; + + config_setting_t *ports_array = config_lookup(cfg, NAME_TCP_RELAY_PORTS); + + if (ports_array == NULL) { + syslog(LOG_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS); + return; + } + + if (config_setting_is_array(ports_array) == CONFIG_FALSE) { + syslog(LOG_WARNING, "'%s' setting should be an array. Array syntax: 'setting = [value1, value2, ...]'.\n"); + return; + } + + int config_port_count = config_setting_length(ports_array); + if (config_port_count == 0) { + syslog(LOG_WARNING, "'%s' is empty.\n", NAME_TCP_RELAY_PORTS); + return; + } + + *tcp_relay_ports = malloc(config_port_count * sizeof(uint16_t)); + + config_setting_t *elem; + int i; + + for (i = 0; i < config_port_count; i ++) { + + elem = config_setting_get_elem(ports_array, i); + + if (elem == NULL) { + // it's NULL if `ports_array` is not an array (we have that check ealier) or if `i` is out of range, which should not be + syslog(LOG_WARNING, "Port #%d: Something went wrong while parsing the port. Stopping reading ports.\n", i); + break; + } + + if (config_setting_is_number(elem) == CONFIG_FALSE) { + syslog(LOG_WARNING, "Port #%d: Not a number. Skipping.\n", i); + continue; + } + + (*tcp_relay_ports)[*tcp_relay_port_count] = config_setting_get_int(elem); + if ((*tcp_relay_ports)[i] < 1 || (*tcp_relay_ports)[i] > 65535) { + syslog(LOG_WARNING, "Port #%d: Invalid port value, should be in [1, 65535]. Skipping.\n", i); + continue; + } + + (*tcp_relay_port_count) ++; + } + + // the loop above skips invalid ports, so we adjust the allocated memory size + *tcp_relay_ports = realloc(*tcp_relay_ports, *tcp_relay_port_count * sizeof(uint16_t)); +} + // Gets general config options // // Important: you are responsible for freeing `pid_file_path` and `keys_file_path` +// also, iff `tcp_relay_ports_count` > 0, then you are responsible for freeing `tcp_relay_ports` // // returns 1 on success // 0 on failure, doesn't modify any data pointed by arguments int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, - int *enable_lan_discovery) + int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, int *tcp_relay_port_count) { config_t cfg; @@ -113,6 +186,7 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi const char *NAME_KEYS_FILE_PATH = "keys_file_path"; const char *NAME_ENABLE_IPV6 = "enable_ipv6"; const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery"; + const char *NAME_ENABLE_TCP_RELAY = "enable_tcp_relay"; config_init(&cfg); @@ -169,6 +243,20 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY; } + // Get TCP relay option + if (config_lookup_bool(&cfg, NAME_ENABLE_TCP_RELAY, enable_tcp_relay) == CONFIG_FALSE) { + syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_TCP_RELAY); + syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_TCP_RELAY, + DEFAULT_ENABLE_TCP_RELAY ? "true" : "false"); + *enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY; + } + + if (*enable_tcp_relay) { + parse_tcp_relay_ports_config(&cfg, tcp_relay_ports, tcp_relay_port_count); + } else { + *tcp_relay_port_count = 0; + } + config_destroy(&cfg); syslog(LOG_DEBUG, "Successfully read:\n"); @@ -177,6 +265,19 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi syslog(LOG_DEBUG, "'%s': %d\n", NAME_PORT, *port); syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); + syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false"); + // show info about tcp ports only if tcp relay is enabled + if (*enable_tcp_relay) { + if (*tcp_relay_port_count == 0) { + syslog(LOG_DEBUG, "No TCP ports could be read.\n"); + } else { + syslog(LOG_DEBUG, "Read %d TCP ports:\n", *tcp_relay_port_count); + int i; + for (i = 0; i < *tcp_relay_port_count; i ++) { + syslog(LOG_DEBUG, "Port #%d: %u\n", i, (*tcp_relay_ports)[i]); + } + } + } return 1; } @@ -325,8 +426,11 @@ int main(int argc, char *argv[]) int port; int enable_ipv6; int enable_lan_discovery; + int enable_tcp_relay; + uint16_t *tcp_relay_ports; + int tcp_relay_port_count; - if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_lan_discovery)) { + if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_lan_discovery, &enable_tcp_relay, &tcp_relay_ports, &tcp_relay_port_count)) { syslog(LOG_DEBUG, "General config read successfully\n"); } else { syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path); @@ -374,6 +478,25 @@ int main(int argc, char *argv[]) return 1; } + TCP_Server *tcp_server = NULL; + + if (enable_tcp_relay) { + if (tcp_relay_port_count == 0) { + syslog(LOG_ERR, "No TCP relay ports read. Exiting.\n"); + return 1; + } + + tcp_server = new_TCP_server(enable_ipv6, tcp_relay_port_count, tcp_relay_ports, dht->self_public_key, dht->self_secret_key, onion); + + // tcp_relay_port_count != 0 at this point + free(tcp_relay_ports); + + if (tcp_server == NULL) { + syslog(LOG_ERR, "Couldn't initialize Tox TCP server. Exiting.\n"); + return 1; + } + } + if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) { syslog(LOG_DEBUG, "List of bootstrap nodes read successfully\n"); } else { @@ -443,6 +566,10 @@ int main(int argc, char *argv[]) last_LANdiscovery = unix_time(); } + if (enable_tcp_relay) { + do_TCP_server(tcp_server); + } + networking_poll(dht->net); if (waiting_for_dht_connection && DHT_isconnected(dht)) { -- cgit v1.2.3 From 8be6b0986dadee88c2c7506cfcb41a332127add9 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sat, 17 May 2014 20:49:42 -0400 Subject: Extracted min and max allowed port values into named constants --- other/bootstrap_daemon/tox_bootstrap_daemon.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'other') diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index 8d3ed94a..dce181a4 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -62,6 +62,9 @@ #define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false #define DEFAULT_ENABLE_TCP_RELAY 1 +#define MIN_ALLOWED_PORT 1 +#define MAX_ALLOWED_PORT 65535 + // Uses the already existing key or creates one if it didn't exist // @@ -156,8 +159,8 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int } (*tcp_relay_ports)[*tcp_relay_port_count] = config_setting_get_int(elem); - if ((*tcp_relay_ports)[i] < 1 || (*tcp_relay_ports)[i] > 65535) { - syslog(LOG_WARNING, "Port #%d: Invalid port value, should be in [1, 65535]. Skipping.\n", i); + if ((*tcp_relay_ports)[i] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[i] > MAX_ALLOWED_PORT) { + syslog(LOG_WARNING, "Port #%d: Invalid port value, should be in [%d, %d]. Skipping.\n", i, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); continue; } @@ -359,9 +362,8 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) goto next; } - // not (1 <= port <= 65535) - if (bs_port < 1 || bs_port > 65535) { - syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %d. Skipping the node.\n", i, NAME_PORT, bs_port); + if (bs_port < MIN_ALLOWED_PORT || bs_port > MAX_ALLOWED_PORT) { + syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %d, should be in [%d, %d]. Skipping the node.\n", i, NAME_PORT, bs_port, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); goto next; } @@ -437,9 +439,8 @@ int main(int argc, char *argv[]) return 1; } - // not (1 <= port <= 65535) - if (port < 1 || port > 65535) { - syslog(LOG_ERR, "Invalid port: %d, must be 1 <= port <= 65535. Exiting.\n", port); + if (port < MIN_ALLOWED_PORT || port > MAX_ALLOWED_PORT) { + syslog(LOG_ERR, "Invalid port: %d, should be in [%d, %d]. Exiting.\n", port, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); return 1; } -- cgit v1.2.3 From e75930e72e40a69aea94240415af9ca53604ad0e Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sat, 17 May 2014 20:50:17 -0400 Subject: Some small fixes --- other/bootstrap_daemon/tox_bootstrap_daemon.c | 29 ++++++++++++-------------- other/bootstrap_daemon/tox_bootstrap_daemon.sh | 4 ++-- 2 files changed, 15 insertions(+), 18 deletions(-) (limited to 'other') diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index dce181a4..410a3453 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -50,6 +50,7 @@ // misc #include "../../testing/misc_tools.c" + #define DAEMON_NAME "tox_bootstrap_daemon" #define SLEEP_TIME_MILLISECONDS 30 @@ -60,7 +61,7 @@ #define DEFAULT_PORT 33445 #define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false #define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false -#define DEFAULT_ENABLE_TCP_RELAY 1 +#define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false #define MIN_ALLOWED_PORT 1 #define MAX_ALLOWED_PORT 65535 @@ -356,7 +357,7 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) } // Process settings - if (strlen(bs_public_key) != 64) { + if (strlen(bs_public_key) != crypto_box_PUBLICKEYBYTES*2) { syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_PUBLIC_KEY, bs_public_key); goto next; @@ -380,9 +381,9 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) syslog(LOG_DEBUG, "Successfully added bootstrap node #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key); next: - // config_setting_lookup_string() allocates string inside and doesn't allow us to free it - // so in order to reuse `bs_public_key` and `bs_address` we have to remove the element - // which will cause libconfig to free allocated strings + // config_setting_lookup_string() allocates string inside and doesn't allow us to free it direcly + // though it's freed when the element is removed, so we free it right away in order to keep memory + // consumption minimal config_setting_remove_elem(node_list, 0); i++; } @@ -396,17 +397,13 @@ next: void print_public_key(uint8_t *public_key) { - char buffer[64 + 1]; + char buffer[2*crypto_box_PUBLICKEYBYTES + 1]; int index = 0; int i; - for (i = 0; i < 32; i++) { - if (public_key[i] < 16) { - index += sprintf(buffer + index, "0"); - } - - index += sprintf(buffer + index, "%hhX", public_key[i]); + for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) { + index += sprintf(buffer + index, "%02hhX", public_key[i]); } syslog(LOG_INFO, "Public Key: %s\n", buffer); @@ -468,10 +465,6 @@ int main(int argc, char *argv[]) return 1; } - if (enable_lan_discovery) { - LANdiscovery_init(dht); - } - if (manage_keys(dht, keys_file_path)) { syslog(LOG_DEBUG, "Keys are managed successfully\n"); } else { @@ -559,6 +552,10 @@ int main(int argc, char *argv[]) int waiting_for_dht_connection = 1; + if (enable_lan_discovery) { + LANdiscovery_init(dht); + } + while (1) { do_DHT(dht); diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.sh b/other/bootstrap_daemon/tox_bootstrap_daemon.sh index 83d9a119..e083ea0b 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.sh +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.sh @@ -11,12 +11,12 @@ # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/sbin:/usr/sbin:/bin:/usr/bin -DESC="Tox DHT bootstrap server daemon" +DESC="Tox DHT bootstrap daemon" NAME=tox_bootstrap_daemon # You may want to change USER if you are using it anywhere else USER=tom CFG=/home/$USER/.$NAME/conf -DAEMON=/home/$USER/$NAME +DAEMON=/home/$USER/.$NAME/$NAME DAEMON_ARGS="$CFG" PIDFILE=/home/$USER/.$NAME/pid SCRIPTNAME=/etc/init.d/$NAME -- cgit v1.2.3 From 7dd811214ad335224f554ae658ce7b4c430a40c8 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sat, 17 May 2014 23:57:24 -0400 Subject: Added MOTD functionality --- other/bootstrap_daemon/conf | 14 ++++-- other/bootstrap_daemon/tox_bootstrap_daemon.c | 69 ++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 11 deletions(-) (limited to 'other') diff --git a/other/bootstrap_daemon/conf b/other/bootstrap_daemon/conf index fb524754..bbdf7652 100644 --- a/other/bootstrap_daemon/conf +++ b/other/bootstrap_daemon/conf @@ -3,7 +3,7 @@ // Listening port. port = 33445 -// The key file is like a password, so keep it where no one can read it. +// A key file is like a password, so keep it where no one can read it. // The daemon should have permission to read/write to it. // Remember to replace the provided example with your own path. keys_file_path = "/home/tom/.tox_bootstrap_daemon/keys" @@ -23,9 +23,15 @@ enable_lan_discovery = true enable_tcp_relay = true // Tox uses 443 and 3389 ports by default, so it's highly recommended to keep -// them +// them. tcp_relay_ports = [443, 3389] +// It's planned to use message of the day as a convenient method of checking +// whether a node is up or not, though there are other methods of doing that. +enable_motd = true + +motd = "tox_bootstrap_daemon" + // Any number of nodes the daemon will bootstrap itself from. // Remember to replace the provided example with your own node list. // There is a maintained list of bootstrap nodes on Tox's wiki, if you need it. @@ -34,8 +40,8 @@ tcp_relay_ports = [443, 3389] // from anyone. bootstrap_nodes = ( { // Node 1 - // Any ipv4 or ipv6, depending if `enable_ipv6` is set or not, and also - // any US-ASCII domain name. + // Any ipv4 or ipv6, depending on whether `enable_ipv6` is set or not, and + // also any US-ASCII domain name. address = "198.46.136.167" port = 33445 public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854" diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index 410a3453..6853358a 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -48,10 +48,12 @@ #include "../../toxcore/util.h" // misc +#include "../bootstrap_node_packets.c" #include "../../testing/misc_tools.c" #define DAEMON_NAME "tox_bootstrap_daemon" +#define DAEMON_VERSION_NUMBER 2014051700UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day #define SLEEP_TIME_MILLISECONDS 30 #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) @@ -62,6 +64,8 @@ #define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false #define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false #define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false +#define DEFAULT_ENABLE_MOTD 1 // 1 - true, 0 - false +#define DEFAULT_MOTD DAEMON_NAME #define MIN_ALLOWED_PORT 1 #define MAX_ALLOWED_PORT 65535 @@ -129,7 +133,7 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int } if (config_setting_is_array(ports_array) == CONFIG_FALSE) { - syslog(LOG_WARNING, "'%s' setting should be an array. Array syntax: 'setting = [value1, value2, ...]'.\n"); + syslog(LOG_WARNING, "'%s' setting should be an array. Array syntax: 'setting = [value1, value2, ...]'.\n", NAME_TCP_RELAY_PORTS); return; } @@ -161,7 +165,7 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int (*tcp_relay_ports)[*tcp_relay_port_count] = config_setting_get_int(elem); if ((*tcp_relay_ports)[i] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[i] > MAX_ALLOWED_PORT) { - syslog(LOG_WARNING, "Port #%d: Invalid port value, should be in [%d, %d]. Skipping.\n", i, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); + syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, (*tcp_relay_ports)[i], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); continue; } @@ -176,12 +180,14 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int // // Important: you are responsible for freeing `pid_file_path` and `keys_file_path` // also, iff `tcp_relay_ports_count` > 0, then you are responsible for freeing `tcp_relay_ports` +// and also `motd` iff `enable_motd` is set // // returns 1 on success // 0 on failure, doesn't modify any data pointed by arguments int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, - int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, int *tcp_relay_port_count) + int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, int *tcp_relay_port_count, + int *enable_motd, char **motd) { config_t cfg; @@ -191,6 +197,8 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi const char *NAME_ENABLE_IPV6 = "enable_ipv6"; const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery"; const char *NAME_ENABLE_TCP_RELAY = "enable_tcp_relay"; + const char *NAME_ENABLE_MOTD = "enable_motd"; + const char *NAME_MOTD = "motd"; config_init(&cfg); @@ -261,6 +269,30 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi *tcp_relay_port_count = 0; } + // Get MOTD option + if (config_lookup_bool(&cfg, NAME_ENABLE_MOTD, enable_motd) == CONFIG_FALSE) { + syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_MOTD); + syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_MOTD, + DEFAULT_ENABLE_MOTD ? "true" : "false"); + *enable_motd = DEFAULT_ENABLE_MOTD; + } + + if (*enable_motd) { + // Get MOTD + const char *tmp_motd; + + if (config_lookup_string(&cfg, NAME_MOTD, &tmp_motd) == CONFIG_FALSE) { + syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_MOTD); + syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_MOTD, DEFAULT_MOTD); + tmp_motd = DEFAULT_MOTD; + } + size_t tmp_motd_length = strlen(tmp_motd) + 1; + size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length; + *motd = malloc(motd_length); + strncpy(*motd, tmp_motd, motd_length); + (*motd)[MAX_MOTD_LENGTH - 1] = '\0'; + } + config_destroy(&cfg); syslog(LOG_DEBUG, "Successfully read:\n"); @@ -269,6 +301,7 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi syslog(LOG_DEBUG, "'%s': %d\n", NAME_PORT, *port); syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); + syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false"); // show info about tcp ports only if tcp relay is enabled if (*enable_tcp_relay) { @@ -283,6 +316,11 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi } } + syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd ? "true" : "false"); + if (*enable_motd) { + syslog(LOG_DEBUG, "'%s': %s\n", NAME_MOTD, *motd); + } + return 1; } @@ -415,6 +453,8 @@ int main(int argc, char *argv[]) { openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); + syslog(LOG_INFO, "Running \"%s\" version %lu.\n", DAEMON_NAME, DAEMON_VERSION_NUMBER); + if (argc < 2) { syslog(LOG_ERR, "Please specify a path to a configuration file as the first argument. Exiting.\n"); return 1; @@ -428,8 +468,10 @@ int main(int argc, char *argv[]) int enable_tcp_relay; uint16_t *tcp_relay_ports; int tcp_relay_port_count; + int enable_motd; + char *motd; - if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_lan_discovery, &enable_tcp_relay, &tcp_relay_ports, &tcp_relay_port_count)) { + if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_lan_discovery, &enable_tcp_relay, &tcp_relay_ports, &tcp_relay_port_count, &enable_motd, &motd)) { syslog(LOG_DEBUG, "General config read successfully\n"); } else { syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path); @@ -465,8 +507,18 @@ int main(int argc, char *argv[]) return 1; } + if (enable_motd) { + if (bootstrap_set_callbacks(dht->net, DAEMON_VERSION_NUMBER, (uint8_t*)motd, strlen(motd) + 1) == 0) { + syslog(LOG_DEBUG, "Set MOTD successfully.\n"); + } else { + syslog(LOG_ERR, "Couldn't set MOTD: %s. Exiting.\n", motd); + return 1; + } + free(motd); + } + if (manage_keys(dht, keys_file_path)) { - syslog(LOG_DEBUG, "Keys are managed successfully\n"); + syslog(LOG_DEBUG, "Keys are managed successfully.\n"); } else { syslog(LOG_ERR, "Couldn't read/write: %s. Exiting.\n", keys_file_path); return 1; @@ -485,14 +537,16 @@ int main(int argc, char *argv[]) // tcp_relay_port_count != 0 at this point free(tcp_relay_ports); - if (tcp_server == NULL) { + if (tcp_server != NULL) { + syslog(LOG_DEBUG, "Initialized Tox TCP server successfully.\n"); + } else { syslog(LOG_ERR, "Couldn't initialize Tox TCP server. Exiting.\n"); return 1; } } if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) { - syslog(LOG_DEBUG, "List of bootstrap nodes read successfully\n"); + syslog(LOG_DEBUG, "List of bootstrap nodes read successfully.\n"); } else { syslog(LOG_ERR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path); return 1; @@ -554,6 +608,7 @@ int main(int argc, char *argv[]) if (enable_lan_discovery) { LANdiscovery_init(dht); + syslog(LOG_DEBUG, "Initialized LAN discovery.\n"); } while (1) { -- cgit v1.2.3 From 906969d376244fadcf188c0297df2605bf407dd5 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sun, 18 May 2014 14:43:32 -0400 Subject: Fixed out of bounds write. --- other/bootstrap_daemon/tox_bootstrap_daemon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'other') diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index 6853358a..2c8f7014 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -290,7 +290,7 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length; *motd = malloc(motd_length); strncpy(*motd, tmp_motd, motd_length); - (*motd)[MAX_MOTD_LENGTH - 1] = '\0'; + (*motd)[motd_length - 1] = '\0'; } config_destroy(&cfg); -- cgit v1.2.3 From 8b5e3d520825f3376ec0fd00ba3aadc60c625d5f Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 18 May 2014 19:26:36 -0400 Subject: Allow multiple instances of the daemon --- other/bootstrap_daemon/tox_bootstrap_daemon.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'other') diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index 2c8f7014..0d18d411 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -485,8 +485,7 @@ int main(int argc, char *argv[]) // Check if the PID file exists if (fopen(pid_file_path, "r")) { - syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists. Exiting.\n", pid_file_path); - return 1; + syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists.\n", pid_file_path); } IP ip; @@ -555,10 +554,10 @@ int main(int argc, char *argv[]) print_public_key(dht->self_public_key); // Write the PID file - FILE *pidf = fopen(pid_file_path, "w"); + FILE *pidf = fopen(pid_file_path, "a+"); if (pidf == NULL) { - syslog(LOG_ERR, "Can't open the PID file for writing: %s. Exiting.\n", pid_file_path); + syslog(LOG_ERR, "Couldn't open the PID file for writing: %s. Exiting.\n", pid_file_path); return 1; } @@ -575,7 +574,7 @@ int main(int argc, char *argv[]) } if (pid > 0) { - fprintf(pidf, "%d\n", pid); + fprintf(pidf, "%d ", pid); fclose(pidf); syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid); return 0; -- cgit v1.2.3 From 261a70353ff316cc993c23faf07cb0f60e2e5819 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 18 May 2014 19:28:18 -0400 Subject: Fixed a bug --- other/bootstrap_daemon/tox_bootstrap_daemon.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'other') diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index 0d18d411..afe2b2ac 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -164,8 +164,8 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int } (*tcp_relay_ports)[*tcp_relay_port_count] = config_setting_get_int(elem); - if ((*tcp_relay_ports)[i] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[i] > MAX_ALLOWED_PORT) { - syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, (*tcp_relay_ports)[i], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); + if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { + syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); continue; } @@ -173,7 +173,7 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int } // the loop above skips invalid ports, so we adjust the allocated memory size - *tcp_relay_ports = realloc(*tcp_relay_ports, *tcp_relay_port_count * sizeof(uint16_t)); + *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); } // Gets general config options -- cgit v1.2.3 From fe1694fa6963ca0eceb898e4a07c60c123f23184 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 18 May 2014 19:31:50 -0400 Subject: Added default ports to the .c file, included 33445 port --- other/bootstrap_daemon/conf | 4 +-- other/bootstrap_daemon/tox_bootstrap_daemon.c | 45 ++++++++++++++++++++++----- 2 files changed, 39 insertions(+), 10 deletions(-) (limited to 'other') diff --git a/other/bootstrap_daemon/conf b/other/bootstrap_daemon/conf index bbdf7652..23580d9d 100644 --- a/other/bootstrap_daemon/conf +++ b/other/bootstrap_daemon/conf @@ -22,9 +22,9 @@ enable_lan_discovery = true enable_tcp_relay = true -// Tox uses 443 and 3389 ports by default, so it's highly recommended to keep +// Tox uses 443, 3389 and 33445 ports by default, so it's highly recommended to keep // them. -tcp_relay_ports = [443, 3389] +tcp_relay_ports = [443, 3389, 33445] // It's planned to use message of the day as a convenient method of checking // whether a node is up or not, though there are other methods of doing that. diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index afe2b2ac..66271288 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -58,14 +58,16 @@ #define SLEEP_TIME_MILLISECONDS 30 #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) -#define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid" -#define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys" -#define DEFAULT_PORT 33445 -#define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false -#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false -#define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false -#define DEFAULT_ENABLE_MOTD 1 // 1 - true, 0 - false -#define DEFAULT_MOTD DAEMON_NAME +#define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid" +#define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys" +#define DEFAULT_PORT 33445 +#define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false +#define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false +#define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false +#define DEFAULT_TCP_RELAY_PORTS 443, 3389, 33445 // comma-separated list of ports. make sure to adjust DEFAULT_TCP_RELAY_PORTS_COUNT accordingly +#define DEFAULT_TCP_RELAY_PORTS_COUNT 3 +#define DEFAULT_ENABLE_MOTD 1 // 1 - true, 0 - false +#define DEFAULT_MOTD DAEMON_NAME #define MIN_ALLOWED_PORT 1 #define MAX_ALLOWED_PORT 65535 @@ -129,6 +131,33 @@ void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int if (ports_array == NULL) { syslog(LOG_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS); + syslog(LOG_WARNING, "Using default '%s':\n", NAME_TCP_RELAY_PORTS); + + uint16_t default_ports[DEFAULT_TCP_RELAY_PORTS_COUNT] = {DEFAULT_TCP_RELAY_PORTS}; + + int i; + + for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { + syslog(LOG_WARNING, "Port #%d: %u\n", i, default_ports[i]); + } + + // similar procedure to the one of reading config file below + *tcp_relay_ports = malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t)); + + for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { + + (*tcp_relay_ports)[*tcp_relay_port_count] = default_ports[i]; + if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { + syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); + continue; + } + + (*tcp_relay_port_count) ++; + } + + // the loop above skips invalid ports, so we adjust the allocated memory size + *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); + return; } -- cgit v1.2.3 From 286d8d966166c590b2a775b05a7ee7be0f69fe70 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Sun, 18 May 2014 19:38:45 -0400 Subject: Made config file more consistent with default values --- other/bootstrap_daemon/conf | 4 ++-- other/bootstrap_daemon/tox_bootstrap_daemon.c | 2 +- other/bootstrap_daemon/tox_bootstrap_daemon.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'other') diff --git a/other/bootstrap_daemon/conf b/other/bootstrap_daemon/conf index 23580d9d..c05beff1 100644 --- a/other/bootstrap_daemon/conf +++ b/other/bootstrap_daemon/conf @@ -6,13 +6,13 @@ port = 33445 // A key file is like a password, so keep it where no one can read it. // The daemon should have permission to read/write to it. // Remember to replace the provided example with your own path. -keys_file_path = "/home/tom/.tox_bootstrap_daemon/keys" +keys_file_path = "/home/tom/.tox_bootstrap_daemon/.tox_bootstrap_daemon.keys" // The PID file written to by daemon. // Make sure that the user who runs the daemon has permissions to write to the // PID file. // Remember to replace the provided example with your own path. -pid_file_path = "/home/tom/.tox_bootstrap_daemon/pid" +pid_file_path = "/home/tom/.tox_bootstrap_daemon/.tox_bootstrap_daemon.pid" // Enable IPv6. enable_ipv6 = false diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index 66271288..ceb4fded 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c @@ -53,7 +53,7 @@ #define DAEMON_NAME "tox_bootstrap_daemon" -#define DAEMON_VERSION_NUMBER 2014051700UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day +#define DAEMON_VERSION_NUMBER 2014051800UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day #define SLEEP_TIME_MILLISECONDS 30 #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.sh b/other/bootstrap_daemon/tox_bootstrap_daemon.sh index e083ea0b..787498ec 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.sh +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.sh @@ -18,7 +18,7 @@ USER=tom CFG=/home/$USER/.$NAME/conf DAEMON=/home/$USER/.$NAME/$NAME DAEMON_ARGS="$CFG" -PIDFILE=/home/$USER/.$NAME/pid +PIDFILE=/home/$USER/.$NAME/."$NAME".pid SCRIPTNAME=/etc/init.d/$NAME # Exit if the package is not installed -- cgit v1.2.3