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

Reimplement session structure #869

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

AlexProgrammerDE
Copy link
Contributor

Benefits are clear, developers can easily provide custom behaviour by overriding the server and client classes to provide custom channels (like geyser does for localchannel) and also custom channel handlers can be provided, like for ViaVersion support.

Transfers were moved to a flag. There are now ClientSession and ServerSession interfaces which extend Session. This way a ServerSession doesn't have connect methods. Binding to UnixDomainSockets or any other type of SocketAddress is now supported and the client can connect to those too. Tcp was renamed to Net because now non-tcp protocols like local channels and udp (for bedrock ViaBedrock) can be used.

Benefits are clear, developers can easily provide custom behaviour by overriding the server and client classes to provide custom channels (like geyser does for localchannel) and also custom channel handlers can be provided, like for ViaVersion support.

Transfers were moved to a flag. There are now ClientSession and ServerSession interfaces which extend Session. This way a ServerSession doesn't have connect methods.
Binding to UnixDomainSockets or any other type of SocketAddress is now supported and the client can connect to those too.
Tcp was renamed to Net because now non-tcp protocols like local channels and udp (for bedrock ViaBedrock) can be used.
This allows us to share more code between server and client. Additionally, the split worker groups allow mcpl to handle server packets more closely to vanilla and reduce timeouts during load.
@AlexProgrammerDE
Copy link
Contributor Author

Implementation note: the MinecraftConstants.CLIENT_HOST and CLIENT_PORT flags are dynamic flags used by the ClientSessionListener. If not explicitly set, they'll cast the remote address to an InetSocketAddress to take the values. However for developers using anything other like UnixDomainSockeAddresst or LocalChannelAddress they'll have to set those flags to avoid an cast error.

Copy link
Member

@onebeastchris onebeastchris left a comment

Choose a reason for hiding this comment

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

Other than these RFCs/minor touches, lgtm

Comment on lines 39 to 60
public NetClientSession(SocketAddress remoteAddress, PacketProtocol protocol) {
this(remoteAddress, null, protocol);
}

public NetClientSession(SocketAddress remoteAddress, PacketProtocol protocol, ProxyInfo proxy) {
this(remoteAddress, null, protocol, proxy);
}

public NetClientSession(SocketAddress remoteAddress, SocketAddress bindAddress, PacketProtocol protocol) {
this(remoteAddress, bindAddress, protocol, null);
}

public NetClientSession(SocketAddress remoteAddress, SocketAddress bindAddress, PacketProtocol protocol, ProxyInfo proxy) {
this(remoteAddress, bindAddress, protocol, proxy, DefaultPacketHandlerExecutor.createExecutor());
}

public NetClientSession(SocketAddress remoteAddress, SocketAddress bindAddress, PacketProtocol protocol, ProxyInfo proxy, Executor packetHandlerExecutor) {
super(remoteAddress, protocol, packetHandlerExecutor);
this.bindAddress = bindAddress;
this.proxy = proxy;
this.codecHelper = protocol.createHelper();
}
Copy link
Member

@onebeastchris onebeastchris Nov 29, 2024

Choose a reason for hiding this comment

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

Thoughts on making these a builder with default values instead of multiple constructors?

}

protected EventLoopGroup getEventLoopGroup() {
createEventLoopGroup();
Copy link
Member

Choose a reason for hiding this comment

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

any particular reason the event group null check was moved to the method instead of being here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better isolates EVENT_LOOP_GROUP to only be referenced from one method. Also imo makes this method more readable for devs looking to override this.

Copy link
Member

@Redned235 Redned235 left a comment

Choose a reason for hiding this comment

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

Code generally looks fine fine to me, but the main nitpick I have is with the naming. net is just an abbreviation of network, and it doesn't make the most sense IMO to have a second network package nested inside of network already. I'd suggest renaming the net package to session to be a bit more clear to the end user.

Additionally I'd suggest the following names:

  • NetSession -> NetworkSession
  • NetClientSession -> ClientNetworkSession
  • NetServerSession -> ServerNetworkSession

I'd drop the Net prefix for all the other remaining classes aside from NetFlowControlHandler being renamed to AutoReadFlowControlHandler or retaining the previous Tcp prefix as the doc indicates this is still for TCP connections. May be better for these classes to be placed in a netty package as well.

@AlexProgrammerDE
Copy link
Contributor Author

Alright implemented Redneds advice

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.

3 participants