Skip to content

Commit

Permalink
Tunnel updates (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnewhall authored Feb 6, 2024
2 parents 0d92e10 + 45dbe4d commit 38552fc
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
brew install mitchellh/gon/gon jq
make signdmg
- name: upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: dmg-release
path: release
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
make release
source settings.sh ; echo "version=${VERSION}-${ITERATION}" >> $GITHUB_OUTPUT
- name: upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: release
path: release
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ require (
golift.io/cnfgfile v0.0.0-20230531075023-f880041cc0a0
golift.io/datacounter v1.0.4
golift.io/deluge v0.10.1
golift.io/mulery v0.0.5
golift.io/mulery v0.0.6-0.20240206194956-b0ec70c7ca65
golift.io/nzbget v0.1.5
golift.io/qbit v0.0.0-20240203190039-8f98b32d1e66
golift.io/rotatorr v0.0.0-20230911015553-cd2abbd726c7
Expand Down Expand Up @@ -82,7 +82,7 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/kdomanski/iso9660 v0.4.0 // indirect
github.com/klauspost/compress v1.17.5 // indirect
github.com/klauspost/compress v1.17.6 // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/lufia/plan9stats v0.0.0-20231016141302-07b5767bb0ed // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand Down Expand Up @@ -114,7 +114,7 @@ require (
lukechampine.com/uint128 v1.3.0 // indirect
modernc.org/cc/v3 v3.41.0 // indirect
modernc.org/ccgo/v3 v3.16.15 // indirect
modernc.org/libc v1.40.17 // indirect
modernc.org/libc v1.41.0 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/opt v0.1.3 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ github.com/kevinburke/go-bindata/v4 v4.0.2 h1:6qQI0nNTL27wM1En8zQHGBEPp3ETzgFU6h
github.com/kevinburke/go-bindata/v4 v4.0.2/go.mod h1:M/CkBqw2qCZ1Ztv5JyKgocGYWyUkYlDqkqXS1ktLe5c=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
github.com/klauspost/compress v1.17.5 h1:d4vBd+7CHydUqpFBgUEKkSdtSugf9YFmSkvUYPquI5E=
github.com/klauspost/compress v1.17.5/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI=
github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down Expand Up @@ -443,8 +443,8 @@ golift.io/datacounter v1.0.4 h1:b2gLQCs8WYRtKjOMG0qM82rF1o0+oKUXB9QH7kjmxZ4=
golift.io/datacounter v1.0.4/go.mod h1:79Yf1ucynYvZzVS/hpfrAFt6y/w82FMlOJgh+MBaZvs=
golift.io/deluge v0.10.1 h1:wu1GzXsDYzWGnRl4mNEd2IeY0O7+jhYJ4IKBPfDEanM=
golift.io/deluge v0.10.1/go.mod h1:i6h0V+nRzG4XymHQ5kC4d4Z6JZw2M83gMqcZhWgiD1k=
golift.io/mulery v0.0.5 h1:/+UF6KRDy0jHBi0Rf5Ge0q0fMz5OPuNJViIOlaK3WhM=
golift.io/mulery v0.0.5/go.mod h1:xIzxZSHGqWtqPsOd9SDhffsSne1sAHQy+njKRehO5qE=
golift.io/mulery v0.0.6-0.20240206194956-b0ec70c7ca65 h1:twHM68+hx9AIfMIYMokBNVKEOhM9gdRUPuq/v7Rb+3g=
golift.io/mulery v0.0.6-0.20240206194956-b0ec70c7ca65/go.mod h1:xIzxZSHGqWtqPsOd9SDhffsSne1sAHQy+njKRehO5qE=
golift.io/nzbget v0.1.5 h1:TE/TPldaLr/Qy5wy+7R4Lvur1SosOpjTLs6BLK3TMrU=
golift.io/nzbget v0.1.5/go.mod h1:YYGQsadsgvadzM6qlVBS21gz8DBhfbxexGMndsGelj8=
golift.io/qbit v0.0.0-20240203190039-8f98b32d1e66 h1:ipkWG/7cwFrExfQuSuiFAmQjq+jiUIc0sZtYAk8+tyc=
Expand Down Expand Up @@ -521,8 +521,8 @@ modernc.org/ccorpus v1.11.6 h1:J16RXiiqiCgua6+ZvQot4yUuUy8zxgqbqEEUuGPlISk=
modernc.org/ccorpus v1.11.6/go.mod h1:2gEUTrWqdpH2pXsmTM1ZkjeSrUWDpjMu2T6m29L/ErQ=
modernc.org/httpfs v1.0.6 h1:AAgIpFZRXuYnkjftxTAZwMIiwEqAfk8aVB2/oA6nAeM=
modernc.org/httpfs v1.0.6/go.mod h1:7dosgurJGp0sPaRanU53W4xZYKh14wfzX420oZADeHM=
modernc.org/libc v1.40.17 h1:g3CzILr809cxqZGe0IuNh1Z7j2Dm7uDtyjNGyY5NuQU=
modernc.org/libc v1.40.17/go.mod h1:w0eszPsiXoOnoMJgrXjglgLuDy/bt5RR4y3QzUUeodY=
modernc.org/libc v1.41.0 h1:g9YAc6BkKlgORsUWj+JwqoB1wU3o4DE3bM3yvA3k+Gk=
modernc.org/libc v1.41.0/go.mod h1:w0eszPsiXoOnoMJgrXjglgLuDy/bt5RR4y3QzUUeodY=
modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4=
modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo=
modernc.org/memory v1.7.2 h1:Klh90S215mmH8c9gO98QxQFsY+W451E8AnzjoE2ee1E=
Expand Down
18 changes: 15 additions & 3 deletions pkg/client/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/url"
"os"
"path"
"strings"
"time"

"github.com/Notifiarr/notifiarr/pkg/mnd"
Expand Down Expand Up @@ -65,6 +66,7 @@ func (c *Client) startTunnel(ctx context.Context) {
// If clientinfo is nil, then we probably have a bad API key.
ci := clientinfo.Get()
if ci == nil {
c.Errorf("Skipping tunnel creation because there is no client info.")
return
}

Expand All @@ -86,7 +88,7 @@ func (c *Client) startTunnel(ctx context.Context) {
poolmax++
}

if poolmax > maxPoolSize {
if poolmax > maxPoolSize || ci.IsSub() {
poolmax = maxPoolSize
} else if poolmax < maxPoolMin {
poolmax = maxPoolMin
Expand All @@ -112,8 +114,11 @@ func (c *Client) startTunnel(ctx context.Context) {
Backoff: 600*time.Millisecond + time.Duration(c.triggers.Timers.Rand().Intn(600))*time.Millisecond,
SecretKey: c.Config.APIKey,
Handler: remWs.Wrap(c.prefixURLbase(c.Config.Router), c.Logger.HTTPLog.Writer()).ServeHTTP,
Logger: &tunnelLogger{Logger: c.Logger},
Logger: &tunnelLogger{Logger: c.Logger, sendSiteErrors: ci.User.DevAllowed},
})
c.Printf("Tunneling to %q with %d connections; cleaner:%s, backoff:%s, url: %s, hash: %s",
strings.Join(c.tunnel.Targets, ", "), c.tunnel.PoolMaxSize, c.tunnel.CleanInterval,
c.tunnel.Backoff, ci.User.TunnelURL, c.tunnel.GetID())
c.tunnel.Start(ctx)
}

Expand Down Expand Up @@ -237,6 +242,8 @@ func (n *netConnWrapper) Write(b []byte) (int, error) {
// tunnelLogger lets us tune the logs from the mulery tunnel.
type tunnelLogger struct {
mnd.Logger
// sendSiteErrors true sends tunnel errors to website as notifications.
sendSiteErrors bool
}

// Debugf prints a message with DEBUG prefixed.
Expand All @@ -246,7 +253,12 @@ func (l *tunnelLogger) Debugf(format string, v ...interface{}) {

// Errorf prints a message with ERROR prefixed.
func (l *tunnelLogger) Errorf(format string, v ...interface{}) {
l.Logger.ErrorfNoShare(format, v...) // this is why we dont just pass the interface in as-is.
// this is why we dont just pass the interface in as-is.
if l.sendSiteErrors {
l.Logger.Errorf(format, v...)
} else {
l.Logger.ErrorfNoShare(format, v...)
}
}

// Printf prints a message with INFO prefixed.
Expand Down
24 changes: 16 additions & 8 deletions pkg/website/clientinfo/clientinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ import (
// ClientInfo is the client's startup data received from the website.
type ClientInfo struct {
User struct {
ID any `json:"id"` // user id from notifiarr db.
WelcomeMSG string `json:"welcome"`
Subscriber bool `json:"subscriber"`
Patron bool `json:"patron"`
DevAllowed bool `json:"devAllowed"`
DateFormat PHPDate `json:"dateFormat"`
StopLogs bool `json:"stopLogs"`
Tunnels []string `json:"tunnels"`
ID any `json:"id"` // user id from notifiarr db.
WelcomeMSG string `json:"welcome"`
Subscriber bool `json:"subscriber"`
Patron bool `json:"patron"`
DevAllowed bool `json:"devAllowed"`
DateFormat PHPDate `json:"dateFormat"`
StopLogs bool `json:"stopLogs"`
TunnelURL string `json:"tunnelUrl"`
Tunnels []string `json:"tunnels"`
Mulery []*MuleryServer `json:"mulery"`
} `json:"user"`
Actions struct {
Plex PlexConfig `json:"plex"` // Site Config for Plex.
Expand All @@ -36,6 +38,12 @@ type ClientInfo struct {
} `json:"actions"`
}

// MuleryServer is data from the website. It's a tunnel's https and wss urls.
type MuleryServer struct {
Tunnel string `json:"tunnel"`
Socket string `json:"socket"`
}

// CronConfig defines a custom GET timer from the website.
// Used to offload crons to clients.
type CronConfig struct {
Expand Down

0 comments on commit 38552fc

Please sign in to comment.