Networking rewrite #48
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR rewrites some of the Networking API to make it more uniform. To achieve this, a lot of code was separated out into a networking library with just 5 modules, which contains most of the API. Most of the implementation details have been moved into a smaller networking-impl library, which has a lot more modules as a result.
API Changes
Payload Channels
Where previously, payload channels were represented by
Strings in 1.13-pre2 and below andIdentifiers in 1.13-pre4 and above, now OSL Core'sNamespacedIdentifieris used instead. It is essentially equivalent toIdentifier, but it can be used in all Minecraft versions.All API code now references these "channel identifiers" instead of
Strings orIdentifiers. To construct a channel identifier, use the helper methods in theChannelIdentifiersclass:Channels should be registered through the
ChannelRegistryclass:Registering payload listeners and sending payloads now requires passing in a channel identifier:
Packet Buffers
Where previously, payload reading and writing was done through either the
DataInputandDataOutputinterfaces or thePacketByteBufclass, OSL now provides its ownPacketBuffer. In 13w41a and above, this class is essentially a wrapper aroundPacketByteBuf, making it a simple drop-in replacement forPacketByteBuf. Mods that target 13w39b and below may require more work to update to this, as it is very different from theDataInputandDataOutputinterfaces.Listener Context
Packet listeners are now given a context object rather than direct access to the game instances and network handlers. These can now be accessed through the context. For example:
Async packet handling is now also controlled through this context. Rather separate
registerandregisterAsyncmethods for registering listeners, all listeners can now be invoked asynchronously by default. To ensure your code is running on the main thread, callensureOnMainThreadon the context:Internal Changes
Handshakes
The handshake payload now carries a protocol number, which can be updated if changes are made to the handshake process.
Handshakes now also only sync valid channels with valid (i.e. to OSL spec) identifiers. Channels with invalid identifiers are not sent via OSL anyway.
Channel Length Limit
The length limit for
Stringchannels has been effectively removed.Async Packet Handling
Support for asynchronous packet handling has been added to versions prior to 14w21a.