Commit Graph

566 Commits

Author SHA1 Message Date
jfreegman
53bd3c86df
Fix possible unintended negative loop bound 2022-01-01 16:01:29 -05:00
jfreegman
d8397c93c8
Put breaks inside case bracers 2021-12-25 12:30:39 -05:00
iphydf
24f49fc917
chore: Fix up a few source code comment and style issues.
Tokstyle no longer allows:
* Includes inside an `extern "C"`
* Comments on function definition and declaration to be different.
* Doxygen comments commenting on other doxygen comments.
2021-12-21 18:14:53 +00:00
iphydf
4746a8b3af
cleanup: Remove apidsl; remove crypto_memcmp.
* `crypto_memcmp` was replaced by more specific functions. We never want
  to compare arbitrary amounts of data this way. We use these functions
  to compare key material.
* apidsl has been bothering people, so now we un-bother them. You're
  welcome.
* Added the memlock/unlock functions from the New Group Chats branch.
* Remove some system dependencies in crypto_core_mem.c.
* Renamed UPPERCASE_NAMES to Snake_Camel_Case names.
2021-12-19 19:22:38 +00:00
iphydf
27f7c8beaa
chore: Tie down the use of doxygen comments.
These should only be used before a toplevel thing that can be commented on.
2021-12-15 18:35:48 +00:00
iphydf
5c53e6a30f
chore: Add autotools build; exempt crypto_pwhash from tokstyle. 2021-12-13 18:47:45 +00:00
iphydf
fd32c87707
cleanup: Don't include "config.h" unless needed.
Currently only `crypto_core_mem.c` needs this. We should try not to
depend on configure'd values. Also note: config.h is only created and
used in the autotools build. In CMake, we pass `-D` flags directly.
2021-12-12 22:18:38 +00:00
sudden6
891fe60ea2
extend ToxAV API to support different threads for audio and video
This allows for prioritizing audio over video transcoding and improves
performance when multiple CPU cores are available.
2021-12-11 10:43:47 +01:00
sudden6
a80a29163c
clarify purpose of variable 2021-12-10 23:10:21 +01:00
iphydf
30c939e4ab
cleanup: Fix some clang-tidy warnings and make them errors.
The android warnings are disabled now because they suggest using
linux-only extensions of libc. Useful for android indeed, but we're
targeting non-android and non-linux systems as well.
2021-12-10 15:21:27 +00:00
iphydf
d5fefc927e
cleanup: Require {} around all switch case label statements.
Except for single return-with-value statements.
2021-12-10 14:20:13 +00:00
iphydf
e4ad0c833c
cleanup: Enforce for loop consistency.
All for-loops must have an init-decl, a condition, and an increment
statement. Any loop that doesn't have one of these should be a while
loop (only 2 of these exist in toxav, none in toxcore).
2021-12-09 14:53:00 +00:00
jfreegman
ce268c2f82
Add some missing null checks 2021-12-06 16:57:07 -05:00
iphydf
af1848ed13
chore: Use toktok-stack docker image with built third_party.
This should cut down the build time a bit by downloading the binaries
built for `//third_party/...`.
2021-12-05 19:21:57 +00:00
jfreegman
00f2f41dbb
Use heap memory instead of stack for large variables
The default stack size for musl-libc is 128kb. Therefore we should try to keep stack
allocations well below this limit in order to avoid stack overflows.
2020-11-20 19:15:58 -05:00
iphydf
03a511482f
Format comments according to tokstyle's requirements. 2020-05-17 18:16:42 +01:00
iphydf
88b90c8225
Fix a bug in savedata loading when malloc fails.
Also added a bunch of asserts to tests where they don't check allocs.
2020-05-03 14:13:48 +00:00
iphydf
7b758f66db
Enable cimple tests by default but allow disabling them.
Use `bazel test //c-toxcore/... --build_tag_filters=-haskell` to run all
tests except the ones that depend on Haskell (i.e. cimple tests).
2020-05-03 14:03:54 +01:00
iphydf
2570ddcb17
Fix errors on error paths found by oomer.
* 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-05-02 21:47:08 +01:00
iphydf
c08b2fb3e2
Remove tokstyle exemptions from build files.
We put some tokstyle exemptions into the source files themselves,
instead. This way we can check some of the code in those files, and more
in the future when tokstyle supports more constructs (like apidsl).

Also: hacked ping_array.api.h to not emit `_array` as parameter names.
We'll need to fix apidsl to do this better. This works for now.
2020-04-16 11:05:08 +00:00
zoff99
af6e27bbf1
Use public API for sending in RTP. 2020-04-09 11:51:34 +00:00
zoff99
da2c4191b4
Use public API for sending in BWC. 2020-04-08 13:41:58 +00:00
iphydf
8ddc2df662
Remove newlines from the end of LOGGER format strings.
See https://github.com/TokTok/hs-tokstyle/pull/49 for the corresponding
tokstyle analysis.
2020-04-07 19:17:58 +00:00
zoff99
dfe19e04d3
Change ToxAVCall struct mutex to a more distinct name. 2020-04-07 17:56:01 +00:00
zoff99
97fc2f4c0b
Create own instance of MonoTime for ToxAV. 2020-04-07 17:16:17 +00:00
zoff99
27f24e61b2
Stop using Messenger's mono_time in bandwidth controller.
We're actually still using it, but we got a private pointer now,
preparing us for having a private mono_time in toxav.
2020-04-05 11:56:52 +00:00
zoff99
bcbc374370
Fix 2 memory leaks in ToxAV. 2020-04-05 09:32:23 +00:00
iphydf
84e6a8d057
Make function defns match their decls regarding storage class.
We want functions declared as `static` to also be defined as `static`.
2020-03-18 15:14:31 +00:00
iphydf
1b7bf5b182
Mark file-local function definitions as static.
https://github.com/TokTok/hs-tokstyle/pull/43 implements a validation for
this. We should avoid locally declaring functions from another
translation unit, and instead use header files to export/import them.
2020-03-18 00:53:02 +00:00
zugz (tox)
52655b0c1b
clean groups code
* make static functions return bool rather than int to indicate success
* add peer_in_list() to factor out uniformity over peer and frozen lists
* reduce repetition in send_lossy_all_close
* rename 'close' to 'connections'
* use uint32_t for peernumber (in accord with tox.c)
* explain persistence in tox_conference_get_chatlist documentation
* clarify "connectedness" in group API documentation
* clarify that tox_conference_peer_count counts only online peers
* refactor variously
2020-03-15 00:00:27 +00:00
iphydf
8795c5f987
Avoid casting back and forth between void-ptr.
In windows network code, we implement inet_pton and inet_ntop, which take
void pointers. We can do slightly better because we already know the type
when we call these functions, so we can avoid casting between void
pointer and the addr struct types.
2020-03-14 13:48:56 +00:00
iphydf
94d98ddd86
Standardise on having a comma at the end of enums.
Most of our enums already have one. Some didn't. Tokstyle is going to
require commas at the end of enumerator lists in enum definitions.
2020-03-14 13:40:36 +00:00
iphydf
cb22b3df5f
Fix up comments a bit to start being more uniform.
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-14 13:28:42 +00:00
iphydf
11ad5471b9
Use spdx license identifier instead of GPL blurb. 2020-03-14 13:06:19 +00:00
iphydf
e671490989
Use rules_cc instead of native cc_library rules. 2020-03-12 12:20:54 +00:00
iphydf
7b3d2eda3f
Use net_pack instead of casting bytes to ints.
The current code violates the C standard and causes crashes on strict
alignment architectures.
2020-03-06 11:05:52 +00:00
iphydf
e618829112
Add "cimple_test" to the bazel build. 2020-03-02 15:20:34 +00:00
iphydf
0f7138c010
Upgrade bazel to 2.1.1.
Removed av_test, because it depends on an ancient opencv that starts to
really not exist on modern systems anymore.
2020-03-02 14:23:44 +00:00
sudden6
683bc802e2
fix ToxAV threading documentation
ToxAV is not thread-safe at the moment, remove that claim from the
header file.
2020-01-02 11:58:52 +01:00
sudden6
abfd90d25b
fix log message creating data race 2019-11-21 23:47:03 +01:00
sudden6
a29d5805a6
fix missing mutex 2019-11-21 23:47:02 +01:00
sudden6
81728addb2
fix ToxAV mutex released to early 2019-11-21 23:46:59 +01:00
zugz (tox)
d14989f6df
put toxav.h stuff in toxav.api.h 2019-02-10 18:17:59 +01:00
zugz (tox)
695fa4373a
explain enabling in API comment 2019-02-10 00:00:00 +00:00
zugz (tox)
959f468eac
add API function to test whether av is enabled 2019-02-10 00:00:00 +00:00
zugz (tox)
49e2406ffa
Expose api functions for enabling and disabling AV in AV groups
A group loaded from a savefile starts with AV disabled.
2019-02-10 00:00:00 +00:00
zugz (tox)
a122ee9e01
Expose offline conference peers in API 2019-01-05 15:01:29 +00:00
iphydf
3e58f3cd4d
Improve Windows compatibility of toxav code.
- unistd.h doesn't exist on MSVC.
- `vpx_codec_iface_t` is already `const`, so adding `const` qualifiers is
  redundant and causes warnings on MSVC.
2018-10-08 22:22:58 +00:00
iphydf
bfd288c196
Revert "Improve cmake build for MSVC."
This reverts commit f87f8719d0.
2018-09-24 22:25:49 +00:00
iphydf
b694dbc223
Add Cirrus CI configuration.
This CI can run Bazel tests, because it supports IPv6. This is nice,
because now we can run IPv6 tests on every PR.
2018-09-24 22:00:17 +00:00
Mick Sayson
f87f8719d0
Improve cmake build for MSVC. 2018-09-22 11:14:45 +00:00
Mick Sayson
dc0b2e7919
Fix using uninitialized mutex on call end. 2018-09-21 20:44:24 +00:00
yangfl
d3d5b701cb
Fix typos 2018-09-19 18:16:13 +00:00
iphydf
49bb43f662
Standardise header guards.
Using the full path including the repo name.
2018-09-14 19:09:10 +00:00
iphydf
7821cd8412
Use C++ style casts in C++ code. 2018-09-14 14:08:27 +00:00
iphydf
33c2f5138f
Always use the passed logger (from Messenger) in msi_kill. 2018-09-08 22:47:32 +00:00
iphydf
6872c14e1a
Avoid use of global mutable state in mono_time on win32.
This uses a trick to get read-write access to `this` from a `const`
member function, similar to C++ `mutable`, but uglier.
2018-09-03 20:03:47 +00:00
iphydf
473cde24d8
Update copyright to 2018. 2018-08-26 18:57:29 +00:00
iphydf
e99c13120f
Change while-loop to for-loop to express for-each-frame.
* Assignments can't be used as expressions, therefore `while` loops
  should not be used as a `for-each` construct. Use `for`, instead.
2018-08-25 20:39:24 +00:00
iphydf
7aa57afeba
Avoid redefining macros from different files. 2018-08-19 23:15:01 +00:00
zugz (tox)
14484c6879
make Mono_Time an argument to current_time_monotonic 2018-08-19 23:41:43 +02:00
iphydf
d6d305feeb
Use per-instance Mono_Time for Messenger and onion. 2018-08-16 21:01:43 +00:00
iphydf
c0db255425
Limit the size of a save file in file_saving_test.
Limited to 4GiB. That ought to be enough for any save file.
2018-08-16 10:15:01 +00:00
iphydf
475f01bc1a
Fix style in toxav.c.
* Use Camel_Snake_Case for type names.
* Use at least 4 characters for constant names. I.e. `END` is a type
  name, but `RETURN` is a constant name. This is because `DHT` is a type
  name (yay consistency).
* Using `min_*` functions instead of MIN, we can avoid a cast.
* Use `for`-loops for for-each-frame semantics instead of `while`.
* Don't use assignments as expressions.
* `++i` instead of `i++`.
* Function pointers are dereferenced automatically, so no need to
  manually do so.
* Avoid void pointers that lie about not being spaghetti code. Toxcore
  and toxav are both spaghetti and shouldn't pretend anything else.
* Don't use empty statements (e.g. no `;;` anywhere in the code).
2018-08-14 21:59:27 +00:00
iphydf
2d84681529
Fix ToxAv's use of struct Tox.
* Fix `toxav_get_tox` to return tox, not messenger.
* Fix the casts from Tox* to Messenger* in toxav_old.c.
* Pass Tox instead of Messenger to public group AV callbacks.
2018-08-13 22:11:48 +00:00
iphydf
c10d5ceeee
Fix style in video.c.
* Constant-style macros can't be function call expressions. These must be
  function calls themselves.
* Assignments can't be used as expressions.
  * Therefore: `while` loops should not be used as a `for-each`
    construct. Use `for`, instead.
2018-08-13 21:40:05 +00:00
iphydf
97a4b8e6a7
Fix memory leak in error path in group A/V.
This probably doesn't happen, but it can in theory, so we avoid it.
2018-08-13 10:45:21 +00:00
iphydf
d518374819
Fix groupav.c style and avoid casts in toxav_old.c.
* No anonymous structs.
* No assignment expressions.
* Only one declarator per struct member declaration.
* Named callback types only, no inline types.
* No `;` empty statements.
* `++i` instead of `i++`.

Avoiding a cast in toxav_old.c avoids some potential (and real) bugs.
2018-08-13 10:37:09 +00:00
iphydf
df9033dcb9
Fix coding style in rtp module.
* Named callback types only.
* No anonymous enums or structs.
* `++i` instead of `i++`.
* Don't use enums to specify integer constants. Enums should be
  enumerations. All values of an enum type should be listed[1].

[1] I don't know what to do about bit masks yet, but given that enums by
C standard can only go up to 32767 portably and 2^31 in reality, they are
probably not useful for 64 bit bit masks.
2018-08-12 23:32:59 +00:00
iphydf
04d894e7cc
Fix style in msi.c.
* Don't use anonymous enums (`typedef enum { ... } Name;`).
* Don't use macros to generate structs (too magical, hard to grep).
* Assign output parameter once, and don't access it a lot in the
  function body.
* Don't pass type names as parameters to macros (this is C, we don't have
  templates, sorry).
* All function-like macros must be do-while(0).
* `++i` instead of `i++`.
* No assignment-expressions.
* No void-casts.
2018-08-12 21:27:53 +00:00
iphydf
6d8d80b387
Make conferences_object properly typed.
The void pointer here only adds opportunity to introduce bugs and doesn't
actually make things more layered. It's just the code lying about being
layered while it's actually spaghetti.
2018-08-12 21:10:27 +00:00
iphydf
4ed6e59992
Fix enumerator names to comply with toxcore naming standards. 2018-08-12 20:07:18 +00:00
iphydf
767ccbb387
Avoid forward declaration of rtp structs.
Forward declarations are problematic, as they easily allow introducing
cyclic dependencies.
2018-08-12 19:54:27 +00:00
iphydf
b2590e2f44
Fix style in bwcontroller module.
* Comments in macros must be `//` style.
* No inner structs.
* Named callback types.
* `++i` instead of `i++`.
* No assignments as expressions.
2018-08-12 18:26:31 +00:00
iphydf
1de8b020cb
Remove all uses of the PAIR macro in toxav. 2018-08-12 11:38:23 +00:00
iphydf
5d15b5930d
Remove last use of the MIN macro.
We use functions for this instead.
2018-08-12 11:38:23 +00:00
iphydf
064ffe5875
Make a separate struct Tox containing the Messenger.
This allows Tox to contain additional data on top of Messenger, making
Messenger not necessarily the most top-level object. E.g. groups are
built on Messenger and currently awkwardly void-pointered into it to
pretend there is no cyclic dependency.
2018-08-04 09:29:15 +00:00
iphydf
f627a26a7b
Run Clang global static analysis on Travis.
This uses a single .cc file containing almost all the code in the
repository to perform whole program analysis.
2018-07-22 02:34:30 +00:00
iphydf
7c2b95ef5e
Remove redundant casts to the same type.
Also removed an unused identifier in messenger_test.c.
2018-07-21 15:09:39 +00:00
iphydf
adb12d5340
Add github usernames to TODOs. 2018-07-21 14:56:21 +00:00
iphydf
b6b3cdbf25
Synchronise parameter names in headers with those in the implementation. 2018-07-21 14:46:31 +00:00
iphydf
9a96bb9a5b
Reduce nesting by doing more early returns on error.
This almost entirely avoids any else-after-return in toxcore. One case is
left, and that one is more readable this way.

Why no else after return: https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return
Why exemptions exist: https://blog.mozilla.org/nnethercote/2009/08/31/no-else-after-return-considered-harmful/
2018-07-21 14:22:41 +00:00
iphydf
beeb9b4335
Style fixes in TCP code; remove MIN and PAIR from util.h.
* 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-12 20:21:42 +00:00
iphydf
abc17b0f89
Factor out time keeping code into its own module: mono_time.c.
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-09 21:04:50 +00:00
iphydf
c0c3098737
Avoid side-effectful assignments in conditionals.
Only in audio.c for now. This should be done everywhere.
2018-07-08 19:34:45 +00:00
iphydf
b3889f0f05
Remove VLA usage from send_audio_packet.
Also use `net_pack_u16` in that function instead of manual ntohs+memcpy
and `net_unpack_u16` in its receiving counterpart.
2018-07-08 13:59:37 +00:00
iphydf
08ff19a63b
Call the "peer leaves" callback only once on group delete.
We used to pass the actual peer numbers of peers leaving, but we no
longer know these in the PGC world, so we don't pass them anymore.
2018-07-07 16:02:00 +00:00
iphydf
3ef1f839fc
Add some tests for our ring_buffer implementation.
These can serve as documentation until we write actual api docs, probably
using apidsl.
2018-07-04 10:37:46 +00:00
iphydf
29b2dd6315
Use clang-format for C++ code.
`clang-format -style='{BasedOnStyle: Google, ColumnLimit: 100}'`
2018-06-24 20:17:53 +00:00
iphydf
8e00294b3c
Add Logger to various net_crypto functions.
In preparation for adding log statements.

Also, fix an uninitialised variable warning in cppcheck.
2018-06-24 19:17:32 +00:00
Robin Lindén
2f80e2206c
Only check full rtp offset if RTP_LARGE_FRAME is set 2018-06-16 22:50:07 +00:00
iphydf
be797d4b03
Move system header includes from network.h to network.c 2018-05-20 15:42:42 +00:00
Maxim Biro
7d399cedcf
Improve network error reporting on Windows
Windows doesn't report network errors though errno, it has its own facilities.
2018-04-17 19:07:50 -04:00
iphydf
aa05095419
Remove the use of the 'hh' format specifier.
It's not supported in mingw.

See https://github.com/TokTok/c-toxcore/issues/786.
2018-03-16 01:57:26 +00:00
Robin Lindén
5600251efe
Don't set RTP_LARGE_FRAME on rtp audio packets 2018-03-09 17:18:39 +00:00
Robin Lindén
5da8c8d5de
Don't throw away rtp packets from old Toxcore 2018-03-09 17:06:41 +00:00
iphydf
d3b286cb43
Fix a bunch of compiler warnings and remove suppressions. 2018-02-24 22:20:22 +00:00
sudden6
03b55cde1a
make groupnumber uint32_t
fixes #606
2018-02-20 20:58:54 +01:00
zoff99
721358208b
Improve video key frame sending.
This change does not include the addition of VP9. We do that in a
separate pull request.

Changes:

* fix the video bug (video frames larger than 65KBytes) by sending full
  frame length in alternate header field
* improve video frame reconstruction logic with slots
* configure video encoder and decoder to be multihtreaded
* set error resilience flags on video codec
* change encoder and decoder softdeadline
2018-02-11 23:31:46 +00:00
iphydf
36ba80aacb
Remove csrc from the RTPHeader struct.
This is not used by anything in the code, so we shouldn't have it in the
header.
2018-02-08 13:20:40 +00:00