summaryrefslogtreecommitdiff
path: root/toxcore/DHT.c
AgeCommit message (Collapse)Author
2020-05-17Format comments according to tokstyle's requirements.iphydf
2020-05-05refactor: Remove multi-declarators entirely.iphydf
We no longer allow `int a, b;`. In the few cases where we used it, we instead better * limit the scope of the identifier (e.g. in a for-init-decl) * split the line and have 2 separate declarators, because the identifiers designate different types of things (e.g. friend numbers and group numbers).
2020-05-05refactor: Disallow multiple initialised declarators per decl.iphydf
We no longer allow: ```c int a = 0, b = 0; int a[3], b[3]; int a, *b; ``` But we do still allow (for now): ```c int a, b; ```
2020-05-03Fix a bug in savedata loading when malloc fails.iphydf
Also added a bunch of asserts to tests where they don't check allocs.
2020-05-02Fix errors on error paths found by oomer.iphydf
* Use-after-free because we free network before dht in one case. * Various unchecked allocs in tests (not so important). * We used to not check whether ping arrays were actually allocated in DHT. * `ping_kill` and `ping_array_kill` used to crash when passing NULL. Also: * Added an assert in all public API functions to ensure tox isn't NULL. The error message you get from that is a bit nicer than "Segmentation fault" when clients (or our tests) do things wrong. * Decreased the sleep time in iterate_all_wait from 20ms to 5ms. Everything seems to still work with 5ms, and this greatly decreases the amount of time spent per test run, making oomer run much faster.
2020-04-07Remove newlines from the end of LOGGER format strings.iphydf
See https://github.com/TokTok/hs-tokstyle/pull/49 for the corresponding tokstyle analysis.
2020-03-22Minor cleanup: use `assoc_timeout` function where possible.iphydf
This function exists and simplifies some code a little bit. There are lots of places in DHT.c where we have the exact same code, so there is a lot of opportunity to factor out common bits. For now, we just make a minor improvement that's easy to review.
2020-03-14Fix up comments a bit to start being more uniform.iphydf
Tokstyle (check-cimple) will start enforcing comment formats at some point. It will not support arbitrary stuff in comments, and will parse them. The result can then be semantically analysed.
2020-03-14Use spdx license identifier instead of GPL blurb.iphydf
2020-03-14use -1 rather than ~0 in unsigned integer typeszugz (tox)
Using ~0 involves a bitwise operation on int, so depends on the internal representation of signed integers.
2019-05-01Do not send the same packet to the same node twice.Evgeny Kurnevsky
2018-10-24Change method of PK production for fake friend in DHTNamsooCho
2018-10-20Make saving and loading the responsibility of Tox rather than Messengerzugz (tox)
2018-10-11ensure save data unchanged after save and loadzugz (tox)
2018-09-19Fix typosyangfl
2018-09-07Add messenger state plugin system.iphydf
This is for modules like groups to hook into to have their own state management in the `tox_savedata` format.
2018-09-06Ignore "unused-result" warning in super_donators code.iphydf
2018-08-30Clean up `add_to_list` function a bit.iphydf
Can't trivially get rid of recursion here, since it's a non-linear recursive function.
2018-08-27Make `ip_is_lan` return bool instead of 0/-1.iphydf
This inverts the truthiness of the return value. Previously, 0 meant `true` and -1 meant `false`. Now, `true` (1) means `true` and `false` (0) means `false`.
2018-08-26Use `bool` in place of 0/1 int values.iphydf
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