Page 4 of 5

Re: Add SRV Record support

Posted: Sat Dec 05, 2020 10:26 am
by Gellis12
ssilk wrote:
Sat Dec 05, 2020 8:22 am
I have a question at this point: when you run two Factorio servers at one host, who or what decides which will receive which packet when the incoming packet is for the same target port? Is that be done by the operating system? I mean: there must be something “above” the two Factorio servers, which does the routing depending on the target IP, otherwise - AFAIK - the OS does not distinct between the incoming IP, it can route internally only to the port of the listening server, or not?
That's the thing - you cannot run two factorio servers on the same host and have them listen on the same port. The first server that you start will bind to the port you set, and then any other process that tries to bind to that port will be denied and (if it's properly designed, like the factorio server is) will promptly give an error message and stop gracefully.

The SRV record solves this at the DNS level: it tells your game client what port number to connect to on the host, so that the user doesn't need to try and remember it. As mentioned above, you cannot have two factorio servers listening on host 1.2.3.4:101, you'd need to have your second server listening on host 1.2.3.4:102. Once you add a standard DNS A record, you can have that resolve to example.com:101 and example.com:102 (this already works in factorio). Once you add SRV records, you can have factorio1.example.com point to 1.2.3.4:101 for factorio clients, and factorio.example.com point to 1.2.3.4:102 for factorio clients (this does not yet work in factorio).

Another really nice feature of SRV records is that they're application specific; so you can theoretically have a website for your factorio server running on a completely different host than the game server in order to minimize game lag (ex. 4.3.2.1:80/443). You could then have a DNS A record for factorio1.example.com point to 4.3.2.1, but the SRV record for factorio would mean the game still knows to connect to the other host at 1.2.3.4:101. You'd then have the game and web browser connecting to two completely different hosts, even though you're typing in the exact same domain name for each one.

Re: Add SRV Record support

Posted: Sat Dec 05, 2020 2:46 pm
by robot256
ssilk wrote:
Sat Dec 05, 2020 8:22 am
@robot256: have you seen the post date? 2017. It might be - I’m not an expert - that there where changes meanwhile. Just my usual stackoverflow habits. :)

I have a question at this point: when you run two Factorio servers at one host, who or what decides which will receive which packet when the incoming packet is for the same target port? Is that be done by the operating system? I mean: there must be something “above” the two Factorio servers, which does the routing depending on the target IP, otherwise - AFAIK - the OS does not distinct between the incoming IP, it can route internally only to the port of the listening server, or not?
The SRV record makes sure that Factorio is redirected to both the correct IP and the unique port for that server during the initial connection process. The server itself still has to have unique ports for each instance, and each of those must be port-forwarded by the router.

The nginx load balancing method (which I have not tried, mind you), means only the nginx process listens on port 34197, which is the only port forwarded by the router. Nginx looks at the metadata of each packet sent to that port to see which subdomain it was originally sent to. Then it forwards it to a different port (and IP if desired) where that factorio instance is listening (34198, 34199, etc). Nginx will be actively forwarding packets for the entire gaming session.

We really have to test this to know if it will work, because I don't know whether the UDP packets sent by Factorio clients will even have the metadata nginx needs to perform this internal routing. It might not work the way it does with Minecraft and TCP.

Re: Add SRV Record support

Posted: Sun Dec 06, 2020 8:52 am
by ssilk
Thank you. :)

Re: Add SRV Record support

Posted: Thu Dec 10, 2020 7:47 pm
by IzaacJ
+1 on this!
I run most of my saves as different private servers in my homelab, just because servers are fun, and remembering which port was for which save is quite a hassle! With this I could make it waaay easier for myself!

Re: Add SRV Record support

Posted: Mon Jan 18, 2021 3:44 am
by Darth Android
For some clarity RE: NginX and its capabilities:

NginX Load Balancing: This is useful if you need to spread clients across multiple servers when one server can't handle all of them, and client's don't care which server they connect to.. Nginx listens on the public IP/port, and routes clients randomly to upstream servers in an effort to spread the load evenly across upstream servers. This isn't useful for Factorio because clients want to join a specific server.

NginX Virtual Hosting: This is useful when you want to host multiple distinct services on a single public IP/port, and route to separate upstream services. The catch: The client must specify which upstream service they want to connect to inside the protocol, and NginX must have a plugin that can understand the protocol to extract the name of the upstream service and configure the route. NginX only supports this for HTTP/HTTPS/HTTP2 protocols, and virtual hosting in general is only useful for TCP protocols-- UDP protocols would have to specify the DNS name inside every packet, which would waste considerable amounts of bandwidth. This isn't useful for Factorio because the protocol would have to be completely rewritten to support it, and someone would have to either write a plugin for NginX or an entirely standalone factorio virtual hosting server application.

By comparison, issuing a SRV dns lookup in C++ is ~40 lines of code.

Re: Add SRV Record support

Posted: Mon Feb 15, 2021 6:04 pm
by mkaito
I would definitely love to see SRV supported by Factorio. It's an immensely useful thing.

Re: Add SRV Record support

Posted: Fri May 21, 2021 4:39 pm
by Liquid_touch22
+1 for SRV support.

I understand that using SRV records is not required to list a server publicly but listing a server publicly is not the same thing as running a private personal server where SRV makes it much easier to manage and access. Beyond gameplay part of the reason Minecraft has been so successful is how accessible the game is. Implementing things like SRV support will only aid the smaller demographic of people that would use it make the game far more accessible to people that wouldn't. When it's stated most people wouldn't use this feature thats sort of the point; one person can use it and provide an easier entry point for many others that wouldn't otherwise know how.

Re: Add SRV Record support

Posted: Fri May 21, 2021 9:04 pm
by ptx0
oh god yes please it'll make it easier to set up multiple games on a single IP and not have to provide a port number, just a subdomain.

Re: Add SRV Record support

Posted: Wed Jun 15, 2022 7:34 pm
by xxsodapopxx5
Yes please! SRV support would be very nice. I just configured it all assuming it would work, sadly it did not. Once I googled "factorio SRV record" I found this topic laying out that it won't work. It will be hard keeping track of which saves are linked to which ports - not a big deal by any means, but would be a nice tiny polishing for an already exceptionally polished game!

Re: Add SRV Record support

Posted: Sun Jul 24, 2022 12:40 pm
by Salzig
Is this topic dead? I would really love to see SRV records working. Or did i missed some news that's meanwhile possible?

Re: Add SRV Record support

Posted: Sun Jul 24, 2022 6:49 pm
by ssilk
The only way I currently know is the described method to use - for example - Nginx as reverse proxy.

Re: Add SRV Record support

Posted: Sun Jul 24, 2022 10:26 pm
by Rseding91
Ok, I finally got around to working on this and (at least on windows) the next version will support SRV records. It's a super basic implementation but it should function for Factorio server needs.

Re: Add SRV Record support

Posted: Sun Jul 24, 2022 11:04 pm
by BenSeidel
Thank you.

Re: Add SRV Record support

Posted: Tue Jul 26, 2022 1:58 pm
by Rseding91
Ok, so the implementation was TOO basic ... and probably won't work until the *next* release.

Re: Add SRV Record support

Posted: Fri Jul 29, 2022 4:28 am
by Maldor96
Rseding91 wrote:
Tue Jul 26, 2022 1:58 pm
Ok, so the implementation was TOO basic ... and probably won't work until the *next* release.
Just to clarify, .62 has the support, but .63 actually makes it work? Or does it not work yet?

Re: Add SRV Record support

Posted: Fri Jul 29, 2022 3:38 pm
by Rseding91
Maldor96 wrote:
Fri Jul 29, 2022 4:28 am
Rseding91 wrote:
Tue Jul 26, 2022 1:58 pm
Ok, so the implementation was TOO basic ... and probably won't work until the *next* release.
Just to clarify, .62 has the support, but .63 actually makes it work? Or does it not work yet?
Yes; it makes it work. You can try it out in game.

Re: Add SRV Record support

Posted: Fri Aug 19, 2022 3:14 pm
by vinzenz
So with SRV support for Linux and Mac landing in 1.1.67 here are some infos about how it's implemented in Factorio:
  • Factorio use the service name _factorio and only supports the _udp protocol
  • Factorio doesn't support multiple SRV records for a domain, it will not look at the priority and weight values and instead use the first record the query returns
  • It will log a "DNS SRV lookup returned [...]" message when it found a SRV record for the given domain
  • In verbose logging it will also log "DNS SRV lookup for [domain] didn't return any usable records" when there's no SRV record
When you want to setup a SRV record for example.com pointing towards srv-target.example.com:34197 you need to create a SRV record for _factorio._udp.example.com. Here's how it looks like in the Cloudflare interface:
Screenshot from 2022-08-19 17-07-40.png
Screenshot from 2022-08-19 17-07-40.png (40.25 KiB) Viewed 5881 times

Re: Add SRV Record support

Posted: Sat Aug 20, 2022 7:08 am
by Koub
Would it be possible to add the wiki some info about this SRV record thing, along with kind of a howto ?
(The whole subject is way out of reach of my understanding, so I don't feel easy doing it myself).

Re: Add SRV Record support

Posted: Sat Aug 20, 2022 8:16 am
by vinzenz
Yes will put it on the wiki. But 1.1.67 needs to become stable first and more testers other than myself, rseding and me would be nice.

Re: Add SRV Record support

Posted: Wed Oct 05, 2022 5:33 pm
by Saklad5
Could someone at Wube please register the "factorio" service name with IANA? You're just squatting on the name right now, and that's a serious problem.

The relevant form is here: https://www.iana.org/form/ports-services. It's very easy to use: I could do it on your behalf if you prefer.

Also consider registering UDP port 34197 for Factorio, since that's the same form. It's similarly bad practice to use an unregistered port by default (really, modern software should be using dynamic ports until configured otherwise, with SRV/SVCB records if you don't want to make people specify ports themselves), but that ship has sailed.