Skip to content

Commit

Permalink
refactor: prepare for storage
Browse files Browse the repository at this point in the history
  • Loading branch information
haveachin committed Nov 18, 2022
1 parent e3833e1 commit ae38b3d
Show file tree
Hide file tree
Showing 12 changed files with 241 additions and 95 deletions.
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,15 @@ func onConfigChange(cfg map[string]any) {
logger.Error("failed to load java config",
zap.Error(err),
)
return
}

bedrockPrxCfg, err := bedrock.NewProxyConfigFromMap(cfg)
if err != nil {
logger.Error("failed to load bedrock config",
zap.Error(err),
)
return
}

prxCfgs := map[infrared.Edition]infrared.ProxyConfig{
Expand Down
76 changes: 53 additions & 23 deletions configs/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ providers:
#
#watch: true

# Storage like a database that Infrared should read from.
#
storage:
# A list of storage IDs that Infrared should read from.
#
ids:
- default

# Config files that Infrared should read from.
#
file:
Expand All @@ -37,14 +45,31 @@ providers:
#
watch: true

api:
bind: :8080
allowedOrigins:
- "http://*"
- "https://*"
# Storage are mainly used to store and read Infrared configs,
# but are also used to enable other features that need persistend storage.
#
storage:
# This is the ID of this database.
#
default:
driver: postgres
address: :5432
database: infrared
username: username
password: password

# Enables the API to access real time data.
#
#api:
#bind: :8080
#allowedOrigins:
# - "http://*"
# - "https://*"

prometheus:
bind: :9070
# Enables the prometheus server for real time metric tracking.
#
#prometheus:
#bind: :9070

# Configuration for webhooks
#
Expand All @@ -62,19 +87,19 @@ prometheus:
#
#url: https://example.com/callback

# Client timeout specifies a time limit for requests made by the webhook client.
# A Timeout of zero means no timeout.
# Dial timeout is the amount of time that Infrared waits for it cancels the POST request.
# This is best set in defaults to not have to copy-paste this all the time. See bottom of the file.
#
#clientTimeout: 300ms
#dialTimeout: 1s

# Event Topics to listen for.
# Available events are:
# NewConnEvent - When a new connection to Infrared is made.
# PreConnProcessingEvent- Before the new connection is processed.
# PostConnProcessingEvent - After a connection is processed.
# PreConnConnectingEvent - Before a client is connecting to the target server.
# PlayerJoinEvent - When a player joins a server.
# PlayerLeaveEvent - When a player leaves the server.
# - NewConnEvent - When a new connection to Infrared is made.
# - PreConnProcessingEvent - Before the new connection is processed.
# - PostConnProcessingEvent - After a connection is processed.
# - PreConnConnectingEvent - Before a client is connecting to the target server.
# - PlayerJoinEvent - When a player joins a server.
# - PlayerLeaveEvent - When a player leaves the server.
#
#events:
# - PlayerJoin
Expand All @@ -88,6 +113,7 @@ java:
#
chanCaps:
# The capacity of the channel from the gateway to the processing nodes
# If this is unset or 0
#
connProcessor: 100

Expand All @@ -104,7 +130,7 @@ java:
# Count describes the number of processing nodes that concurrently process
# incoming connections. By increasing the count of processing nodes you can
# tremendously reduce the effect of DDoS effects at the cost of performance.
# If you CPU has a lot of thread then feel free to increase this number.
# If your CPU has a lot of threads then feel free to increase this number.
#
count: 10

Expand All @@ -124,8 +150,10 @@ java:

# This is the window of time in that a single IP can make a specific amount of requests.
#
windowLenght: 50ms
windowLength: 50ms

# See Java above
#
bedrock:
chanCap:
connProcessor: 100
Expand All @@ -137,10 +165,12 @@ bedrock:
middlewares:
rateLimiter:
requestLimit: 1
windowLenght: 50ms
windowLength: 50ms

defaults:
webhook:
# Dial timeout is the amount of time that Infrared waits for it cancels the POST request
# Defaults are global default values that can be
#
#defaults:
#webhook:
# Sets the dial timeout for every webhook. This can be individually overridden.
#
dialTimeout: 1s
#dialTimeout: 1s
6 changes: 4 additions & 2 deletions configs/proxies/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defaults:
#
edition: MCPE

# The protocol version and name. For more info see https://wiki.vg/Bedrock_Protocol_version_numbers
# The protocol version number. For more info see https://wiki.vg/Bedrock_Protocol_version_numbers
#
protocolVersion: 544

Expand Down Expand Up @@ -94,4 +94,6 @@ defaults:
iconPath: icons/default.png
motd: |
Powered by Infrared
§6Server at {{serverDomain}} is not responding.
§6Server at {{serverDomain}} is not responding.
bandwidth:
storage: default
15 changes: 11 additions & 4 deletions configs/proxies/java-example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ java:
domains:
- "*"
address: example.com:25565
overrideStatus:
versionName: Infrared
maxPlayerCount: 777777777
playerCount: 2
#proxyBind: 0.0.0.0
#sendProxyProtocol: true
#sendRealIP: true
#overrideStatus:
#versionName: Infrared
#maxPlayerCount: 20
#playerCount: 0
#
bandwidth:
trafficLimit: 1TB
resetCron: "0 0 0 1 * *"
4 changes: 2 additions & 2 deletions docs/architecture.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 26 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/haveachin/infrared
go 1.19

require (
github.com/cespare/xxhash/v2 v2.1.2
github.com/df-mc/atomic v1.10.0
github.com/docker/docker v20.10.20+incompatible
github.com/fsnotify/fsnotify v1.6.0
Expand All @@ -12,13 +13,18 @@ require (
github.com/gofrs/uuid v4.3.0+incompatible
github.com/golang-jwt/jwt/v4 v4.4.2
github.com/golang/mock v1.6.0
github.com/golang/snappy v0.0.4
github.com/gorilla/schema v1.2.0
github.com/imdario/mergo v0.3.13
github.com/klauspost/compress v1.15.11
github.com/mitchellh/mapstructure v1.5.0
github.com/pires/go-proxyproto v0.6.2
github.com/prometheus/client_golang v1.13.0
github.com/sandertv/go-raknet v1.12.0
github.com/spf13/cobra v1.6.0
github.com/uptrace/bun v1.1.8
github.com/uptrace/bun/dialect/sqlitedialect v1.1.8
github.com/uptrace/bun/driver/sqliteshim v1.1.8
go.uber.org/atomic v1.10.0
go.uber.org/multierr v1.8.0
go.uber.org/zap v1.23.0
Expand All @@ -29,16 +35,18 @@ require (
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/ajg/form v1.5.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4
github.com/google/uuid v1.3.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/klauspost/compress v1.15.11
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect
github.com/morikuni/aec v1.0.0 // indirect
Expand All @@ -48,12 +56,27 @@ require (
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/uptrace/bun/dialect/pgdialect v1.1.8
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20221017152216-f25eb7ecb193 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gotest.tools/v3 v3.4.0 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.36.3 // indirect
modernc.org/ccgo/v3 v3.16.9 // indirect
modernc.org/libc v1.17.1 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.2.1 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/sqlite v1.18.1 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.0.1 // indirect
)
Loading

0 comments on commit ae38b3d

Please sign in to comment.