Commit Graph

287 Commits (master)

Author SHA1 Message Date
Nicolas Hake 3edc6d9ead Fix misleading indentation on several controlled statements
The C++ standard doesn't require us to stuff multiple statements
onto the same line, so we should avoid this for readability reasons.
This is especially true if one of the statements is controlled and
others aren't.
2018-12-31 14:27:14 +01:00
Lukas Werling 99ef4ce853 Implement TCP Simultaneous Open for IPv6 2018-03-09 23:20:00 +01:00
Lukas Werling ee34ac1b06 Add C4NetIOTCP::Bind() for binding without connect 2018-03-07 17:30:58 +01:00
Lukas Werling c0375bba72 Fix IPv4 address serialization on FreeBSD (hopefully) 2018-02-18 00:42:17 +01:00
Kevin Zheng 0c8371f113 Fix networking on FreeBSD (#1998) 2018-02-17 11:59:24 +01:00
Lukas Werling 298feab441 Change netpuncher protocol to be more extensible
- Each packet has a version field.

 - Clients connecting to the netpuncher always send a request packet.
   This allows the netpuncher to react differently depending on the
   client's version.

 - Encode packets as binary instead of ASCII. This allows adding fields
   while maintaining compatibility.
2017-12-14 17:22:38 +01:00
Lukas Werling 3476d76e61 C4NetIOUDP: Fix sending data before ConnOK
With my fix from 9eb2478b2 ("C4NetIOUDP: Fix timeout during non-MC
connection"), C4NetIOUDP would send data packets to the master server
before the ConnOK packet. The server would then discard these data
packets, resulting in a one-second delay until retransmission.
2017-12-14 14:35:07 +01:00
Lukas Werling 9eb2478b2c C4NetIOUDP: Fix timeout during non-MC connection
The "normal" connection process is a three-way handshake (Conn->,
<-Conn, ConnOK->). When establishing a multicast connection, this
handshake is repeated via the MC address. However, the code always
expected that second handshake to happen and thus ran into a timeout on
the client in the non-MC case, repeating the handshake a second time. In
the end, it usually still worked as the server supports reconnecting,
but packets may be lost in the process.
2017-12-02 18:52:10 +01:00
Lukas Werling 2d4934e4dd Fix C4NETIO_DEBUG 2017-12-02 18:52:10 +01:00
Tushar Maheshwari a661eab867 Automatic fixes using clang-tidy for header files
A follow-up on a previous PR GH-41. The discussion in the forum can be
viewed at http://forum.openclonk.org/topic_show.pl?pid=33086.
Run clang-tidy (without auto, pass-by-value and using checks) to fix the
header files not modified in the previous PR.

Summary of the changes:

 - C++11 member initialization.
 - nullptr instead of 0 for pointers.
 - override for functions declared virtual in base class.
 - default trivial special member functions
2017-05-15 13:46:46 +02:00
Tushar Maheshwari 3a4f49ad90 Revisit #includes
Consolidate the include statements scattered across the code in accordance
with the comment in C4Include.h. The advantages are listed in the same
comment.
Furthermore, it follows llvm-include-order which is the logical
extrapolation of the project's style guideline wherever possible
(C4Include.h being the most-frequent exception).
2017-05-15 13:24:59 +02:00
Tushar Maheshwari e58a7884e4 Automatic fixes using clang-tidy
See http://forum.openclonk.org/topic_show.pl?tid=3376 for discussion.

Close GH-41
2017-05-03 20:30:45 +02:00
Sven Eberhardt bcecff2811 Fix BOOL->bool conversion 2017-03-26 21:20:39 -04:00
Nicolas Hake c56bc4193e Replace InterlockedFoo by std::atomic
Atomic increments/decrements are part of C++11, so we don't need to use
or implement InterlockedWhatever anymore.
2017-03-23 17:03:16 +01:00
Lukas Werling 22161ae561 Client: Send netpuncher request as soon as possible
Previously, the SReq packet would only be sent after receiving an
ID from the netpuncher. Instead, we can send the request as soon as the
C4NetIOUDP connection setup finishes.
2017-03-21 17:14:33 +01:00
Lukas Werling d4bb760b17 Move OnPuncherConnect to C4Network2
All the other puncher handling functions are there as well.
2017-03-21 17:14:33 +01:00
Lukas Werling 8ca3801741 Do the initial client->host connection in stages
With the IPv6 support, hosts now often list around 20 addresses.
However, most of these are local only and thus rarely result in a
successful connection. With the introduction of address sorting in
7d5596220 ("Sort addresses used for initial host connection",
2017-02-26), the connection succeeds with the first few addresses most
of the time.

This commit changes the initial connection process to start with only
the first four addresses. After 100 ms, it proceeds with the next four
addresses and so on. This should reduce the packet volume significantly
as the connection should be established after only one or two steps.

We may want to tweak the parameters if this turns out to make joining
slower in practise. In a "normal" setup, the first four addresses should
be the IPv6 privacy and stable addresses, and the next four addresses
should include the IPv4 addresses from masterserver and netpuncher.
100 ms are long enough to get an answer from the host and short enough
to not bother the player too much.
2017-03-17 23:02:45 +01:00
Julius Michaelis 183c6e076f silence 'could not connect to' spam in lobby 2017-03-14 22:49:35 +01:00
Sven Eberhardt be66da2c7b Fix editor network join on Windows 2017-03-11 15:10:25 -05:00
Nicolas Hake 41f4779d74 StdCompiler: Use terms "Serializer" and "Deserializer"
Instead of "Compiler" and "Decompiler", which make me look up what's
even going on each time I see them, use the standard terms "serializer"
and "deserializer".
2017-03-11 15:05:41 +01:00
Lukas Werling 3ebedd0c5f Rank private/UL addresses lower than global ones
Also adds some tests. Yay tests!
2017-02-28 22:15:29 +01:00
Lukas Werling d7e71d8362 Double the maximum address count to accomodate IPv6
With the addition of IPv6, some computers with lots of addresses are
reaching the old address limit of 20 addresses. We'll have to see how
this works out in practise. Maybe we'll have to do the connection in
stages to prevent sending out too many packets at once (like only
connecting to the first five addresses initially, then after a timeout
the next five, and so on).
2017-02-27 22:52:24 +01:00
Lukas Werling aa5f5cd654 Convert IPv4-mapped IPv6 peer addresses to IPv4
This avoids duplicating these addresses when broadcasting them.
2017-02-26 23:36:32 +01:00
Lukas Werling 7d55962208 Sort addresses used for initial host connection
Computers with multiple (possibly virtual) network adapters can have
tons of link-local fe80::/64 IPv6 addresses. Connections to those hosts
would run into a timeout before getting to public addresses behind the
link-local ones.

By sorting the address list, we can prioritize public IPv6 addresses if
supported by the client, then try IPv4 before working through the swamp
of link-local addresses.
2017-02-26 23:36:32 +01:00
Lukas Werling a4492dd828 Fix double escaping of Statistics JSON
As newlines are already escaped in the JSON, this is safe.
2017-02-18 19:08:15 +01:00
Lukas Werling 87ee44964c Send script-defined statistics to the masterserver
After GameOver(), the global function CollectStatistics() is called
which in turn calls CollectStats() on all definitions and the Scenario.
The results are collected into a proplist and sent to the masterserver
as JSON.

The intended purpose is to collect statistics like weapon kill counts
and evaluate them across all online games to improve balancing.
2017-02-17 23:29:16 +01:00
Lukas Werling 181f7ab471 Prefer public/stable IPv6 source addresses
We don't benefit at all from privacy addresses as we're publishing all
local addresses in any case. By preferring stable addresses, we can
avoid reconnection issues after the preferred address changes.

This API is defined in RFC5014, but apparently only implemented in
Linux.
2017-02-14 21:44:05 +01:00
Sven Eberhardt 2b888fd136 Enlarge initial client connection dialogue to accommodate long ipv6 addresses 2017-02-12 11:48:55 -05:00
Lukas Werling 487fcc362d Linux: Read IPv6 addresses from /proc/net/if_inet6
In contrast to getifaddrs(), /proc/net/if_inet6 allows filtering
deprecated privacy addresses. As these addresses generally won't be
useful for new connections, there's no reason to include them and they
only cause unnecessary connection attempts.
2017-02-02 22:23:12 +01:00
Maikel de Vries 4d6be35c32 allow script players to join in network rounds (#1885) 2017-02-02 21:47:56 +01:00
Lukas Werling 459adbd199 Fix local network discovery on Windows (#1886)
On Windows, we cannot resolve addresses using getaddrinfo() before
initializing Winsock. By storing the address as string, the address
parsed later on.
2017-01-21 16:03:03 +01:00
Lukas Werling e3a0f2f8b5 Implement Happy Eyeballs for C4Network2HTTPClient
This should make masterserver requests more reliable for users with a
bad IPv6 connection.

See RFC6555
2017-01-18 21:55:17 +01:00
Lukas Werling 894edfce5b Allow adding connections from other addresses
Forcing a static address does not work for IPv6 where everyone has
multiple addresses that change over time. For example, adding a new
connection would fail if the preferred privacy address changes during
a game.
2017-01-18 21:55:17 +01:00
Lukas Werling 6677295bac Serialize addresses in UDP connection packages
The previous approach of just embedding the raw struct fails miserably
when trying to transfer AF_INET6 across platforms.
2017-01-18 21:55:17 +01:00
Lukas Werling 6af32a7c46 Fix IPv6 sockets on Windows not being dual-stack
On Linux, all IPv6 sockets are dual-stack per default; on Windows, they
are not. It's still a good idea to set the option on Linux as well as
the default value can be changed.

When connecting via TCP, C4NetIO still creates IPv4 sockets, so no dual
stack option is required there.
2017-01-18 21:54:50 +01:00
Lukas Werling a9ee16a287 Change C4NetIOUDP broadcast to IPv6
It's not actually used anywhere, but it's not broken now!

This also moves the low-level and OS-specific GetLocalAddresses code to
C4NetIO where it's fitting better than in C4Network2Client.
2017-01-18 21:54:50 +01:00
Lukas Werling 890deb997d Improve "unexpected address family" asserts 2017-01-18 21:54:50 +01:00
Lukas Werling efe0b134ef Use UDP address from puncher to derive TCP address
This is necessary for dual stack connections where the masterserver will
only an IPv6 address and the netpuncher will only return a UDP address/port.
2017-01-18 21:54:50 +01:00
Lukas Werling 602d62cf52 Implement netpunching for IPv6 2017-01-18 21:54:50 +01:00
Lukas Werling b3ef196935 Remove ResolveAddress()
As setting a default port is a common operation, add a helper function
for this.
2017-01-18 21:54:50 +01:00
Lukas Werling 85f5b3cb75 Fix local network discovery 2017-01-18 21:54:49 +01:00
Lukas Werling 5a09c1d4a5 Convert addresses from puncher to IPv4
Addresses from the puncher would show as [::ffff:1.2.3.4] and be a bit
confusing.
2017-01-18 21:54:49 +01:00
Lukas Werling 68d18bf872 Remove obsolete CompileFunc for in_addr 2017-01-18 21:54:49 +01:00
Lukas Werling ef9be2e24e Change (discovery) multicast to IPv6
We use ff02::1 as discovery multicast address.

This "all nodes" multicast address is good enough for discovery in the
local network as packets there are likely broadcasted over ethernet
anyways.
2017-01-18 21:54:35 +01:00
Lukas Werling 793207ce28 Fix connections to link-local IPv6 addresses
Link-local IPv6 addresses are valid on all interfaces and thus need an
interface specifier / scope id, e.g. fe80::1%eth0.
2017-01-18 21:54:02 +01:00
Lukas Werling 5d803d3be3 Improve "could not find connection" error message 2017-01-09 20:35:04 +01:00
Lukas Werling 1925f47440 Fix C4NETIO_DEBUG option 2017-01-09 20:35:04 +01:00
Lukas Werling 592ef85672 Fix local IPv6 address discovery 2017-01-09 20:35:04 +01:00
Nicolas Hake 102047f537 Implement IPv6 support to C4NetIO 2017-01-09 20:34:43 +01:00
Lukas Werling 8d9eedffe4 Reset C4NET2IO_DUMP_LEVEL to 1 (#1869) 2016-12-19 17:30:19 +01:00