mirror of
https://github.com/onyx-and-iris/q3rcon-proxy.git
synced 2025-06-07 19:50:23 +01:00
Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
7897348669 | ||
6489d1e556 | |||
d0e3f5863a | |||
a00796254d | |||
80ef18f705 | |||
40d79063f5 | |||
02e73a21c0 | |||
5e399b8590 | |||
28baa2ed00 | |||
58c95879cc | |||
af0a72eb67 | |||
0d85129d31 | |||
bf7bd4f5b8 | |||
a13d3d7da3 | |||
a0c1f15ef0 | |||
e0dc2c02d9 | |||
514688b9ce | |||
43183717f6 | |||
|
464fbec85f |
@ -1,6 +1,6 @@
|
|||||||
*
|
*
|
||||||
!cmd/
|
!cmd/
|
||||||
!pkg/
|
!*.go
|
||||||
|
|
||||||
!go.mod
|
!go.mod
|
||||||
!go.sum
|
!go.sum
|
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@ -9,9 +9,9 @@
|
|||||||
"type": "go",
|
"type": "go",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"mode": "auto",
|
"mode": "auto",
|
||||||
"program": "${workspaceFolder}/cmd/q3rcon-proxy/main.go",
|
"program": "${workspaceFolder}/cmd/q3rcon-proxy/",
|
||||||
"env": {
|
"env": {
|
||||||
"Q3RCON_PROXY": "28961:28960",
|
"Q3RCON_PORTS_MAPPING": "28961:28960",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
12
CHANGELOG.md
12
CHANGELOG.md
@ -11,6 +11,18 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
|
|||||||
|
|
||||||
- [x]
|
- [x]
|
||||||
|
|
||||||
|
## [1.7.0] - 2025-06-05
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Taskfile added for running and building project.
|
||||||
|
- The binary may be passed CLI flags as well as environment variables.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- CLI component rewritten with urfave/cli.
|
||||||
|
- env var `Q3RCON_TARGET_PORTS` renamed to `Q3RCON_PORTS_MAPPING`
|
||||||
|
|
||||||
## [1.4.0] - 2024-11-29
|
## [1.4.0] - 2024-11-29
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
34
README.md
34
README.md
@ -8,17 +8,36 @@ Unfortunately the Q3Rcon engine ties the rcon port to the game servers public po
|
|||||||
|
|
||||||
### Use
|
### Use
|
||||||
|
|
||||||
Run one or multiple rcon proxies by setting an environment variable `Q3RCON_TARGET_PORTS`
|
#### Flags
|
||||||
|
|
||||||
for example:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
export Q3RCON_TARGET_PORTS="20000:28960;20001:28961;20002:28962"
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
/usr/local/bin/q3rcon-proxy \
|
||||||
|
--proxy-host=0.0.0.0 \
|
||||||
|
--target-host=localhost \
|
||||||
|
--ports-mapping=28961:28960 \
|
||||||
|
--session-timeout=20 \
|
||||||
|
--loglevel=debug
|
||||||
```
|
```
|
||||||
|
|
||||||
This would configure q3rcon-proxy to run 3 proxy servers listening on ports `20000`, `20001` and `20002` that redirect rcon requests to game servers on ports `28960`, `28961` and `28962` respectively.
|
#### Environment Variables
|
||||||
|
|
||||||
Then just run the binary which you can compile yourself, download from `Releases` or use the included Dockerfile.
|
Each of the flags has a corresponding environment variable:
|
||||||
|
|
||||||
|
- `Q3RCON_PROXY_HOST`: The host the proxy server sits on.
|
||||||
|
- `Q3RCON_TARGET_HOST`: The host the game servers sit on.
|
||||||
|
- `Q3RCON_PORTS_MAPPING`: A mapping as a string with `source:target` pairs delimited by `;`.
|
||||||
|
- `Q3RCON_SESSION_TIMEOUT`: Timeout in seconds for each udp session.
|
||||||
|
- `Q3RCON_LOGLEVEL`: The application's logging level (see [Logging][logging]).
|
||||||
|
|
||||||
|
Multiple rcon proxies may be configured by setting *--ports-mapping/Q3RCON_PORTS_MAPPING* like so:
|
||||||
|
|
||||||
|
```console
|
||||||
|
export Q3RCON_PORTS_MAPPING="20000:28960;20001:28961;20002:28962"
|
||||||
|
```
|
||||||
|
|
||||||
|
This would configure q3rcon-proxy to run 3 proxy servers listening on ports 20000, 20001 and 20002 that redirect rcon requests to game servers on ports 28960, 28961 and 28962 respectively.
|
||||||
|
|
||||||
### Logging
|
### Logging
|
||||||
|
|
||||||
@ -47,4 +66,5 @@ If not set it will default to `info`.
|
|||||||
|
|
||||||
For a compatible rcon client also written in Go consider checking out the [Q3 Rcon][q3rcon] package.
|
For a compatible rcon client also written in Go consider checking out the [Q3 Rcon][q3rcon] package.
|
||||||
|
|
||||||
[q3rcon]: https://github.com/onyx-and-iris/q3rcon
|
[q3rcon]: https://github.com/onyx-and-iris/q3rcon
|
||||||
|
[logging]: https://github.com/onyx-and-iris/q3rcon-proxy/tree/dev?tab=readme-ov-file#logging
|
11
Taskfile.yml
11
Taskfile.yml
@ -58,3 +58,14 @@ tasks:
|
|||||||
desc: Clean the build artifacts
|
desc: Clean the build artifacts
|
||||||
cmds:
|
cmds:
|
||||||
- '{{.SHELL}} rm -r {{.BIN_DIR}}'
|
- '{{.SHELL}} rm -r {{.BIN_DIR}}'
|
||||||
|
|
||||||
|
run:
|
||||||
|
desc: Run the q3rcon-proxy project
|
||||||
|
cmds:
|
||||||
|
- |
|
||||||
|
go run ./cmd/{{.PROGRAM}} \
|
||||||
|
--proxy-host=0.0.0.0 \
|
||||||
|
--target-host=localhost \
|
||||||
|
--ports-mapping=28961:28960 \
|
||||||
|
--session-timeout=20 \
|
||||||
|
--loglevel=debug
|
||||||
|
@ -1,75 +1,132 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
udpproxy "github.com/onyx-and-iris/q3rcon-proxy"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/urfave/cli/v3"
|
||||||
"github.com/onyx-and-iris/q3rcon-proxy/pkg/udpproxy"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
// proxyConfig holds the configuration for a single UDP proxy server.
|
||||||
loglevel := os.Getenv("Q3RCON_LOGLEVEL")
|
type proxyConfig struct {
|
||||||
if loglevel == "" {
|
proxyHost string
|
||||||
loglevel = "info"
|
targetHost string
|
||||||
}
|
portsMapping []string
|
||||||
level, err := log.ParseLevel(loglevel)
|
sessionTimeout int
|
||||||
if err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "Invalid log level: %s\n", loglevel)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
log.SetLevel(level)
|
|
||||||
|
|
||||||
proxyHost := os.Getenv("Q3RCON_PROXY_HOST")
|
|
||||||
if proxyHost == "" {
|
|
||||||
proxyHost = "0.0.0.0"
|
|
||||||
}
|
|
||||||
|
|
||||||
targetHost := os.Getenv("Q3RCON_TARGET_HOST")
|
|
||||||
if targetHost == "" {
|
|
||||||
targetHost = "127.0.0.1"
|
|
||||||
}
|
|
||||||
|
|
||||||
proxies := os.Getenv("Q3RCON_TARGET_PORTS")
|
|
||||||
if proxies == "" {
|
|
||||||
log.Fatal("env Q3RCON_TARGET_PORTS required")
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionTimeout, err := getEnvInt("Q3RCON_SESSION_TIMEOUT")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("unable to parse Q3RCON_SESSION_TIMEOUT: %s", err.Error())
|
|
||||||
}
|
|
||||||
if sessionTimeout == 0 {
|
|
||||||
sessionTimeout = 20
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, proxy := range strings.Split(proxies, ";") {
|
|
||||||
go start(proxyHost, targetHost, proxy, sessionTimeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
<-make(chan struct{})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func start(proxyHost, targetHost, ports string, sessionTimeout int) {
|
func main() {
|
||||||
proxyPort, targetPort := func() (string, string) {
|
cmd := &cli.Command{
|
||||||
x := strings.Split(ports, ":")
|
Name: "q3rcon-proxy",
|
||||||
return x[0], x[1]
|
Usage: "A Quake 3 RCON proxy server",
|
||||||
}()
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "proxy-host",
|
||||||
|
Value: "0.0.0.0",
|
||||||
|
Usage: "Proxy host address",
|
||||||
|
Sources: cli.EnvVars("Q3RCON_PROXY_HOST"),
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "target-host",
|
||||||
|
Value: "localhost",
|
||||||
|
Usage: "Target host address",
|
||||||
|
Sources: cli.EnvVars("Q3RCON_TARGET_HOST"),
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "ports-mapping",
|
||||||
|
Usage: "Proxy and target ports (proxy:target)",
|
||||||
|
Sources: cli.EnvVars("Q3RCON_PORTS_MAPPING"),
|
||||||
|
Required: true,
|
||||||
|
Action: func(ctx context.Context, cmd *cli.Command, v string) error {
|
||||||
|
// Validate the ports mapping
|
||||||
|
for mapping := range strings.SplitSeq(v, ";") {
|
||||||
|
ports := strings.Split(mapping, ":")
|
||||||
|
if len(ports) != 2 {
|
||||||
|
return fmt.Errorf("invalid ports mapping: %s", mapping)
|
||||||
|
}
|
||||||
|
proxyPort, err := strconv.Atoi(ports[0])
|
||||||
|
if err != nil || proxyPort < 1 || proxyPort > 65535 {
|
||||||
|
return fmt.Errorf("invalid proxy port: %s", ports[0])
|
||||||
|
}
|
||||||
|
targetPort, err := strconv.Atoi(ports[1])
|
||||||
|
if err != nil || targetPort < 1 || targetPort > 65535 {
|
||||||
|
return fmt.Errorf("invalid target port: %s", ports[1])
|
||||||
|
}
|
||||||
|
if proxyPort == targetPort {
|
||||||
|
return fmt.Errorf("proxy and target ports cannot be the same: %s", mapping)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&cli.IntFlag{
|
||||||
|
Name: "session-timeout",
|
||||||
|
Value: 20,
|
||||||
|
Usage: "Session timeout in minutes",
|
||||||
|
Sources: cli.EnvVars("Q3RCON_SESSION_TIMEOUT"),
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "loglevel",
|
||||||
|
Value: "info",
|
||||||
|
Usage: "Log level (trace, debug, info, warn, error, fatal, panic)",
|
||||||
|
Sources: cli.EnvVars("Q3RCON_LOGLEVEL"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
|
||||||
|
logLevel, err := log.ParseLevel(cmd.String("loglevel"))
|
||||||
|
if err != nil {
|
||||||
|
return ctx, fmt.Errorf("invalid log level: %w", err)
|
||||||
|
}
|
||||||
|
log.SetLevel(logLevel)
|
||||||
|
return ctx, nil
|
||||||
|
},
|
||||||
|
Action: func(_ context.Context, cmd *cli.Command) error {
|
||||||
|
errChan := make(chan error)
|
||||||
|
|
||||||
hostAddr := fmt.Sprintf("%s:%s", proxyHost, proxyPort)
|
for mapping := range strings.SplitSeq(cmd.String("ports-mapping"), ";") {
|
||||||
proxyAddr := fmt.Sprintf("%s:%s", targetHost, targetPort)
|
cfg := proxyConfig{
|
||||||
|
proxyHost: cmd.String("proxy-host"),
|
||||||
|
targetHost: cmd.String("target-host"),
|
||||||
|
portsMapping: strings.Split(mapping, ":"),
|
||||||
|
sessionTimeout: cmd.Int("session-timeout"),
|
||||||
|
}
|
||||||
|
|
||||||
c, err := udpproxy.New(
|
go launchProxy(cfg, errChan)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Under normal circumstances, the main goroutine will block here.
|
||||||
|
// If we receive an error we will log it and exit
|
||||||
|
return <-errChan
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Fatal(cmd.Run(context.Background(), os.Args))
|
||||||
|
}
|
||||||
|
|
||||||
|
// launchProxy initializes the UDP proxy server with the given configuration.
|
||||||
|
// It listens on the specified proxy host and port, and forwards traffic to the target host and port.
|
||||||
|
// server.ListenAndServe blocks until the server is stopped or an error occurs.
|
||||||
|
func launchProxy(cfg proxyConfig, errChan chan<- error) {
|
||||||
|
proxyPort, targetPort := cfg.portsMapping[0], cfg.portsMapping[1]
|
||||||
|
|
||||||
|
hostAddr := fmt.Sprintf("%s:%s", cfg.proxyHost, proxyPort)
|
||||||
|
proxyAddr := fmt.Sprintf("%s:%s", cfg.targetHost, targetPort)
|
||||||
|
|
||||||
|
server, err := udpproxy.New(
|
||||||
hostAddr, proxyAddr,
|
hostAddr, proxyAddr,
|
||||||
udpproxy.WithSessionTimeout(time.Duration(sessionTimeout)*time.Minute))
|
udpproxy.WithSessionTimeout(time.Duration(cfg.sessionTimeout)*time.Minute))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
errChan <- fmt.Errorf("failed to create proxy: %w", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("q3rcon-proxy initialized: [proxy] (%s) [target] (%s)", hostAddr, proxyAddr)
|
log.Printf("q3rcon-proxy initialized: [proxy] (%s) [target] (%s)", hostAddr, proxyAddr)
|
||||||
|
|
||||||
log.Fatal(c.ListenAndServe())
|
errChan <- server.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getEnvInt(key string) (int, error) {
|
|
||||||
s := os.Getenv(key)
|
|
||||||
if s == "" {
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
v, err := strconv.Atoi(s)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
return v, nil
|
|
||||||
}
|
|
4
debian/q3rcon-proxy.service
vendored
4
debian/q3rcon-proxy.service
vendored
@ -6,9 +6,9 @@ After=network.target
|
|||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
User=gameservers
|
User=gameservers
|
||||||
Environment="Q3RCON_PROXY=20000:28960;20001:28961;20002:28962"
|
Environment="Q3RCON_PORTS_MAPPING=20000:28960;20001:28961;20002:28962"
|
||||||
Environment="Q3RCON_HOST=0.0.0.0"
|
Environment="Q3RCON_HOST=0.0.0.0"
|
||||||
Environment="Q3RCON_DEBUG=0"
|
Environment="Q3RCON_LOGLEVEL=info"
|
||||||
|
|
||||||
ExecStart=/usr/local/bin/q3rcon-proxy
|
ExecStart=/usr/local/bin/q3rcon-proxy
|
||||||
Restart=always
|
Restart=always
|
||||||
|
7
go.mod
7
go.mod
@ -4,6 +4,9 @@ go 1.24.0
|
|||||||
|
|
||||||
toolchain go1.24.1
|
toolchain go1.24.1
|
||||||
|
|
||||||
require github.com/sirupsen/logrus v1.9.3
|
require (
|
||||||
|
github.com/sirupsen/logrus v1.9.3
|
||||||
|
github.com/urfave/cli/v3 v3.3.3
|
||||||
|
)
|
||||||
|
|
||||||
require golang.org/x/sys v0.31.0 // indirect
|
require golang.org/x/sys v0.33.0 // indirect
|
||||||
|
12
go.sum
12
go.sum
@ -6,11 +6,15 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
|||||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||||
|
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
|
github.com/urfave/cli/v3 v3.3.3 h1:byCBaVdIXuLPIDm5CYZRVG6NvT7tv1ECqdU4YzlEa3I=
|
||||||
|
github.com/urfave/cli/v3 v3.3.3/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
|
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
|
||||||
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
22
option.go
Normal file
22
option.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package udpproxy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option is a functional option type that allows us to configure the Client.
|
||||||
|
type Option func(*Client)
|
||||||
|
|
||||||
|
// WithSessionTimeout is a functional option to set the session timeout
|
||||||
|
func WithSessionTimeout(timeout time.Duration) Option {
|
||||||
|
return func(c *Client) {
|
||||||
|
if timeout < time.Minute {
|
||||||
|
log.Warnf("cannot set stale session timeout to less than 1 minute.. defaulting to 20 minutes")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.sessionTimeout = timeout
|
||||||
|
}
|
||||||
|
}
|
@ -7,21 +7,6 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Option is a functional option type that allows us to configure the Client.
|
|
||||||
type Option func(*Client)
|
|
||||||
|
|
||||||
// WithSessionTimeout is a functional option to set the session timeout
|
|
||||||
func WithSessionTimeout(timeout time.Duration) Option {
|
|
||||||
return func(c *Client) {
|
|
||||||
if timeout < time.Minute {
|
|
||||||
log.Warnf("cannot set stale session timeout to less than 1 minute.. defaulting to 20 minutes")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.sessionTimeout = timeout
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
laddr *net.UDPAddr
|
laddr *net.UDPAddr
|
||||||
raddr *net.UDPAddr
|
raddr *net.UDPAddr
|
Loading…
x
Reference in New Issue
Block a user