Skip to content

Commit

Permalink
Skip reverse DNS lookup when connecting/pinging servers
Browse files Browse the repository at this point in the history
The rDNS is not cheap and is not necessary. We skip the
rDNS by providing the input address as the host name when
the input address is a plain ipv4/ipv6 address.
  • Loading branch information
Spottedleaf committed Jul 29, 2024
1 parent c2375fe commit 3351f9d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ca.spottedleaf.moonrise.mixin.serverlist;

import net.minecraft.client.multiplayer.resolver.ServerAddressResolver;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

@Mixin(ServerAddressResolver.class)
public interface ServerAddressResolverMixin {

/**
* @reason Avoid rDNS lookups for plain IP addresses
* @author Spottedleaf
*/
@Redirect(
method = "method_36903",
at = @At(
value = "INVOKE",
target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;"
)
)
private static InetAddress eliminateRDNS(final String name) throws UnknownHostException {
final InetAddress ret = InetAddress.getByName(name);

if (ret instanceof Inet4Address || ret instanceof Inet6Address) {
// pass name to prevent rDNS
return InetAddress.getByAddress(name, ret.getAddress());
}

return ret;
}
}
1 change: 1 addition & 0 deletions src/main/resources/moonrise.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"collisions.ParticleMixin",
"render.SectionRenderDispatcherMixin",
"serverlist.ClientConnectionMixin",
"serverlist.ServerAddressResolverMixin",
"serverlist.ServerSelectionListMixin",
"starlight.multiplayer.ClientPacketListenerMixin"
],
Expand Down

0 comments on commit 3351f9d

Please sign in to comment.