Skip to content

Commit f130d7e

Browse files
committed
tunnel updates
1 parent 9f445fc commit f130d7e

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

pkg/client/webserver.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/url"
1111
"os"
1212
"path"
13+
"strings"
1314
"time"
1415

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

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

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

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

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

247254
// Errorf prints a message with ERROR prefixed.
248255
func (l *tunnelLogger) Errorf(format string, v ...interface{}) {
249-
l.Logger.ErrorfNoShare(format, v...) // this is why we dont just pass the interface in as-is.
256+
// this is why we dont just pass the interface in as-is.
257+
if l.sendSiteErrors {
258+
l.Logger.Errorf(format, v...)
259+
} else {
260+
l.Logger.ErrorfNoShare(format, v...)
261+
}
250262
}
251263

252264
// Printf prints a message with INFO prefixed.

pkg/website/clientinfo/clientinfo.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ import (
1515
// ClientInfo is the client's startup data received from the website.
1616
type ClientInfo struct {
1717
User struct {
18-
ID any `json:"id"` // user id from notifiarr db.
19-
WelcomeMSG string `json:"welcome"`
20-
Subscriber bool `json:"subscriber"`
21-
Patron bool `json:"patron"`
22-
DevAllowed bool `json:"devAllowed"`
23-
DateFormat PHPDate `json:"dateFormat"`
24-
StopLogs bool `json:"stopLogs"`
25-
Tunnels []string `json:"tunnels"`
18+
ID any `json:"id"` // user id from notifiarr db.
19+
WelcomeMSG string `json:"welcome"`
20+
Subscriber bool `json:"subscriber"`
21+
Patron bool `json:"patron"`
22+
DevAllowed bool `json:"devAllowed"`
23+
DateFormat PHPDate `json:"dateFormat"`
24+
StopLogs bool `json:"stopLogs"`
25+
TunnelURL string `json:"tunnelUrl"`
26+
Tunnels []string `json:"tunnels"`
27+
Mulery []*MuleryServer `json:"mulery"`
2628
} `json:"user"`
2729
Actions struct {
2830
Plex PlexConfig `json:"plex"` // Site Config for Plex.
@@ -36,6 +38,12 @@ type ClientInfo struct {
3638
} `json:"actions"`
3739
}
3840

41+
// MuleryServer is data from the website. It's a tunnel's https and wss urls.
42+
type MuleryServer struct {
43+
Tunnel string `json:"tunnel"`
44+
Socket string `json:"socket"`
45+
}
46+
3947
// CronConfig defines a custom GET timer from the website.
4048
// Used to offload crons to clients.
4149
type CronConfig struct {

0 commit comments

Comments
 (0)