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

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

Open
ghost opened this issue Aug 26, 2024 · 6 comments
Open

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

ghost opened this issue Aug 26, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@ghost
Copy link

ghost commented Aug 26, 2024

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
        }
    }
}
@ghost ghost added the enhancement New feature or request label Aug 26, 2024
@ghost
Copy link
Author

ghost commented Aug 26, 2024

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

Repository owner deleted a comment Aug 26, 2024
@jonesdevelopment jonesdevelopment self-assigned this Aug 26, 2024
@jonesdevelopment
Copy link
Owner

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
Copy link
Owner

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

@jonesdevelopment jonesdevelopment changed the title Drop IP from Velocity rate-limiter before transferring Feature Request: Invalidate IP entry in rate-limiter before transfer Aug 26, 2024
@jonesdevelopment jonesdevelopment added this to the 2.2.0 milestone Aug 26, 2024
@andreasdc
Copy link

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

It's good to report every account like that

@jonesdevelopment
Copy link
Owner

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
Copy link
Owner

jonesdevelopment commented Sep 8, 2024

Planned for 2.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

No branches or pull requests

6 participants
@jonesdevelopment @andreasdc and others