-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip reverse DNS lookup when connecting/pinging servers
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
1 parent
c2375fe
commit 3351f9d
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/ca/spottedleaf/moonrise/mixin/serverlist/ServerAddressResolverMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters