Commit Graph

156 Commits

Author SHA1 Message Date
Maxim Biro c7f63737eb Revert "Implement tox_loop"
This reverts commit 5ff099763b.
2017-04-22 15:31:25 -04:00
Maxim Biro 5ed37e5438 Revert "Fix TokTok/c-toxcore#535"
This reverts commit 439f676d45.
2017-04-22 15:31:25 -04:00
Ansa89 439f676d45 Fix TokTok/c-toxcore#535 2017-04-16 10:49:56 +02:00
Diadlo 6c9b95750c Add TCP_INET family to ip comparator 2017-04-13 20:25:19 +00:00
Yuri f751fcfbf6 Added missing includes: <netinet/in.h> and <sys/socket.h>
Found these missing includes while compiling on FreeBSD 11.
2017-04-12 21:35:14 +00:00
Ansa89 5ff099763b Implement tox_loop 2017-04-01 17:47:34 +02:00
Diadlo f675474c08 Fix network malloc(0) bug 2017-03-26 12:40:52 +00:00
Diadlo c1e3358dcd Fix formatting with astyle
Fix #494
2017-03-04 15:32:00 +03:00
Diadlo f91af5c93a Move 'family' copying after all address checks
Fix #495
2017-03-04 15:32:00 +03:00
Diadlo b19a9e5464 Add part of platform-independent network API implementation
socket      -> net_socket
htons       -> net_htons
htonl       -> net_htonl
connect     -> net_connect
sendto      -> net_sendto_ip4
getaddrinfo -> net_getipport
sa_family_t -> Family
2017-02-26 23:16:16 +03:00
Diadlo f00006cf1d Add platform-independent Socket and IP implementation 2017-01-26 23:11:15 +03:00
zugz b630121f2f reduce thread-unsafe use of static variables
- rework ip_ntoa() to avoid use of static variables
- rework sort_client_list() to avoid use of static variables
- move static 'lastdump' into Messenger struct
- rework ID2String() to avoid use of static variables; rename to id_to_string()
- fetch_broadcast_info(): attempt to mitigate risks from concurrent execution
- current_time_monotonic(): attempt to mitigate risks from concurrent execution
- comment on non-thread-safety of unix_time_update
2017-01-21 22:08:52 +01:00
iphydf 8f96ca6d86 Update license headers and remove redundant file name comment.
"All rights reserved" was incorrect. The project was licensed under GPL3,
which means a lot of rights are licensed to everybody in the world, i.e.
not reserved to the "Tox Project".
2017-01-19 00:01:44 +00:00
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
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 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 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
iphydf 63e0008b7d const-correctness in windows code. 2016-09-16 14:45:52 +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 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 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 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 576f130615 Remove redundant return statements. 2016-08-31 23:51:39 +01:00
iphydf 3a9300368d Add newlines because astyle wants them.
We'll revert this once we move to clang-format.
2016-08-31 20:54:20 +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
iphydf 5d26ce1cf5 Fix a bug I introduced that would make toxcore fail to initialise a second time.
sodium_init returns 1 when the library was already initialised. Toxcore code
wasn't prepared to handle sodium errors, so it thought it was an allocation
error.

This error is still not handled correctly. If crypto fails to initialise, it
will think it's an allocation error. Fixing this requires too many code changes,
so must be done later.
2016-08-11 18:14:54 +01:00
iphydf fc330c1fa5 Silence/fix some compiler warnings.
Some of these (like the incompatible pointers one) are really annoying for
later refactoring.
2016-08-10 13:52:40 +01:00
Roman Yepishev c886f906a8 Move argument comments to the end of line 2016-02-27 14:32:49 -05:00
Roman Yepishev 9035325e56 Remove magic numbers from addr_resolve
* Add #defines for INET/INET6 returns
* Remove magic number 3 - exact AF_INET/INET6 result found.
* Updated network_test.c
2016-02-27 11:45:02 -05:00
Roman Proskuryakov 7d66c70037 add: more comments into network.c 2016-01-27 02:14:59 +03:00
Eniz Vukovic d6fdf16520 New Adaptive BR algorithm, cleanups and fixes 2015-10-10 23:54:23 +02:00
irungentoo 0045ace8a8 Small cleanups. 2015-05-02 21:55:42 -04:00
irungentoo 2ff39d3d54 Fixed windows warning. 2015-04-14 20:56:16 -04:00
irungentoo d05e39274c Make tox_new return TOX_ERR_NEW_PORT_ALLOC for all socket related errors. 2015-04-13 08:32:33 -04:00
irungentoo 405558258d Enable SO_REUSEADDR on TCP server socket. 2015-04-11 20:24:39 -04:00
irungentoo 7afab000f7 tox_new now sets error to TOX_ERR_NEW_PORT_ALLOC when binding to port fails. 2015-03-12 13:03:14 -04:00
irungentoo 73b9cf48f9 Merge branch 'worfox-new_api' into new_api 2015-03-08 19:08:33 -04:00
Christoffer Sterner 3315fd2571 Change LOGGER_DEBUG to LOGGER_ERROR for fail bind 2015-03-07 23:45:00 +01:00
Christoffer Sterner 10ca292f24 Change fprintf debug into LOGGER_DEBUG for consistency 2015-03-07 22:39:27 +01:00
irungentoo 2af1608059 Fixed debug fprintf. 2015-03-07 16:16:25 -05:00
irungentoo 7a82565c8c Merge branch 'port_range_option' of https://github.com/saneki/toxcore into new_api 2015-03-02 21:03:34 -05:00
saneki 6e8762b30a Allow for specifying the port range to use in Tox_Options 2015-02-27 11:58:00 -06:00