Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(vpn): send info, debug logs over tunnel#18240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 2 commits intomainfromethan/send-more-logs-over-tunnel
Jun 6, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletioncli/vpndaemon_windows.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,7 +65,6 @@ func (r *RootCmd) vpnDaemonRun() *serpent.Command {
logger.Info(ctx,"starting tunnel")
tunnel,err:=vpn.NewTunnel(ctx,logger,pipe,vpn.NewClient(),
vpn.UseOSNetworkingStack(),
vpn.UseAsLogger(),
Copy link
MemberAuthor

@ethanndicksonethanndicksonJun 5, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The Windows app drops logs received over the tunnel, so this can be removed. It adds it's own sink tostderr.

vpn.UseCustomLogSinks(sinks...),
)
iferr!=nil {
Expand Down
5 changes: 4 additions & 1 deletionvpn/dylib/lib.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,7 +46,10 @@ func OpenTunnel(cReadFD, cWriteFD int32) int32 {
returnErrOpenPipe
}

_,err=vpn.NewTunnel(ctx,slog.Make(),conn,vpn.NewClient(),
// We log everything, as filtering is done by whatever renders the OS
// logs.
_,err=vpn.NewTunnel(ctx,slog.Make().Leveled(slog.LevelDebug),conn,
vpn.NewClient(),
vpn.UseOSNetworkingStack(),
vpn.UseAsLogger(),
)
Expand Down
32 changes: 12 additions & 20 deletionsvpn/tunnel.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,9 +46,6 @@ type Tunnel struct {

logger slog.Logger

logMu sync.Mutex
logs []*TunnelMessage
Comment on lines -49 to -50
Copy link
MemberAuthor

@ethanndicksonethanndicksonJun 5, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm not seeing any value in this buffer, as we don't do any disk I/O - the pipe is entirely in-memory. With pings every 5 seconds and debug logs on, we produce around 150~ logs a minute, or about 35 kilobytes. The in-memory pipe can handlegigabytes a second. I think buffering would make sense were we relaying the logs to a terminal or a file, but that's not the case here.

Since only Error and above logs are flushed immediately, the alternative is adding the complexity of flushing the logs from the buffer periodically. One downside of this is that the macOS timestamps on the logs once they reach the Swift code aren't actually representative of the time the log was produced.


client Client

// clientLogger is a separate logger than `logger` when the `UseAsLogger`
Expand DownExpand Up@@ -300,29 +297,22 @@ func (t *Tunnel) stop(*StopRequest) error {
var _ slog.Sink = &Tunnel{}

func (t *Tunnel) LogEntry(_ context.Context, e slog.SinkEntry) {
t.logMu.Lock()
defer t.logMu.Unlock()
t.logs = append(t.logs, &TunnelMessage{
msg := &TunnelMessage{
Msg: &TunnelMessage_Log{
Log: sinkEntryToPb(e),
},
})
}

func (t *Tunnel) Sync() {
t.logMu.Lock()
logs := t.logs
t.logs = nil
t.logMu.Unlock()
for _, msg := range logs {
select {
case <-t.ctx.Done():
return
case t.sendCh <- msg:
}
}
select {
case <-t.updater.ctx.Done():
return
case <-t.ctx.Done():
return
case t.sendCh <- msg:
Comment on lines +305 to +310
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We deliberately never cancel the tunnel ctx, due to the somewhat precarious teardown procedure. We do however cancel the updater ctx to ensure we don't tick network updates after shutdown, so we'll check for that here too.

}
}

func (*Tunnel) Sync() {}

func sinkEntryToPb(e slog.SinkEntry) *Log {
l := &Log{
// #nosec G115 - Safe conversion for log levels which are small positive integers
Expand DownExpand Up@@ -583,6 +573,8 @@ func (u *updater) sendAgentUpdate() {
return
}

u.logger.Debug(u.ctx, "sending agent update")

msg := &TunnelMessage{
Msg: &TunnelMessage_PeerUpdate{
PeerUpdate: &PeerUpdate{
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp