Add SRV Record support

Suggestions that have been added to the game.

Moderator: ickputzdirwech

Gellis12
Manual Inserter
Manual Inserter
Posts: 3
Joined: Mon May 27, 2019 8:31 am
Contact:

Re: Add SRV Record support

Post 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.
robot256
Filter Inserter
Filter Inserter
Posts: 909
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Add SRV Record support

Post 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.
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Add SRV Record support

Post by ssilk »

Thank you. :)
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
IzaacJ
Manual Inserter
Manual Inserter
Posts: 4
Joined: Thu Dec 10, 2020 7:29 pm
Contact:

Re: Add SRV Record support

Post 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!
Containerize everything! | Automate everything! | Optimize everything!
Darth Android
Manual Inserter
Manual Inserter
Posts: 1
Joined: Mon Jan 18, 2021 2:51 am
Contact:

Re: Add SRV Record support

Post 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.
mkaito
Inserter
Inserter
Posts: 32
Joined: Tue Sep 26, 2017 2:09 am
Contact:

Re: Add SRV Record support

Post by mkaito »

I would definitely love to see SRV supported by Factorio. It's an immensely useful thing.
Liquid_touch22
Manual Inserter
Manual Inserter
Posts: 1
Joined: Fri May 21, 2021 4:04 pm
Contact:

Re: Add SRV Record support

Post 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.
User avatar
ptx0
Smart Inserter
Smart Inserter
Posts: 1507
Joined: Wed Jan 01, 2020 7:16 pm
Contact:

Re: Add SRV Record support

Post 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.
xxsodapopxx5
Manual Inserter
Manual Inserter
Posts: 1
Joined: Wed Jun 15, 2022 7:30 pm
Contact:

Re: Add SRV Record support

Post 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!
Salzig
Burner Inserter
Burner Inserter
Posts: 11
Joined: Sun Oct 26, 2014 5:40 pm
Contact:

Re: Add SRV Record support

Post 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?
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Add SRV Record support

Post by ssilk »

The only way I currently know is the described method to use - for example - Nginx as reverse proxy.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
Rseding91
Factorio Staff
Factorio Staff
Posts: 14269
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Add SRV Record support

Post 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.
If you want to get ahold of me I'm almost always on Discord.
BenSeidel
Filter Inserter
Filter Inserter
Posts: 590
Joined: Tue Jun 28, 2016 1:44 am
Contact:

Re: Add SRV Record support

Post by BenSeidel »

Thank you.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14269
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Add SRV Record support

Post by Rseding91 »

Ok, so the implementation was TOO basic ... and probably won't work until the *next* release.
If you want to get ahold of me I'm almost always on Discord.
User avatar
Maldor96
Burner Inserter
Burner Inserter
Posts: 17
Joined: Tue May 09, 2017 8:53 pm
Contact:

Re: Add SRV Record support

Post 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?
Addicted to cracktorio since May 2017
Streaming live at: https://www.twitch.tv/maldor96
Rseding91
Factorio Staff
Factorio Staff
Posts: 14269
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Add SRV Record support

Post 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.
If you want to get ahold of me I'm almost always on Discord.
User avatar
vinzenz
Factorio Staff
Factorio Staff
Posts: 341
Joined: Mon Aug 02, 2021 6:45 pm
Contact:

Re: Add SRV Record support

Post 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 7604 times
bringing the oops to devops
Koub
Global Moderator
Global Moderator
Posts: 7784
Joined: Fri May 30, 2014 8:54 am
Contact:

Re: Add SRV Record support

Post 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).
Koub - Please consider English is not my native language.
User avatar
vinzenz
Factorio Staff
Factorio Staff
Posts: 341
Joined: Mon Aug 02, 2021 6:45 pm
Contact:

Re: Add SRV Record support

Post 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.
bringing the oops to devops
Saklad5
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu Mar 31, 2022 6:01 pm
Contact:

Re: Add SRV Record support

Post 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.
Post Reply

Return to “Implemented Suggestions”