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

Deprecate data_version and introduce checksum for DataPackages. #684

Merged
merged 33 commits into from
Mar 20, 2023

Conversation

ThePhar
Copy link
Member

@ThePhar ThePhar commented Jun 20, 2022

As discussed a bit more in Proposed Changes to DataPackage and Network Protocol in discord, I'm proposing we make the following changes to the DataPackage and Network Protocol to deprecate and eventually stop using data_version to indicate if a given world definition has an updated items/locations table. Instead, clients can reference the checksum of a given game and request the server for an updated DataPackage if it does not match their local cache's checksum. Then, a client can choose to override (or store additionally) that new DataPackage if the cache_safe property is true as well. This can be helpful for games that are still in development or testing and there may be rapid change to the items/locations table and we don't want to cache every single change. In worlds, they can set a development_mode member to True to indicate that it is not cache_safe.

Also made the updates to the documentation to show the new changes and which properties are deprecated to allow time for library and game maintainers to update before it can be removed entirely.

Updates to RoomInfo:

# Mark as deprecated.
datapackage_versions: Dict[str, int]
# A dictionary of Games to hex encoded SHA1 hash of the DataPackage for a particular game.
datapackage_checksums: Dict[str, str]

Updates to GameData (DataPackage Data):

# Mark as deprecated.
version: int
# Base64 encoded SHA1 hash of the DataPackage for a particular game.
checksum: str

The reason for this change is to hopefully avoid situations where integrators forget to increment the data_version and allow clients to be 100% sure that if their checksum matches the server, their DataPackage is exactly the same as the servers. This should incentivize library maintainers to cache their data as they can be sure the DataPackage has not updated.

@Berserker66 @Ijwu @JarnoWesthof @black-sliver @KonoTyran @espeon65536 @FelicitusNeko @N00byKing as you all have libraries (or help maintain them) that I am aware of. I have the thread in Discord as well.

@ThePhar ThePhar changed the title Deprecate data_version and introduce checksum and cache_safe for DataPackages. Deprecate data_version and introduce checksum for DataPackages. Jun 20, 2022
@ThePhar
Copy link
Member Author

ThePhar commented Jun 20, 2022

Crossed out the stuff talking about cache_safe as I removed that in the previous commits.

MultiServer.py Outdated Show resolved Hide resolved
worlds/__init__.py Outdated Show resolved Hide resolved
@Jarno458
Copy link
Collaborator

This PR needs to be updated as the data_versions added to some games are outdated, and the version(s) in the docs are nolonger depricated but already removed

@black-sliver black-sliver added the affects: core Issues/PRs that touch core and may need additional validation. label Jul 28, 2022
@ThePhar
Copy link
Member Author

ThePhar commented Aug 23, 2022

Now that I'm back in action PC-wise, plan is to finish wrapping this up over the next week so we can have it ready to deploy when we're ready to do all the planned protocol changes.

@Jarno458
Copy link
Collaborator

^^ And that was almost a month ago

@ThePhar ThePhar self-assigned this Nov 1, 2022
@ThePhar ThePhar marked this pull request as ready for review January 2, 2023 17:56
@ThePhar
Copy link
Member Author

ThePhar commented Jan 2, 2023

Yeah, my sense of time is bad.

MultiServer.py Outdated Show resolved Hide resolved
#
# Deprecated. This is only used by older clients. Newer clients should be checking the checksum in DataPackage
# instead.
data_version: ClassVar[int] = 0
Copy link
Member

Choose a reason for hiding this comment

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

0 currently still implies to embed the relevant game's datapackage into the resulting .archipelago file.
This PR should probably explain this or offer an alternative, as with this default and explanation I'd expect people to use version 0 now, as in not change it, which is undesired.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hopefully the changes to the comment should be more clear.

@@ -37,7 +37,7 @@ class Hylics2World(World):

topology_present: bool = True

data_version: 1
data_version = 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change should probably be in a different pull request as a bug fix.
The only reason it's working without this fix is that it's getting the 1 value from the base class.

Copy link
Member Author

Choose a reason for hiding this comment

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

Originally this set data_version to 0 as default to ensure new worlds were automatically in testing mode and that would have affected this world. It could be reverted now that I changed the default back to 1, but honestly it's such a small tweak that it's probably just fine in my opinion, but if you insist, I can revert it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Saying that it should be in a different PR is not saying that it shouldn't be in this PR.
It's not a problem if it's both here and in another PR.

Copy link
Member

@black-sliver black-sliver left a comment

Choose a reason for hiding this comment

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

If i were to continue this - what is still missing?
Caching in the client,
caching in the server,
always including datapackage in generated games,
stripping datapackage when storing generated games on the webhost,
anything else?

Do we want to truncate the hash for filename (MAX_PATH=256 may be a problem for some games?) If so, wouldn't a web-safe b64 representation be less likely to collide even if stored CI?

>>> len(hashlib.sha1(dump.encode()).hexdigest())
40
>>> len(urlsafe_b64encode(hashlib.sha1(dump.encode()).digest()).rstrip(b"=").decode())
27
>>> len(f"C:\\Documents and Settings\\A Longer Username\\Local Settings\\Application Data\\My Great Client\\datapackage\\A Link To The Past\\{'0' * 40}.json")
168

hex would still kinda work in the worst case if we don't add more to it than I did above.

worlds/AutoWorld.py Outdated Show resolved Hide resolved
@black-sliver black-sliver force-pushed the datapackage-proposal branch from b183669 to cb32925 Compare March 10, 2023 07:24
Utils.py Outdated Show resolved Hide resolved
WebHostLib/models.py Outdated Show resolved Hide resolved
WebHostLib/models.py Outdated Show resolved Hide resolved
Copy link
Member

@Berserker66 Berserker66 left a comment

Choose a reason for hiding this comment

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

approving in so far that I read through it. Unfortunately did not find the time for decent testing and doubt I will this week.

@kindasneaki
Copy link
Collaborator

While I don't fully understand the inner workings. I ran ror2 explore mode with this with the world removed and everything worked just fine.

@shananas
Copy link
Contributor

tested with KH2 same as kindasneaki with the same results everything works fine

@Berserker66 Berserker66 merged commit ff9f563 into ArchipelagoMW:main Mar 20, 2023
kindasneaki pushed a commit to kindasneaki/Archipelago that referenced this pull request Jun 28, 2023
@ThePhar ThePhar deleted the datapackage-proposal branch October 25, 2023 13:05
@ThePhar ThePhar restored the datapackage-proposal branch October 25, 2023 13:05
FlySniper pushed a commit to FlySniper/Archipelago that referenced this pull request Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: core Issues/PRs that touch core and may need additional validation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants