Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codechange: use connection_string in favour of NetworkAddress #9197

Merged
merged 1 commit into from May 5, 2021

Conversation

TrueBrain
Copy link
Member

Motivation / Problem

During work on the STUN support, I kept running into the issue that NetworkAddress modifies its own object when it is resolved (which is done lazy). With the STUN support PR, we get "invite codes", which is another form besides ip:port to indicate the address of a server.

When analyzing this problem, I came to the realisation that we store NetworkAddress in many places, like NetworkGameList, while we simply mean to store the address where the server is. There is no need to have this uber complex object assigned to it for that, a simple string is sufficient. This also helps for "invite codes", as that is just another serialization of a servr address.

This means we now resolve connection strings to NetworkAddress a lot later now. The downside is that we do it slightly more often (every time you refresh/join a server instead of once when adding it).

Description

We now resolve the connection_string to a NetworkAddress in a much
later state. This means there are fewer places constructing a NetworkAddress.

The main benefit of this is in later PRs that introduce different types
of NetworkAddresses. Storing this in things like NetworkGameList is
rather complex, especially as NetworkAddress has to be mutable at all
times.

Additionally, the NetworkAddress is a complex object to store simple
information: how to connect to this server.

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

We now resolve the connection_string to a NetworkAddress in a much
later state. This means there are fewer places constructing a NetworkAddress.

The main benefit of this is in later PRs that introduce different types
of NetworkAddresses. Storing this in things like NetworkGameList is
rather complex, especially as NetworkAddress has to be mutable at all
times.

Additionally, the NetworkAddress is a complex object to store simple
information: how to connect to this server.
@TrueBrain TrueBrain force-pushed the game-info-connection-string branch from 82e3d49 to 3af16ad Compare May 5, 2021 19:14
Copy link
Member

@LordAro LordAro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¯\_(ツ)_/¯

@TrueBrain TrueBrain merged commit f94fb93 into OpenTTD:master May 5, 2021
@TrueBrain TrueBrain deleted the game-info-connection-string branch May 5, 2021 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants