Commit Graph

125 Commits

Author SHA1 Message Date
Diadlo
8a8442a30c
Remove upper bound of save size 2017-11-20 16:53:21 +03:00
Diadlo
c506d73d5d
Fix assert for the first port value
Port of the first tox instance will be 33445 only if this port was not
in use during testing
2017-11-20 16:53:19 +03:00
yangfl
2651193b99
Fix typo 2017-11-19 23:52:23 +01:00
iphydf
cb69b8a986
Build tests on appveyor, the MSVC build.
Tests are not actually ran on appveyor for now, since they all fault for
some reason. For now, we just build them. Also, some tests are disabled
on msvc entirely, because they don't even compile. We'll need to look
into those, later. They are disabled using `MSVC_DONT_BUILD`.
2017-06-05 13:45:20 +00:00
Diadlo
50c526e1a5
Move c_sleep to helpers.h and misc_tools.h
Also fix a mistake with forgotten braces around parameter
2017-03-25 20:40:34 +03:00
iphydf
6ae33c16cf
Add VLA compatibility macro for C89-ish compilers. 2017-01-28 20:49:12 +00:00
David Zero
8ef1f35ca7 Revert "Revert "Portability fixes""
This reverts commit 59e2a844f0, and
defines _DARWIN_C_SOURCE in toxcore/network.c
2017-01-06 04:20:00 -08:00
endoffile78
59e2a844f0 Revert "Portability fixes"
This reverts commit f3469070fe.
2017-01-05 15:16:56 -06:00
David Zero
f3469070fe Portability fixes
- CFLAG gnu99 was changed to c99.
- CXXFLAG c++98 was changed to c++11.
- CFLAG -pedantic-errors was added so that non-ISO C now throws errors.
- _XOPEN_SOURCE feature test macro added and set to 600 to expose SUSv3
  and c99 definitions in modules that required them.
- Fixed tests (and bootstrap daemon logging) that were failing due to
  the altered build flags.
- Avoid string suffix misinterpretation; explicit narrowing conversion.
- Misc. additions to .gitignore to make sure build artifacts don't wind
  up in version control.
2017-01-04 13:44:39 -08:00
iphydf
db71602731
Use tox_options_set_* instead of direct member access.
Also added a `tox_options_copy` function for cloning an options object.
This can be useful when creating several Tox instances with slightly
varying options.
2016-12-22 10:53:39 +00:00
iphydf
82515f92ee
Move log callback to options.
Previously, all log messages generated by tox_new (which is quite a lot)
were dropped, because client code had no chance to register a logging
callback, yet. This change allows setting the log callback from the
beginning and removes the ability to unset it.

Since the log callback is forever special, since it can't be stateless,
we don't necessarily need to treat it uniformly (with `event`).
2016-11-06 20:35:09 +00:00
iphydf
cf94537266
Enable all possible C compiler warning flags.
We disable the ones that fire, so we can use -Werror. We can then
investigate each warning individually and see whether to fix it or to
keep silencing it.
2016-11-06 01:32:10 +00:00
iphydf
96c672aef5
Compile as C++ for windows builds.
Compiling as C++ changes nothing semantically, but ensures that we don't
break C++ compatibility while also retaining C compatibility.

C++ compatibility is useful for tooling and additional diagnostics and
analyses.
2016-11-02 18:50:41 +00:00
iphydf
6d0c8060c1
Remove duplicate tests: split tests part 2. 2016-10-11 21:29:58 +02: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
0d347c2b2e
Minor cleanups: unused vars, unreachable code, static globals.
- All global variables should be static unless they have an explicit
  extern declaration in a header file.
- `to_compare` was not used in encryptsave and toxav tests.
- `break` in switch cases is not required directly after `return`,
  `goto`, or a noreturn function like `abort`.
2016-09-24 20:52:09 +01:00
Jfreegman
dd2965a58f Make group callbacks stateless 2016-09-21 15:33:55 -04:00
Jfreegman
8e43ca834c Complete old groupchat conversion to new API 2016-09-17 19:11:28 -04:00
iphydf
c0397a0a46 ApiDSL'ing old group chats (now: conference). 2016-09-17 19:11:28 -04:00
iphydf
5da85c582d
Fix for windows dynamic libraries. 2016-09-17 19:54:22 +01:00
iphydf
37c041f815
Clean up Travis build a bit in preparation for osx/win. 2016-09-16 11:22:23 +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
Chuong Vu
d9cd1b0c64 Use correct logical operator for tox_test
Check to ensure that all 3 tox instances are up rather than
just one.
2016-09-11 10:47:15 -07:00
michael bishop
05f474b4df
make the majority of the callbacks stateless and add some status to a testcase 2016-09-10 01:09:37 -03: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
iphydf
5b57ab6332
Improve C standard compliance.
- Don't cast between object and function pointers.
- Use standard compliant `__VA_ARGS__` in macros.
- Add explicit `__extension__` on unnamed union in struct (it's a GNU
  extension).
- Remove ; after function definitions.
- Replace `const T foo = 3;` for integral types `T` with `enum { foo = 3 };`.
  Folding integral constants like that as compile time constants is a GNU
  extension. Arrays allocated with `foo` as dimension are VLAs on strictly
  compliant C99 compilers.
- Replace empty initialiser list `{}` with zero-initialiser-list `{0}`.
  The former is a GNU extension meaning the latter.
- Cast `T*` (where `T != void`) to `void *` in format arguments. While any
  object pointer can be implicitly converted to and from `void *`, this
  conversion does not happen in variadic function calls.
- Replace arithmetic on `void *` with arithmetic on `char *`. The former
  is non-compliant.
- Replace non-`int`-derived types (like `uint16_t`, which is
  `short`-derived) in bit fields with `int`-derived types. Using any type
  other than `int` or `unsigned int` (or any of their aliases) in bit
  fields is a GNU extension.
2016-09-06 11:09:10 +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
a759ddc7eb
Re-enable group chat tests.
They don't seem to be a lot less stable than the rest. Either way we regularly
need to restart builds to make timeouts go away.
2016-09-02 13:57:46 +01: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
Gregory Mullen (grayhatter)
8c8532a984
Reduce the timeout on travis to something much more reasonable
10x timeouts forces travis to kill our build without offering anything helpful
2016-08-25 11:52:46 -07:00
Gregory Mullen (grayhatter)
1f94c96266
Make the friend message callback stateless 2016-08-20 11:07:49 -07:00
Gregory Mullen (grayhatter)
0e18966a27
Make Typing change callback stateless
Moved a few #defines to the top of the header for better readability
2016-08-19 16:13:23 -07:00
iphydf
bdf5ac37b4
Make friend_status_message callback stateless.
See #40 for details.
2016-08-18 17:19:23 +01:00
iphydf
6935643f9a
Fix some compiler warnings. 2016-08-18 17:10:15 +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
dd8a568141
Make self_connection_status callback stateless.
**What are we doing?**

We are moving towards stateless callbacks. This means that when registering a
callback, you no longer pass a user data pointer. Instead, you pass a user data
pointer to tox_iterate. This pointer is threaded through the code, passed to
each callback. The callback can modify the data pointed at. An extra indirection
will be needed if the pointer itself can change.

**Why?**

Currently, callbacks are registered with a user data pointer. This means the
library has N pointers for N different callbacks. These pointers need to be
managed by the client code. Managing the lifetime of the pointee can be
difficult. In C++, it takes special effort to ensure that the lifetime of user
data extends at least beyond the lifetime of the Tox instance. For other
languages, the situation is much worse. Java and other garbage collected
languages may move objects in memory, so the pointers are not stable. Tox4j goes
through a lot of effort to make the Java/Scala user experience a pleasant one by
keeping a global array of Tox+userdata on the C++ side, and communicating via
protobufs. A Haskell FFI would have to do similarly complex tricks.

Stateless callbacks ensure that a user data pointer only needs to live during a
single function call. This means that the user code (or language runtime) can
move the data around at will, as long as it sets the new location in the
callback.

**How?**

We are doing this change one callback at a time. After each callback, we ensure
that everything still works as expected. This means the toxcore change will
require 15 Pull Requests.
2016-08-17 14:57:20 +01:00
iphydf
459f8f2013
Check code formatting on Travis.
We run astyle on Travis and check if there is a diff. The build terminates if
git finds a difference.
2016-08-12 01:00:00 +01:00
Gregory Mullen (grayhatter)
6f3e689eeb
Fix a few issues with running Toxcore tests on Travis-CI
> increased the timeout for TCP tests because per @irungentoo the network on Travis-CI can be slow sometimes

> allowed groupchats test to restart on error until timeout This had to be done because current groupchats are fundamentally broken and 3/5 times they'll 'net-split' on connect

>> Drop group chat tests, add comment to the reason

> added some debugging information to TCP tests, and a #define to force IPV6 (Travis-CI only uses IPv4 on their containers) and decreased the itr interval

> Went crazy with timeouts for Tox network stuff on Travis. Tests on TCP will still randomly fail due to timeouts. I can't reproduce on any local system. So again per @irungentoo, Travis is slow, let's offer it a short bus.
2016-08-11 14:41:57 -07:00
irungentoo
f40a60575f
Slightly increased number of peers to announce to.
Some test fixes.
2015-12-01 20:11:53 -05:00
irungentoo
c259250abb
Fixed Tox reporting itself as being connected with TCP when using UDP only on LAN. 2015-07-03 21:52:53 -04:00
irungentoo
836daa9e95
Added save/load live test. 2015-06-12 23:05:37 -04:00
irungentoo
81d95809fd
Test fix. 2015-06-07 20:56:02 -04:00
irungentoo
f4d0b85284
Save DHT nodes in a smarter way. 2015-06-06 22:13:43 -04:00
irungentoo
bf90c63c27
Added test. 2015-06-05 22:11:19 -04:00
irungentoo
5196aa82ca
Added test. 2015-06-04 22:18:09 -04:00
irungentoo
17f7376581
Add a test for loading with a secret key. 2015-06-01 20:16:03 -04:00