Commit Graph

268 Commits

Author SHA1 Message Date
iphydf 8b4eae4038 Remove TOX_DEBUG and have asserts always enabled.
These are cheap asserts. I've also replaced the fprintf's with
`LOGGER_ERROR` calls.
2017-01-11 19:43:08 +00:00
iphydf 958aa43bdf Fix logging condition for IPv6 client timestamp updates. 2017-01-11 15:10:52 +00:00
endoffile78 e667ec23b9 Replace make_quick_sort with qsort 2017-01-07 11:47:30 -06:00
iphydf e4d81e1520 Eliminate dead return statement.
Previously, the `ipv6` variable was initialised to `-1`, but that value
was never read. Either it was set to 0 or 1, or the function would return
before it was read. Thus, I've changed it to uninitialised `bool is_ipv4`
(inverted semantics to avoid negative conditions `if (!is_ipv6)`).

The `pack_ip_port` function is a bit unfortunate, but I'm not rewriting
it until we have a binary writer (I'd be rewriting it twice).
2017-01-06 13:53:49 +00:00
iphydf 2328cb74ab Improve documentation of crypto_core. 2016-12-22 10:26:59 +00:00
iphydf ce29c8e7ec Wrap all sodium/nacl functions in crypto_core.c. 2016-12-22 10:26:59 +00:00
Gregory Mullen (grayhatter) ad517eb1df add NAT hole punching level to Tox API 2016-11-24 17:38:34 -08:00
endoffile78 8899b69b40 Add DHT_create_packet 2016-11-11 15:53:04 -06:00
iphydf aed24408db Remove new_nonce function in favour of random_nonce.
`new_nonce` has been an alias for `random_nonce` for a while now. Having
two names for the same operation is confusing. `random_nonce` better
expresses the intent. The documentation for `new_nonce` talks about
guaranteeing that the nonce is different from previous ones, which is
incorrect, it's just quite likely to be different.
2016-11-09 22:30:49 +00:00
endoffile78 3f53090c1d Remove assoc 2016-11-06 09:14:53 -06:00
iphydf 64870b6fd2 Move packing and unpacking DHT request packets to DHT module.
These definitely don't belong in a module called "crypto core". The DHT
module seems like the best place to put them, since they are sent to DHT
nodes.
2016-11-03 11:56:29 +00:00
iphydf 1977d56caa Remove return after no-return situation (and other cleanups).
Cleanups:
- Fix header guards to not use reserved names.
- Avoid name shadowing.
- Removed an unused variable found by avoiding name shadowing.
2016-09-30 19:06:44 +01:00
iphydf 15cb426166 Make toxcore code C++ compatible.
It is still C code, so still compatible with C compilers as well. This
change lets us see more clearly where implicit conversions occur by
making them explicit.
2016-09-24 21:53:50 +01:00
iphydf 1494e474dd Ensure that all TODOs have an owner.
In the future, all TODOs added either need a bug number (TODO(#NN)) or a
person's github user name. By default, I made irungentoo the owner of
all toxcore TODOs, mannol the owner of toxav TODOs, and myself the owner
of API TODOs.
2016-09-16 12:06:02 +01:00
iphydf 45d28904b9 Use <stdbool.h> and replace _Bool with bool.
This header is a requirement for the public API, therefore is assumed to
exist. It is a C99 standard library header, and _Bool is not intended to
be used directly, except in legacy code that defines bool (and
true/false) itself. We don't use or depend on such code. None of our
client code uses or depends on such code. There is no reason to not use
bool.
2016-09-13 22:01:45 +01:00
iphydf a8823830d3 Add some astyle options to make it do more.
It now enforces a bit more formatting. In particular, padding inside
parentheses is removed. I would like it to remove padding after unary
operators, but there seems to be no option for that.
2016-09-13 01:07:02 +01:00
iphydf 0aa2840164 Group #include directives in 3-4 groups.
1. Current module (if C file).
2. Headers from current library.
3. Headers from other library (e.g. toxcore includes in toxav).
4. System headers.
2016-09-13 00:32:02 +01:00
iphydf a365bef2ae Remove else directly after return.
See #78.
2016-09-12 16:30:00 +01:00
Jfreegman 769db9dd9a Separate IP_Port packing from pack_nodes() and unpack_nodes()
Allows us to pack IP_Port structs that are part of arbitrarily structured data.
2016-09-09 10:37:40 -04:00
iphydf ad26560516 Improve static and const correctness.
- Any non-externally-visible declarations should be `static`.
- Casting away the `const` qualifier from pointers-to-const is
  dangerous. All but one instance of this are now correct. The one
  instance where we can't keep `const` is one where toxav code actually
  writes to a chunk of memory marked as `const`. This code also assumes
  4 byte alignment of data packets. I don't know whether that is a valid
  assumption, but it's likely unportable, and *not* obviously correct.
- Replaced empty parameter lists with `(void)` to avoid passing
  parameters to it. Empty parameter lists are old style declarations for
  unknown number and type of arguments.
- Commented out (as `#if DHT_HARDENING` block) the hardening code that
  was never executed.
- Minor style fix: don't use `default` in enum-switches unless the number
  of enumerators in the default case is very large. In this case, it was
  2, so we want to list them both explicitly to be warned about missing
  one if we add one in the future.
- Removed the only two function declarations from nTox.h and put them
  into nTox.c. They are not used outside and nTox is not a library.
2016-09-06 11:54:37 +01:00
Gregory Mullen (grayhatter) aad1e0ad3f Make friend requests stateless
Messenger is slightly twisty when it comes to sending connection status
callbacks It will very likely need at the very least a partial refactor to
clean it up a bit. Toxcore shouldn't need void *userdata as deep as is
currently does.

(amend 1) Because of the nature of toxcore connection callbacks, I decided to
change this commit from statelessness for connections changes to statelessness
for friend requests. It's simpler this was and doesn't include doing anything
foolish in the time between commits.

group fixup because grayhatter doesn't want to do it

"arguably correct" is not how you write security sensitive code

Clear a compiler warning about types within a function.
2016-09-06 02:22:04 -07:00
iphydf a9fbdaf46b Do not use else after return.
http://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code
2016-09-02 11:02:56 +01:00
iphydf 77db27331e Sort #includes in all source files. 2016-09-01 16:35:46 +01:00
iphydf 633da98ae6 Add braces to all if statements. 2016-08-31 20:04:16 +01:00
iphydf 13ae9e9a93 Move logging to a callback.
This removes the global logger (which by the way was deleted when the first tox
was killed, so other toxes would then stop logging). Various bits of the code
now carry a logger or pass it around. It's a bit less transparent now, but now
there is no need to have a global logger, and clients can decide what to log and
where.
2016-08-27 01:16:14 +01:00
iphydf a5e35180c7 Make tox_callback_friend_name stateless.
See #27 and #40 for details.
2016-08-18 00:01:53 +01:00
iphydf db22522741 Add missing DHT_bootstrap to CMakeLists.txt.
- This PR also adds a DEBUG cmake option that enables -DTOX_DEBUG.
- We also remove `-Wall`, because there are too many warnings, and nobody really
  looks at them at the moment. We'll see about fixing them soon. We'll also want
  to enable `-Werror` at some point.
- Finally, this PR enables `-O3` to make sure toxcore still works correctly
  under heavy compiler optimisations.
2016-08-17 22:12:39 +01:00
Roman Proskuryakov 94d6333107 add: comment about endianness 2016-01-27 02:14:59 +03:00
Roman Proskuryakov ed3a794c9b fix: compare sensitive data with sodium_memcmp
fix: make increment_nonce & increment_nonce_number independent of user-controlled input
	fix: make crypto_core more stable agains null ptr dereference
2016-01-27 02:14:59 +03:00
irungentoo 405854e1e7 Cleanups. 2016-01-04 22:48:58 -05:00
irungentoo 760f20c945 DHT improvements part 1. 2016-01-04 20:14:57 -05:00
irungentoo 07b4b041fb Allow 0 length sendnode. 2015-12-17 14:05:35 -05:00
irungentoo 0938ba08d9 Send get nodes instead of ping to timing out nodes. 2015-12-16 17:22:07 -05:00
irungentoo d6b4761c2f This is still useful. 2015-12-16 16:42:12 -05:00
irungentoo c1e00c5d39 Improved the to_ping list. 2015-12-16 11:28:30 -05:00
irungentoo 836e180757 More efficient DHT searching. 2015-12-15 14:13:28 -05:00
irungentoo 5e6bd7bfee Sort list if timed out nodes are in the middle of the list. 2015-12-14 20:18:53 -05:00
irungentoo 4cfafe8310 Send get nodes more to closer nodes than further nodes. 2015-12-14 19:37:19 -05:00
irungentoo 07a6f482d9 Update so this works with the new distance function. 2015-12-12 14:49:21 -05:00
irungentoo b5978a0da8 Remove useless vars. 2015-12-11 18:27:12 -05:00
irungentoo 7494c65bee More DHT fixes. 2015-12-11 17:44:21 -05:00
irungentoo 5fe8429da8 DHT fix. 2015-12-11 17:21:39 -05:00
irungentoo 22b1ebb46e DHT improvements.
Feed better nodes to onion, bootstrap off close clients when DHT friend is added.
2015-12-11 16:48:10 -05:00
irungentoo ae801b3257 DHT fix.
Return only closest nodes in get nodes packet.
2015-12-11 15:34:04 -05:00
irungentoo 1986a2e492 DHT fixes. 2015-12-11 15:07:46 -05:00
irungentoo 39700abd86 Check if node can be stored before sorting. 2015-12-10 10:09:48 -05:00
irungentoo 8fa264e770 Small fix. 2015-12-09 09:10:03 -05:00
irungentoo deb0b358a5 DHT fix.
Improve DHT distance function.
2015-12-09 08:59:10 -05:00
irungentoo 4a6837acc7 Improve likelyhood of the closest nodes being in our lists. 2015-12-08 20:04:27 -05:00
irungentoo 4f33b27f6b Fixed DHT bug. 2015-12-08 16:50:18 -05:00