Commit Graph

77 Commits

Author SHA1 Message Date
Patric Stout 6550682b49
Codechange: minor bits and pieces related to fmt::format() (#11806)
- Don't make run-time formatting what can be done compile-time.
- Be explicit about run-time formatting.
- Fix datetime printing.
2024-01-16 21:10:34 +00:00
frosch b6c8f301be Codechange: Silence warnings about intentionally unused parameters. 2023-09-19 22:49:59 +02:00
Rubidium eaae0bb5e7 Codechange: automatic adding of _t to (u)int types, and WChar to char32_t
for i in `find src -type f|grep -v 3rdparty/fmt|grep -v 3rdparty/catch2|grep -v 3rdparty/opengl|grep -v stdafx.h`; do sed 's/uint16& /uint16 \&/g;s/int8\([ >*),;[]\)/int8_t\1/g;s/int16\([ >*),;[]\)/int16_t\1/g;s/int32\([ >*),;[]\)/int32_t\1/g;s/int64\([ >*),;[]\)/int64_t\1/g;s/ uint32(/ uint32_t(/g;s/_uint8_t/_uint8/;s/Uint8_t/Uint8/;s/ft_int64_t/ft_int64/g;s/uint64$/uint64_t/;s/WChar/char32_t/g;s/char32_t char32_t/char32_t WChar/' -i $i; done
2023-07-19 19:30:14 +02:00
Owen Rudge 1a3d1bca59 Remove: OS/2 port 2023-06-16 14:29:14 +01:00
Rubidium 55dfca1936 Codechange: replace seprintf with C++ style formatting 2023-06-05 23:25:59 +02:00
Peter Nelson 72018badff Codechange: Swap SocketList map key/value around.
This map is used store socket and address together, and, other than
checking that the address does not already have a socket, the data layout
does not seem particularly important.

However, as address is the key, technically it should not be modified,
and address may self-modify itself during comparisons.
2023-05-18 12:18:30 +01:00
Patric Stout 8adade26ed Feature: allow the use of STUN to connect client and server together
This method doesn't require port-forwarding to be used, and works for
most common NAT routers in home setups. But, for sure it doesn't work
for all setups, and not everyone will be able to use this.
2021-07-16 19:50:29 +02:00
Patric Stout 1baec41542 Change: groundwork to allow ServerAddress to use invite codes
Normally TCPConnecter will do a DNS resolving of the connection_string
and connect to it. But for SERVER_ADDRESS_INVITE_CODE this is different:
the Game Coordinator does the "resolving".

This means we need to allow TCPConnecter to not setup a connection
and allow it to be told when a connection has been setup by an external
(to TCPConnecter) part of the code. We do this by telling the (active)
socket for the connection.

This means the rest of the code doesn't need to know the TCPConnecter
is not doing a simple resolve+connect. The rest of the code only
cares the connection is established; not how it was established.
2021-07-11 20:38:42 +02:00
Patric Stout cee8174d02 Codechange: track servers with a ServerAddress instead of a NetworkAddress
This allows future extensions to have different ways of referencing
a server, instead of forcing to use IP:port.
2021-07-11 20:38:42 +02:00
rubidium42 667301e3ec Codechange: [Network] Make hostname/client IP return strings instead of a C-string 2021-06-15 06:13:00 +02:00
rubidium42 a91e29b656 Codechange: [Network] Let IsInNetmask use std::string 2021-06-15 06:13:00 +02:00
rubidium42 36705f1dc0 Codechange: [Network] Simplify formatting of network addresses to string 2021-06-15 06:13:00 +02:00
rubidium42 55a11710a6 Codechange: convert printf DEBUG statements to fmt Debug statements 2021-06-13 12:45:45 +02:00
Rubidium 031e91de6e Fix: [Network] Check on CIDR for netmask check considered everything valid 2021-05-15 10:16:10 +02:00
Patric Stout b136e65cf9
Change: reworked the debug levels for network facility (#9251)
It now follows very simple rules:
0 - Fatal, user should know about this
1 - Error, but we are recovering
2 - Warning, wrong but okay if you don't know
3 - Info, information you might care about
4 -
5 - Debug #1 - High level debug messages
6 - Debug #2 - Low level debug messages
7 - Trace information
2021-05-12 16:34:02 +02:00
Patric Stout 8f4a612a7c
Change: reworded many of the network errors during connect/listen (#9230)
Also changed some levels to 0, as a failing listen() is something
we should tell the user about. Hiding this information is a bit
evil.
2021-05-10 13:40:28 +02:00
Patric Stout f7e390bdc0
Feature: use Happy Eyeballs to make network connections (TCP-only) (#9199)
Hostnames like "content.openttd.org" resolve into multiple IPv4 and IPv6.
It is possible that either of the IPs is not working, either due to
a poorly configured OS (having IPv6 but no valid route), broken network
paths, or a service that is temporary unavailable.

Instead of trying the IPs one by one, waiting for a 3s timeout between
each, be a bit more like browsers, and stack attempts on top of each
other with slight delays. This is called Happy Eyebells.

Initially, try the first IPv6 address. If within 250ms there is no
connection yet, try the first IPv4 address. 250ms later, try the
second IPv6 address, etc, till all addresses are tried.

If any connection is created, abort all the other (pending) connections
and use the one that is created. If all fail 3s after the last connect(),
trigger a timeout for all.
2021-05-06 23:13:35 +02:00
rubidium42 6c4a65eeb8 Codechange: [Network] Use std::string for NetworkAddress' host name 2021-05-06 20:33:26 +02:00
rubidium42 22720332eb Codechange: encapsulate network error handling 2021-05-01 19:36:22 +02:00
Patric Stout be37a2cab8 Codechange: use NetworkAddress instead of two host/port variables where possible
This also means we no longer need last_host/last_port, but can
just use a single last_joined setting.
2021-04-29 20:12:11 +02:00
Patric Stout 99f998805b Codechange: use std::string over stack-based strings if possible 2021-04-29 20:12:11 +02:00
Patric Stout 8fa53f543a
Change: [Network] lower TCP connect() timeout to 3s (#9112)
Currently we use default OS timeout for TCP connections, which
is around 30s. 99% of the users will never notice this, but there
are a few cases where this is an issue:

- If you have a broken IPv6 connection, using Content Service is
  first tried over IPv6. Only after 30s it times out and tries
  IPv4. Nobody is waiting for that 30s.
- Upcoming STUN support has several methods of establishing a
  connection between client and server. This requires feedback
  from connect() to know if any method worked (they have to be
  tried one by one). With 30s, this would take a very long time.

What is good to mention, is that there is no good value here. Any
value will have edge-cases where the experience is suboptimal. But
with 3s we support most of the stable connections, and if it fails,
the user can just retry. On the other side of the spectrum, with 30s,
it means the user has no possibility to use the service. So worst case
we annoy a few users with them having the retry vs annoying a few
users which have no means of resolving the situation.
2021-04-27 20:18:43 +02:00
rubidium42 65c5a64719 Fix: [Network] errno and strerror do not handle network errors on Windows 2021-04-27 18:17:34 +01:00
Rubidium d2fe8c2842 Change: warn the user about the resolving of an address being extra very slow 2021-04-12 21:10:21 +02:00
Niels Martin Hansen e0561dbded Fix #8713: Change OTTD2FS and FS2OTTD to return string objects instead of static buffers 2021-04-07 09:31:47 +02:00
Patric Stout 8fbf5bef60 Fix: workarounds for two emscripten bugs in the network stack 2020-12-15 15:46:39 +01:00
Patric Stout d15dc9f40f Add: support for emscripten (play-OpenTTD-in-the-browser)
Emscripten compiles to WASM, which can be loaded via
HTML / JavaScript. This allows you to play OpenTTD inside a
browser.

Co-authored-by: milek7 <me@milek7.pl>
2020-12-15 15:46:39 +01:00
Jonathan G Rennison 1ac0d4a5b2 Fix: Thread unsafe use of NetworkAddress::GetAddressAsString
Remove static buffer form of NetworkAddress::GetAddressAsString.
This is used in multiple threads concurrently, and is not thread-safe.

Replace it with a form returning std::string.
2020-06-21 11:47:56 +01:00
S. D. Cloudt 13cc8a0cee Cleanup: Removed SVN headers 2019-11-10 17:59:20 +00:00
Henry Wilson 7c8e7c6b6e Codechange: Use null pointer literal instead of the NULL macro 2019-04-10 23:22:20 +02:00
Michael Lutz e804173595 Codechange: If something is a vector of strings, use a vector of strings instead of an AutoFreeSmallVector. 2019-04-09 22:45:15 +02:00
Patric Stout e3c639a09f Remove: ENABLE_NETWORK switch
This switch has been a pain for years. Often disabling broke
compilation, as no developer compiles OpenTTD without, neither do
any of our official binaries.

Additionaly, it has grown so hugely in our codebase, that it
clearly shows that the current solution was a poor one. 350+
instances of "#ifdef ENABLE_NETWORK" were in the code, of which
only ~30 in the networking code itself. The rest were all around
the code to do the right thing, from GUI to NewGRF.

A more proper solution would be to stub all the functions, and
make sure the rest of the code can simply assume network is
available. This was also partially done, and most variables were
correct if networking was disabled. Despite that, often the #ifdefs
were still used.

With the recent removal of DOS, there is also no platform anymore
which we support where networking isn't working out-of-the-box.

All in all, it is time to remove the ENABLE_NETWORK switch. No
replacement is planned, but if you feel we really need this option,
we welcome any Pull Request which implements this in a way that
doesn't crawl through the code like this diff shows we used to.
2019-03-20 19:24:55 +01:00
frosch 396dde1636 (svn r27092) -Fix/Add [FS#6186]: Compilation on OS/2 (smedles) 2014-12-24 17:17:18 +00:00
rubidium 0463dbdc9e (svn r26482) -Codechange: add an include that allows us to undefine/redefine "unsafe" functions to prevent them from being used, and thus having to care about certain aspects of their return values 2014-04-23 20:13:33 +00:00
planetmaker c24374f99c (svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow) 2013-01-08 22:46:42 +00:00
rubidium bd64bf6372 (svn r23193) -Codechange: don't cast away const unneededly 2011-11-12 08:10:22 +00:00
rubidium 289133be14 (svn r22695) -Fix [FS#4697]: mark addresses that could not be resolved as 'do not resolve anymore' as well, instead of trying to resolve them each and every time the address is accessed 2011-07-30 10:28:52 +00:00
rubidium eb299736c1 (svn r21886) -Codechange: move documentation towards the code to make it more likely to be updated [n]. 2011-01-22 09:53:15 +00:00
frosch 98250ad8da (svn r20951) -Codechange: Add SmallMap::Contains() and use it. 2010-10-16 20:34:43 +00:00
rubidium 6b35de215c (svn r19385) -Fix [FS#3684]: [IPv6] Netmask calculations were wrong if cidr >= 32. 2010-03-11 17:57:14 +00:00
rubidium d6cded5380 (svn r17693) -Cleanup: remove some unneeded includes 2009-10-04 17:16:41 +00:00
rubidium 7fbc33dae1 (svn r17248) -Fix: add GPL license notice where appropriate 2009-08-21 20:21:05 +00:00
smatz d4971a22d0 (svn r16265) -Fix (r16238): wrong format string for debug output 2009-05-10 13:23:23 +00:00
rubidium 951b9e7615 (svn r16238) -Change: improve/clarify some network related debug "error" messages by adding more information to them. Also give some clues on how to fix certain issues (like failing advertising). 2009-05-06 09:52:52 +00:00
rubidium 47e2901e18 (svn r16034) -Fix: compile warnings generated by 64 bits MSVC. 2009-04-11 20:26:25 +00:00
rubidium 460fbc7c92 (svn r16007) -Fix (r16004): when we want to bind to both IPv4 and IPv6, make the master socket do that too; too bad getaddrinfo can't handle binding to any address on any port at the same time :( 2009-04-10 09:23:35 +00:00
rubidium 28bce241fd (svn r16005) -Fix: assertion when there is no last joined server; when you've got an unresolved address, the hostname cannot be resolved either so return it as-is. 2009-04-09 21:36:09 +00:00
rubidium 8477e92386 (svn r16004) -Fix (r16000): explicitly binding to an IPv4 socket would try to register an IPv6 address (only if it could ofcourse) 2009-04-09 21:26:29 +00:00
rubidium 0f0cc67d62 (svn r15990) -Codechange: provide a thread safe variant of GetAddressAsString. 2009-04-08 21:11:16 +00:00
rubidium 080095ade5 (svn r15984) -Codechange: prepare the UDP receiver to process multiple types of returned server lists. 2009-04-08 17:51:04 +00:00