summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
AgeCommit message (Collapse)Author
2018-08-16Use per-instance `Mono_Time` for Messenger and onion.iphydf
2018-08-16Reduce the number of times `unix_time_update` is called.iphydf
Reduced by, e.g.: * `file_transfer_test`: 33% of the `clock_gettime` calls. * `tox_many_test`: 53% of the `clock_gettime` calls. Other tests will see similar improvements. Real world applications will be closer to 40-50% improvement, since tox_many_test has 100 nodes, while file_transfer_test has 2 nodes.
2018-08-10Use the crypto random functions instead of `rand()`.iphydf
Presumably the uses of `rand()` were fine because they were not used in security-sensitive places, but having to think about whether a crappy RNG is acceptable in each situation requires effort that could better be spent elsewhere. Also, this means that once we have a custom deterministic RNG for testing, that RNG is used everywhere, so all the code is deterministic. It also allowed us to delete a system-specific function that wasn't used anywhere except in a call to `srand()`.
2018-08-04Avoid multiple for-next expressions.iphydf
All for-loops in toxcore are of the form for (<for-init>; <for-cond>; <for-next>) { <body> } `for-init` can be a variable declaration (like `int i = 0`), an assignment (like `i = 0`), or empty. `for-cond` can be any expression. `for-next` can be an assignment or a single increment/decrement expression (like `++i` or `--i`). No other forms are allowed, so e.g. comma expressions in any of these are not allowed (so no `for (i = 0, j = n; ...; ++i, --j)`).
2018-07-12Style fixes in TCP code; remove MIN and PAIR from util.h.iphydf
* Moved PAIR to toxav, where it's used (but really this should die). * Replace most MIN calls with typed `min_*` calls. Didn't replace the ones where the desired semantics are unclear. Moved the MIN macro to the one place where it's still used. * Avoid assignments in `while` loops. Instead, factored out the loop body into a separate `bool`-returning function. * Use named types for callbacks (`_cb` types). * Avoid assignments in `if` conditions. * Removed `MAKE_REALLOC` and expanded its two calls. We can't have templates in C, and this fake templating is ugly and hard to analyse and debug (it expands on a single line). * Moved epoll system include to the .c file, out of the .h file. * Avoid assignments in expressions (`a = b = c;`). * Avoid multiple declarators per struct member declaration. * Fix naming inconsistencies. * Replace `net_to_host` macro with function.
2018-07-12Fix style in DHT.c.iphydf
* Removed `ARRAY_SIZE` and use NULL markers for end of array, instead. The alternative is + size, but for these arrays, NULL markers made sense, since they are arrays of non-null pointers. * Made `INDEX_OF_PK` a self-contained macro, not dependent upon the naming inside its call site. This is a minor change but makes the code more local and reviews easier. * No nested structs. * Use only named function types ending in `_cb` for callbacks. * Replaced two macros with functions. * `++i` instead of `i++`. * struct member names start with lowercase letters. * It takes a bit of work to support `/**/` comments in preprocessor macros, so I've decided not to support these. If a macro is complex enough to need comments inside it, it's too complex. `//` comments are allowed at the end of macro definitions. * Callback typedefs must name their parameters.
2018-07-09Factor out time keeping code into its own module: mono_time.c.iphydf
It turns out, `unix_time` is also monotonic, and is used as such, so I've renamed the new functions to `mono_time_*`. 2018-07-08: ``` 00:01 <@irungentoo> the idea used to be that the unix_time() function could go backward in time but I think I might have started using it like if it could not after I changed it so that it would never go back in time ```
2018-07-09Move `load_state` and its helper functions to their own module.iphydf
2018-07-05Make tox.c unambiguously parseable.iphydf
Rules: 1. Constants are uppercase names: THE_CONSTANT. 2. SUE[1] types start with an uppercase letter and have at least one lowercase letter in it: The_Type, THE_Type. 3. Function types end in "_cb": tox_friend_connection_cb. 4. Variable and function names are all lowercase: the_function. This makes it easier for humans reading the code to determine what an identifier means. I'm not convinced by the enum type name change, but I don't know a better rule. Currently, a lot of enum types are spelled like constants, which is confusing. [1] struct/union/enum
2018-06-24Add Logger to various net_crypto functions.iphydf
In preparation for adding log statements. Also, fix an uninitialised variable warning in cppcheck.
2018-05-20Finish @Diadlo's network Family abstraction.iphydf
The Family stuff in toxcore is a big mess. I'm sure I saw a bunch of bugs on the way, but I'm not verifying that code now, so the bugs stay.
2018-05-20Move system header includes from network.h to network.ciphydf
2018-03-16Move struct DHT_Friend into DHT.c.iphydf
2018-02-24Fix a bunch of compiler warnings and remove suppressions.iphydf
2018-02-18Use `const` more in C code.iphydf
2018-02-14Get rid of the only GNU extension we used.iphydf
2018-02-14Remove leftover symmetric key from DHT struct.iphydf
2018-01-30Use nullptr as NULL pointer constant instead of NULL or 0.iphydf
This changes only code, no string literals or comments.
2018-01-22Use <stdlib.h> for alloca on FreeBSD.iphydf
https://www.freebsd.org/cgi/man.cgi?alloca If stdlib.h does not define alloca, and we're using GCC (or Clang), we define the macro ourselves in terms of a GCC builtin.
2018-01-16Make DHT a module-private type.iphydf
2018-01-16Use apidsl to generate LAN_discovery.h.iphydf
2018-01-16Make pack/unpack_ip_port public DHT functions.iphydf
These will be needed for new group chats.
2018-01-14Add random_u16 function and rename the others to match.iphydf
2018-01-14Use apidsl to generate ping.h.iphydf
The ping.api.h file looks rather ugly, but it works. This is an exercise in finding the complete set of use cases needed from apidsl for toxcore. We'll try to make things work as much as possible, and then make apidsl better and make the .api.h files pretty.
2018-01-13Make Ping_Array a module-private type.iphydf
2018-01-10Fix formatting in some C files.iphydf
Also replace &(x) with &x for consistency.
2017-09-17reset hole-punching parameters after not punching for a whilezugz
2017-08-24Remove useless 'to_net_family' and 'to_host_family'Diadlo
2017-08-24Add platform independent constantsDiadlo
2017-08-24AF_INET -> TOX_AF_INETDiadlo
2017-06-05Change way to iterate through assocDiadlo
2017-06-05Make work with assoc more genericDiadlo
2017-06-05Improve formatting and syntaxDiadlo
2017-06-05Cleanup punch_holesDiadlo
2017-06-05Add using id_equalDiadlo
2017-06-05Update crypto_size and check indexDiadlo
2017-06-05Extract 'update_client_data' to reduce code duplicationDiadlo
2017-06-05Extract 'update_client_with_reset' function to reduce code duplicationDiadlo
2017-06-05Extract 'update_client' functionDiadlo
To make 'client_or_ip_port_in_list' code easy to read
2017-06-05Extract variablesDiadlo
2017-06-05Change return type to be the same as return value typeDiadlo
Return value of 'addto_list' function is 'used' counter, which is uint32_t. It will be better to use the same return type.
2017-06-05Add using macros to improve codeDiadlo
2017-06-05Add 'index_of' functionsDiadlo
- Replace 'for' with long body - Replace friend_number function on index_of_friend_pk - Replace client_in_nodelist on index_of_node_pk
2017-06-05Extract SharedKey struct and use it as var instead of indexingDiadlo
2017-06-05Add using C99 'for' syntaxDiadlo
2017-06-04Add a monolith_test that includes all toxcore sources.iphydf
This requires that every symbol, even if static (file-scope), is unique. The idea is that we can easily run "whole" program static analysis on programs that include monolith.h ("whole" is in quotes, as we don't include dependencies like libsodium in this static analysis).
2017-04-29check if already in close list in ping_node_from_getnodes_ok()zugz
fix index bounds check in add_to_close() and is_pk_in_close_list() add TODO to write test for bug which fixed by this commit
2017-03-26Add crypto_memzero for temp bufferDiadlo
2017-02-26Add part of platform-independent network API implementationDiadlo
socket -> net_socket htons -> net_htons htonl -> net_htonl connect -> net_connect sendto -> net_sendto_ip4 getaddrinfo -> net_getipport sa_family_t -> Family
2017-02-21Use VLA macroMaxim Biro