Commit Graph

4565 Commits

Author SHA1 Message Date
Jan Malakhovski
e7a5f52c14
Collect PACKET_ID* constants in net_crypto.h, cleanup their uses 2018-07-19 19:24:00 +00:00
iphydf
3f6b6842f3
Use string comparison operator in configure.ac.
.. to compare strings. `==` is for numeric values.
2018-07-19 16:53:48 +00:00
iphydf
bf79fdbb43
Link -lsocket and -lnsl for socket functions on Solaris.
Also, added some #defines to make symbols visible that are in BSD but not
in UNIX. Solaris needs these, since it's fairly strict with its symbol
visibility in system headers.
2018-07-19 15:05:26 +00:00
zugz
7c05b3a85e
replace LOGGER_ERROR with LOGGER_DEBUG on send_data_packet() failure in send_lossless_packet() 2018-07-18 21:17:10 +00:00
iphydf
7f6c681cfa
Use enums for group packet types.
Also moved some macros up to the beginning of `group.c`. This change
brings us closer to the PGC PR.
2018-07-18 21:05:42 +00:00
hugbubby
a592f0fa87 Wrong use of unsigned integer. 2018-07-18 13:55:30 -07:00
hugbubby
864d1c15e4 Using stdint instead of int/long
Did my best to surmise the size requirements of
these integers, will do the rest of the tests soon. Also added a todo
and made an obsessive change to a for loop.
2018-07-18 13:55:30 -07:00
iphydf
392eef7900
Correct the max hostname length constant.
256 bytes including NUL byte is confusing and makes for really annoying
bindings to other languages that don't account for NUL bytes in their
string length. We pass C strings, not byte arrays, for hostnames, so 255
makes more sense here.
2018-07-18 00:32:54 +00:00
iphydf
13aa33a0f8
Set _XOPEN_SOURCE to 700 for FreeBSD. 2018-07-16 01:03:30 +00:00
iphydf
9eacfafff7
Set C++11/C99 flag manually in older cmake on not-msvc.
These flags are needed so the code actually compiles, so can't only be
set on Travis.
2018-07-15 23:01:32 +00:00
Maxim Biro
c0b4cd156f
Simplify Travis-CI FreeBSD build 2018-07-15 18:37:10 -04:00
iphydf
b4cf9808e9
Use the correct repository name in the coverage badge. 2018-07-15 16:52:04 +00:00
iphydf
90a63e8188
Add conference_by_uid and conference_get_uid functions.
These are useful once we have persistent group chats, so clients can
store data associated with this permanent group identifier.
2018-07-13 19:30:02 +00:00
iphydf
3d5fd9c2d0
Limit number of group chats to 65536.
By changing numchats from uint32_t to uint16_t. This is done in PGC. This
PR is making that change in master to reduce the diff in the PGC branch.

Also:
* Inverted groupnumber_not_valid and renamed to is_groupnumber_valid.
* Renamed realloc_groupchats to realloc_conferences and made it return bool.
* Added setup_conference function that currently just zeroes the
  conference structure but later will initialise more values.
* Made some `i` iterator variables local to the for-loop using
  for-init-decl. This is also done in PGC.
2018-07-12 23:58:24 +00:00
iphydf
2377cac94b
Use named function types for group callbacks.
Also some other cleanups. This PR means that future PRs, i.e. the PGC PR,
must not break the rules established here.
2018-07-12 21:15:51 +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
cbda01021c
Fix style in DHT.c.
* 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-12 09:32:46 +00:00
iphydf
37f8f566d5
Fix style in some header files.
* Enums must by typedef'd.
* Comments at end of `#define` must be `//` comments.
* Typedef structs must not be anonymous.
* `;` at the end of a `#define` is invalid.
* Callback typedefs must list their parameter names.
* No nested structs.
* No inline use of function pointer types. Only typedef'd callback types
  are allowed.
* Enum types are spelled in Camelsnake_Case.
* The argument to `#error` must be a string literal.
2018-07-12 09:19:02 +00:00
iphydf
0b7e29e019
Add the bazel build as one of the PR-blocking builds. 2018-07-10 16:45:50 +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
4e21c06551
Add a thread-safe version of unix_time and friends.
These are not used in a thread-safe way, but it opens the path towards
per-tox-instance time keeping and removal of some unsafe global state.
2018-07-09 21:03:08 +00:00
iphydf
c8697ccc20
Move load_state and its helper functions to their own module. 2018-07-09 20:36:39 +00:00
iphydf
751d0948ab
Use named function types for callbacks in net_crypto.
Also:
* compound statements (blocks, e.g. in if/else) must be non-empty.
  Comments don't count.
* `=` is not allowed in subexpressions. We treat it as statement-only.
* `++i` is preferred over `i++` in statements.
* `Type_Names` are camelsnake-case.
2018-07-08 22:32:10 +00:00
iphydf
76e1d05da6
Use named function types for friend_requests callbacks.
Also:
* `#define` must be scoped. If it's used outside a scope, it must be
  defined outside that scope (global `#define` does not need a matching
  `#undef`).
2018-07-08 22:02:52 +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
465c9380ea
Clarify the intent of "file kinds" in the API. 2018-07-08 19:13:23 +00:00
iphydf
2b49f80395
Rename BS_LIST to BS_List to follow the naming conventions.
`BS_LIST` would be a constant. `BS_List` is a type name.
2018-07-08 19:03:52 +00:00
iphydf
ebdc43285a
Use named types for onion callbacks.
This is now a style rule: you can only use typedef'd function types.

Previous rules now applied in `onion_*.c`:
* `struct`s must have a name (typedef of unnamed struct is not allowed).
* `++i` for increment-stmt, not `i++`, e.g. in loops.
* Only a single declarator per struct member declaration.
* Type_Names vs. variable_names.
2018-07-08 18:23:45 +00:00
iphydf
819fe534ea
Use named function types for friend_connection callbacks.
Also:
* No inner structs.
* One declarator per member declaration.
* Function names are snake_case.
* Names ending in `_cb` are function types.
* `++i` is preferred over `i++`.
2018-07-08 18:06:39 +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
3c1025d2dc
Factor out the actual test code from conference_test.
Also, renamed simple_conference_test to conference_simple_test so it's
sorted together with the other conference tests.

Next step is to use run_auto_test.h for the conference test.
2018-07-07 10:35:35 +00:00
iphydf
9d5c55b4b3
Add a test that reproduces the NULL peer nick bug. 2018-07-06 11:14:44 +00:00
hugbubby
47a527509d
lan_discovery_test and version_test cleanup
Removed a pointless declaration of a function in lan_discovery_test
and cleaned up the one error message there. Did an entire restructuring
of the version_test using macros that resulted in fewer lines of code but more
thorough testing.

Formatting of version_test.c

back to old way, save comments and one change

Missing space
My greatest enemy

Add `#include <cstdio>` for `std::printf`.

Make tox.c unambiguously parseable.

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

Use run_auto_test.h test fixture for some auto-tests.

Most of the auto-tests should use this fixture, but I've only done a few
to set an example.
2018-07-06 10:25:47 +00:00
iphydf
597f23bdd9
Use run_auto_test.h test fixture for some auto-tests.
Most of the auto-tests should use this fixture, but I've only done a few
to set an example.
2018-07-05 23:41:27 +00:00
iphydf
8739f7fccb
Make tox.c unambiguously parseable.
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-07-05 23:09:28 +00:00
iphydf
64d0297acc
Add #include <cstdio> for std::printf. 2018-07-04 14:21:12 +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
1a54be06cd
Simplify Travis CI builds.
Have one script per build. This means more duplication between the
scripts, but it's much easier to understand and to run locally.
2018-07-01 08:35:44 +00:00
iphydf
706fad1ce8
Add a test to try and overflow the send queue in net_crypto. 2018-06-29 23:24:20 +00:00
Evgeny Kurnevsky
52f21e3251
Correct check for net_crypto packet index. 2018-06-29 23:02:01 +00:00
iphydf
b9a75d98b2
Remove broken conference tests.
These display some idea, but the tests are not implemented correctly. We
will need to implement the idea correctly later, but for now we can't use
these.
2018-06-29 18:25:44 +00:00
iphydf
86a6b17555
Fix leak of Logger instances in dht_test. 2018-06-28 21:25:21 +00:00
iphydf
7c4b971d67
Various minor cleanups in net_crypto.
* Consistently use `num_packets_array` to get the packet count in the
  packet buffer.
* Use `const` in more places.
* Typo fix: begginning.
* Rewrite `length < 1` for unsigned int to `length == 0`.
* Limit scope of some loop variables by using for-init-decl.
* Use early return in error paths to reduce indentation and for clarity.
* Use `net_unpack_*` instead of manual `ntohs`.
* Fix an uninitialised stack variable copy.
* Fix a potential null pointer dereference.
* Consistently use `get_crypto_connection`. It was inlined in some
  places. I de-inlined it now.
* Add Loggers to some functions in preparation for adding log statements.
2018-06-28 16:04:57 +00:00
hugbubby
4e3bfac47d
Another TCP_test.c upgrade
Mostly documentation + comments. Some cases where code was removed
in exchange for more compact/less sprawly for loops. Introduced a
function that removed like 30 lines of repeated code.
2018-06-28 14:05:03 +00:00
cotox
72863b9b80
Add missing MAX_HOSTNAME_LENGTH doc. 2018-06-27 02:58:56 +00:00
cotox
5b14542d3b
Make arg host understand clearly.
Rename args `host:port` from `address:port`.
The *address* is well known as *Tox Address* in this project. Then we
should reserve *addres* to it, and use *host* to express the hostname or
IP address in TCP domain.
2018-06-26 11:45:17 +00:00
Robin Lindén
ae7899cab8
Release v0.2.3 2018-06-25 23:49:52 +02:00
iphydf
9b7d828f83
Only run astyle if the astyle binary exists. 2018-06-25 20:35:16 +00:00
iphydf
957508f698
Remove utils.c and utils.h from toxencryptsave build.
These were deleted earlier.
2018-06-25 20:27:21 +00:00