Code Monkey home page Code Monkey logo

hopper-rs's Introduction

Hopper License

Hopper is a lightweight reverse proxy for minecraft. It allows you to connect multiple servers under the same IP and port, with additional functionalities, just like Nginx. It is built with Rust ๐Ÿฆ€ to ensure maximum performance and efficiency.

Hopper works starting from version 1.7 up to the latest version of Minecraft.

NOTE: this proxy is still heavily under development, and a lot of new features are coming really soon!

FEATURES:

Index

Configuration

To quickly get started checkout this example configuration:

Example Config.toml:
# the address hopper will listen on
listen = "0.0.0.0:25565"

# metrics configuration
# [metrics]
# type = "influx"
# ...
#
# follow the section below for more information about
# gathering metrics with hopper

# general routing configuration
[routing]
default = { ip = "127.0.0.1:12345" } # optional
# default = { ip = ["127.0.0.1:12001", "127.0.0.1:12002"] } # load balanced

# list of servers fronted by hopper
[routing.routes]
# simple reverse proxy
"mc.gaming.tk" = { ip = "docker_hostname:25008" } # hostnames are supported too!

# bungeecord's ip forwarding feature enabled
"mc.server.com" = { ip-forwarding = "bungeecord", ip = "127.0.0.1:25123" }

# RealIP ip forwarding feature enabled
"mc.withrealip.com" = { ip-forwarding = "realip", ip = "127.0.0.1:26161" }

# this will load balance between the two servers
"other.gaming.tk" = { ip = ["127.0.0.1:25009", "10.1.0.1:25123"] }

Load balancing

Hopper's load balancer is a hash distributor based on the player's source IP and port.

You can load balance players between two backend servers by specifying a list of ip addresses instead of a single address.

[routing]
default = { ip = ["1.1.1.1:25565", "2.2.2.2:25577"] } # works on non-default routes too

IP Forwarding

Without IP Forwarding, when servers receive connections from this reverse proxy they won't see the original client's ip address. This may lead to problems with sessions with plugins such as AuthMe. Hopper implements both the legacy BungeeCord protocol and the more versatile RealIP one.

Bungeecord

You must enable bungeecord ip-forwarding inside of spigot.yml just like you would using bungeecord. Click here to learn more.

You can enable ip forwarding per-server on hopper with the "ip-forwarding" directive:

# You can either do it this way
[routing.routes]
"your.hostname.com" = { ip-forwarding = "bungeecord", ip = "<your server ip>" }

# or this way
[routing.routes."your.hostname.com"]
ip-forwarding = "bungeecord" # available options are: bungeecord, none. Defaults to none
ip = "<your server ip>"

RealIP

Hopper supports up to RealIP v2.4 (private/public key authentication has been implemented for versions after that, which only works with TCPShield).

โš ๏ธ Note: RealIP v2.4 was built using older dependencies, hence support for newer minecraft versions may be lacking.

You must whitelist Hopper's ip address (or network) by adding a line inside of plugins/TCPShield/ip-whitelist/tcpshield-ips.list.

Finally, you must enable RealIP support in your Config.toml:

[routing.routes]
"your.hostname.com" = { ip-forwarding = "realip", ip = "<your server ip>" }

PROXY Protocol a.k.a HAProxy V2

Support for PROXY Protocol is available by setting ip-forwarding to proxy_protocol. Only the 2nd version of the protocol (the one supported by Bungeecord out of the box) is implemented in Hopper.

Example configuration:

[routing.routes]
"my.bungee.hostname.com" = { ip-forwarding = "proxy_protocol", ip = "<your server ip>" }

Logging metrics with InfluxDB

Hopper supports cheap (resource-wise), easily configurable data gathering through the help of an external database like InfluxDB (although other databases will be supported in the future, I still recommend InfluxDB whose query language is very easy and versatile).

You must first configure an InfluxDB instance and get a token with writing privilege before moving along with this section.

Add and modify this configuration section in Config.toml according to your setup:

[metrics] # top-level section
type = "influxdb"
# hostname = "my-hostname" # OPTIONAL, defaults to system hostname
url = "<http/https>://<influxdb-host-or-ip>:<port>/"
organization = "<Your organization>"
bucket = "<Your data bucket>"
token = "<Your access token>"

Hopper will start logging every 5 seconds according to this data format:

Measurement "traffic":

Field Type Description
host Tag system (or custom if specified) hostname generating this metric
destination_hostname Tag the hostname clients connected corresponding to these metrics
clientbound_traffic Value (int) the traffic this host generated server=>client
serverbound_traffic Value (int) same as above, but client=>server
open_connections Value(int) connections opened in the moment of the measurement
total_game Value(int) people who attemped or succeded joining this server
total_ping Value(int) people who pinged this server

NOTE: Since counters reset through restarts, data manipulation using the influx query language allows you to aggregate rows and get persistent results.

How to run

There are two ways to run hopper:

Docker GitHub Workflow Status

  • Pull the latest image from the GitHub registry:
docker pull ghcr.io/bra1l0r/hopper-rs
  • Create a Config.toml (NOTE: the port you will specify must match the exposed port below)
  • Run it using docker:
docker run -d -p 25565:25565 -v /home/user/path-to/Config.toml:/Config.toml ghcr.io/bra1l0r/hopper-rs

Using docker-compose (recommended):

# new versions of compose don't require this anymore
version: "3"

services:
  hopper:
    image: ghcr.io/bra1l0r/hopper-rs
    ports:
      - 25565:25565
    volumes:
      - ./Config.toml:/Config.toml

Binary GitHub Workflow Status

You can either download the latest release (recommended) or follow the steps below to build your own binary:

  • Download and install the latest version of the rustc toolchain
  • Clone and build the repo:
# Clone the repo into hopper-rs and enter the directory
git clone https://github.com/BRA1L0R/hopper-rs
cd hopper-rs/

# Build the project with the release profile
cargo build --release
  • The runnable binary will now be available at target/release/hopper

Systemd configuration

Assuming both the hopper binary and Config.toml configuration file are located inside /opt/hopper, you can extend this systemd configuration that supports both the stop and reload commands.

It is strongly advised not to use the root user as a best practice, however this configuration does use it and is to be intended as a template.

[Unit]
Description=Hopper reverse proxy
After=network.target

[Service]
Type=simple
ExecStart=/opt/hopper/hopper
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
WorkingDirectory=/opt/hopper

[Install]
WantedBy=multi-user.target

Changing the verbosity level

If you think something is off with your instance and want to enable debug logging, or you just want to reduce the default talkativeness of hopper you must choose your desired level of verbosity through the RUST_LOG environment variable.

Level Description
off No console output at all
error Only output important errors such as an unreachable backend server
info Informative data such as incoming connections and the current listening address
debug More descriptive errors (includes failed handshakes and bad packet data)

Default: info

Example:

RUST_LOG="debug" ./hopper

Hot reload

Hot reloading of Config.toml is supported only on linux as it provides the best way to signal the process to perform a hot reload.

If you think you know how something similar might be implemented in Windows please open an issue explaining your idea.

Hopper supports hot reloading through the SIGHUP process signal. Just like nginx. A rudimentary example of doing this would be through the kill command:

kill -s sighup <process PID>

If the new configuration contains the reload is aborted and the server continues running with the previous configuration.

You can automate this with systemd, allowing for the handy systemctl reload <service> shortcut, as you can see explained here.

hopper-rs's People

Contributors

bra1l0r avatar dumbmahreeo avatar imfound avatar sparpvp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hopper-rs's Issues

Bedrock support

Hi! Could you look into making this compatible with Bedrock/Geyser?
It could be a very interesting alternative for Bedrock proxies as Nginx does not quite work well with Geyser and there is not much else out there.

Minimum Requirements

I think it would be pretty good to know the minimum requirements for a KVM needed to properly run this project. :)

Ping seems quite volatile

Hey,

I replaced HAProxy with Hopper as a proxy and noted the following:
With HAProxy, my ping appears to be stable at around ~20:
image

With Hopper, it likes to jump around quite a lot and is way higher than it was:
image

(This behavior is also seen by different users from different parts of the country with different ISPs)

Both Revers Proxies connect to the same Minecraft Proxy and are hosted by the same Hoster. And both Revers Proxies are using the Proxy Protocol.
I can give you both Revers Proxies IPs in case you are interested and want to investigate that.

InfluxDB

How i can import a Influx to grafana?

Luckperms "module"

I don't think I need to state just how popular and useful Luckperms is as a permission manager.

One of the things that I can do with Luckperms on both Bungee and Server is to allow/deny usergroups connecting to a a host amongst other options.

RealIP support

Hi!
I installed the hopper and everything is fine, except for one thing.
When I turn on "ip-forwarding", the players pings jump twice.
I'm sure it's because of the bungeecord protocol as I had similar problems when I had the server linked via bungeecord.
I suggest adding support for "realIP" from TCPShield. I know it's complicated but add at least 2.4 support which doesn't seem to require public and private keys.
(If possible, add support for the latest version at once, please!)
Thanks in advance!

Broken docker image dependencies

Hello!
I did all steps mentioned under "How to run" title, and it don't start.
I tried to run it using docker:
docker run -d -p 25565:25565 -v /etc/hopper/Config.toml:/Config.toml ghcr.io/bra1l0r/hopper-rs

Logs:
Error relocating /hopper: __res_init: symbol not found

Any tutorial with fixing it? Thank you in advance!

Root domain

Good evening, the application is wonderful but I found a small problem, root domains do not work, only suboominios, example the domain test.play.com works but point only the play.com does not work

CPU max usage

Hello, I have set up hopper to proxy a basic spigot server. even when no one uses the proxy, hopper tends to spike the cpu at 100% for like 10 minutes.
unknown (3)
unknown (4)

Suggestion: Reload config for High Availability

Maybe it would be possible to add a reload mechanism into hopper to allow for easy changes without having to disconnect all users.
Like for example, if I want to add a new route, hopper would kick all users because I have to restart it.
Furthermore, this is something which might be important for me but not for others.
But I would love the ability to change the IP of the backend server, reload hopper, and then have only new users connect to this new IP while users that are currently connected keep their current connection.

Protocol Routing

Hello there, don't know if this is in the scope of the software but would be neat to have the option to route players to different proxy using different protocol versions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.