sonar icon indicating copy to clipboard operation
sonar copied to clipboard

Feature Request: Invalidate IP entry in rate-limiter before transfer

Open whiler-sesame opened this issue 1 year ago • 6 comments

Information

Drop IP from Velocity rate-limiter before transferring (1.20.5) players again to the same server, probably make it an option.

Reason

A usual configuration of the rate-limiter is about 5 seconds. Sonar verifies the client much quicker. Manually removing the IP from cache before transferring might allow not to disable or lower rate-limits and still be convenient for players.

Additional information

These are "internals". Sample code for any Velocity plugin with access to proxy module, not actually tested:

import com.github.benmanes.caffeine.cache.Cache;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.event.proxy.ProxyReloadEvent;
import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.util.ratelimit.CaffeineCacheRatelimiter;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.net.InetAddress;

public class Sample {
    private final MethodHandle cacheGetter;
    private Cache<InetAddress, Long> cache;

    public Sample() throws NoSuchFieldException, IllegalAccessException {
        this.cacheGetter = MethodHandles.privateLookupIn(CaffeineCacheRatelimiter.class, MethodHandles.lookup())
                .findGetter(CaffeineCacheRatelimiter.class, "expiringCache", Cache.class);
        this.loadCache();
    }

    public void dropFromCache(InetAddress address) {
        if (this.cache == null) return; // Not tested for races
        this.cache.invalidate(address);
    }

    @Subscribe
    public void proxyInitializeEvent(ProxyInitializeEvent event) {
        this.loadCache();
    }

    @Subscribe
    public void proxyReloadEvent(ProxyReloadEvent event) {
        this.loadCache();
    }

    private void loadCache() {
        try {
            VelocityServer server = ...; // Obtain from plugin
            if (!(server.getIpAttemptLimiter() instanceof CaffeineCacheRatelimiter limiter)) {
                this.cache = null;
                return;
            }
            this.cache = (Cache<InetAddress, Long>) this.cacheGetter.invoke(limiter);
        } catch (Throwable e) {
            this.cache = null;
            // Handle errors here
        }
    }
}

whiler-sesame avatar Aug 26 '24 03:08 whiler-sesame

wtf edit: if these comments above will be deleted, this is what i'm writing "wtf" about.

ghost avatar Aug 26 '24 03:08 ghost

Drop IP from Velocity rate-limiter before transferring (1.20.5) players [...]

Good idea, but I'd have to implement this for BungeeCord and Bukkit as well, not just Velocity.

jonesdevelopment avatar Aug 26 '24 12:08 jonesdevelopment

I hope nobody clicked on the link WSA1k posted. If you did, reset your PC :sweat:

jonesdevelopment avatar Aug 26 '24 12:08 jonesdevelopment

I hope nobody clicked on the link WSA1k posted. If you did, reset your PC 😓

It's good to report every account like that

andreasdc avatar Aug 26 '24 22:08 andreasdc

It's good to report every account like that

Yeah, I did report them to GitHub. One of the accounts was already banned afaik.

jonesdevelopment avatar Aug 27 '24 12:08 jonesdevelopment

Planned for 2.2.0

jonesdevelopment avatar Sep 08 '24 13:09 jonesdevelopment

This will be addressed in Sonar 3.0.0.

More information: https://jonesdev.xyz/discord (or https://patreon.com/jonesdev) for previews, polls, and news.

jonesdevelopment avatar Jan 05 '25 07:01 jonesdevelopment