Skip to content

Commit

Permalink
Fix lint, update soju diff and update senpair window change refresh l…
Browse files Browse the repository at this point in the history
…ogic
antoniomika committed Jan 15, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 0bada11 commit d4087e8
Showing 4 changed files with 659 additions and 671 deletions.
36 changes: 14 additions & 22 deletions bouncer/subscriber-change.diff
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/downstream.go b/downstream.go
index 8527e94..82e2158 100644
index 78044e1..c95a0f6 100644
--- a/downstream.go
+++ b/downstream.go
@@ -2926,6 +2926,9 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
@@ -3102,6 +3102,9 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
network.pushTargets.Del(target)
}
go network.broadcastWebPush(&irc.Message{
@@ -12,7 +12,7 @@ index 8527e94..82e2158 100644
Command: "MARKREAD",
Params: []string{target, timestampStr},
})
@@ -3173,6 +3176,10 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
@@ -3350,6 +3353,10 @@ func (dc *downstreamConn) handleMessageRegistered(ctx context.Context, msg *irc.
}}
}

@@ -24,7 +24,7 @@ index 8527e94..82e2158 100644
Endpoint: endpoint,
}
diff --git a/server.go b/server.go
index 1f56205..4375fad 100644
index f6e1cf6..9114580 100644
--- a/server.go
+++ b/server.go
@@ -10,6 +10,7 @@ import (
@@ -35,7 +35,7 @@ index 1f56205..4375fad 100644
"sync"
"sync/atomic"
"time"
@@ -328,6 +329,15 @@ func (s *Server) sendWebPush(ctx context.Context, sub *webpush.Subscription, vap
@@ -333,6 +334,15 @@ func (s *Server) sendWebPush(ctx context.Context, sub *webpush.Subscription, vap
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()

@@ -51,36 +51,28 @@ index 1f56205..4375fad 100644
var urgency webpush.Urgency
switch msg.Command {
case "PRIVMSG", "NOTICE", "INVITE":
@@ -342,12 +352,10 @@ func (s *Server) sendWebPush(ctx context.Context, sub *webpush.Subscription, vap
@@ -347,7 +357,7 @@ func (s *Server) sendWebPush(ctx context.Context, sub *webpush.Subscription, vap
},
VAPIDPublicKey: s.webPush.VAPIDKeys.Public,
VAPIDPrivateKey: s.webPush.VAPIDKeys.Private,
- // TODO: switch back to an HTTP URL once this is merged:
- // https://github.com/SherClockHolmes/webpush-go/pull/57
- Subscriber: "[email protected]",
- TTL: 7 * 24 * 60 * 60, // seconds
- Urgency: urgency,
- RecordSize: 2048,
- Subscriber: "https://soju.im",
+ Subscriber: "[email protected]",
+ TTL: 7 * 24 * 60 * 60, // seconds
+ Urgency: urgency,
+ RecordSize: 2048,
}

if vapidPubKey != options.VAPIDPublicKey {
TTL: 7 * 24 * 60 * 60, // seconds
Urgency: urgency,
RecordSize: 2048,
diff --git a/upstream.go b/upstream.go
index 6de6445..d734fa0 100644
index ea309f4..e198dc7 100644
--- a/upstream.go
+++ b/upstream.go
@@ -695,6 +695,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
@@ -694,6 +694,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
}

if sendPushNotification && (highlight || directMessage) {
if !self && !detached && msg.Command != "TAGMSG" && (highlight || directMessage) {
+ msg.Tags["bouncerNetwork"] = strconv.FormatInt(uc.network.ID, 10)
go uc.network.broadcastWebPush(msg)
if timestamp, err := time.Parse(xirc.ServerTimeLayout, string(msg.Tags["time"])); err == nil {
uc.network.pushTargets.Set(bufferName, timestamp)
@@ -1639,6 +1640,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
@@ -1640,6 +1641,7 @@ func (uc *upstreamConn) handleMessage(ctx context.Context, msg *irc.Message) err
})

if weAreInvited {
268 changes: 136 additions & 132 deletions go.mod
Original file line number Diff line number Diff line change
@@ -16,22 +16,24 @@ go 1.23.1

// replace git.sr.ht/~rockorager/vaxis => ../../vaxis

// replace github.com/charmbracelet/wish => ../../wish

replace git.sr.ht/~delthas/senpai => github.com/antoniomika/senpai v0.0.0-20250114180426-3061ddccec76

replace git.sr.ht/~rockorager/vaxis => github.com/antoniomika/vaxis v0.0.0-20250114030546-8524674789ca

require (
git.sr.ht/~delthas/senpai v0.3.1-0.20240425235039-206be659439e
github.com/alecthomas/chroma/v2 v2.15.0
github.com/alecthomas/chroma/v2 v2.14.0
github.com/antoniomika/syncmap v1.0.0
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/charmbracelet/bubbles v0.20.0
github.com/charmbracelet/bubbletea v1.2.4
github.com/charmbracelet/bubbletea v1.2.2
github.com/charmbracelet/glamour v0.8.0
github.com/charmbracelet/lipgloss v1.0.0
github.com/charmbracelet/promwish v0.7.0
github.com/charmbracelet/ssh v0.0.0-20241211182756-4fe22b0f1b7c
github.com/charmbracelet/wish v1.4.1
github.com/charmbracelet/ssh v0.0.0-20240725163421-eb71b85b27aa
github.com/charmbracelet/wish v1.4.3
github.com/containerd/console v1.0.4
github.com/darkweak/souin v1.7.5
github.com/darkweak/souin/plugins/souin/storages v1.7.5
@@ -49,105 +51,103 @@ require (
github.com/picosh/pobj v0.0.0-20241016194248-c39198b2ff23
github.com/picosh/pubsub v0.0.0-20241114191831-ec8f16c0eb88
github.com/picosh/send v0.0.0-20241218031305-056b1fe8ff80
github.com/picosh/tunkit v0.0.0-20241216034628-decf68dd65bb
github.com/picosh/tunkit v0.0.0-20240905223921-532404cef9d9
github.com/picosh/utils v0.0.0-20241120033529-8ca070c09bf4
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
github.com/sendgrid/sendgrid-go v3.16.0+incompatible
github.com/simplesurance/go-ip-anonymizer v0.0.0-20200429124537-35a880f8e87d
github.com/x-way/crawlerdetect v0.2.25
github.com/x-way/crawlerdetect v0.2.24
github.com/yuin/goldmark v1.7.8
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
github.com/yuin/goldmark-meta v1.1.0
go.abhg.dev/goldmark/anchor v0.1.1
go.abhg.dev/goldmark/hashtag v0.3.1
go.abhg.dev/goldmark/toc v0.10.0
golang.org/x/crypto v0.32.0
google.golang.org/protobuf v1.36.2
golang.org/x/crypto v0.31.0
google.golang.org/protobuf v1.35.2
gopkg.in/yaml.v2 v2.4.0
)

require (
cel.dev/expr v0.19.1 // indirect
codeberg.org/emersion/go-scfg v0.1.0 // indirect
dario.cat/mergo v1.0.1 // indirect
dario.cat/mergo v1.0.0 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
git.sr.ht/~rockorager/vaxis v0.11.0 // indirect
git.sr.ht/~rockorager/vaxis v0.10.3 // indirect
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect
github.com/DavidGamba/go-getoptions v0.31.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/PuerkitoBio/goquery v1.10.1 // indirect
github.com/RoaringBitmap/roaring v1.9.4 // indirect
github.com/andybalholm/cascadia v1.3.3 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/PuerkitoBio/goquery v1.10.0 // indirect
github.com/RoaringBitmap/roaring v1.2.3 // indirect
github.com/andybalholm/cascadia v1.3.2 // indirect
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/antlabs/stl v0.0.2 // indirect
github.com/antlabs/timer v0.1.4 // indirect
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
github.com/antlabs/stl v0.0.1 // indirect
github.com/antlabs/timer v0.0.11 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aws/aws-sdk-go-v2 v1.32.8 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.7 // indirect
github.com/aws/aws-sdk-go-v2/config v1.28.10 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.51 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.23 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.48 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.27 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.27 // indirect
github.com/aws/aws-sdk-go-v2 v1.32.4 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.6 // indirect
github.com/aws/aws-sdk-go-v2/config v1.28.4 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.45 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.19 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.38 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.23 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.23 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.27 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.8 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.8 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.8 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.72.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.24.9 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.8 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.6 // indirect
github.com/aws/smithy-go v1.22.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.23 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.4 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.4 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.67.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.24.5 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.4 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.33.0 // indirect
github.com/aws/smithy-go v1.22.0 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.20.0 // indirect
github.com/bits-and-blooms/bitset v1.5.0 // indirect
github.com/buraksezer/consistent v0.10.0 // indirect
github.com/buraksezer/olric v0.5.7 // indirect
github.com/buraksezer/olric v0.5.6 // indirect
github.com/bwmarrin/snowflake v0.3.0 // indirect
github.com/caddyserver/caddy/v2 v2.9.1 // indirect
github.com/caddyserver/certmagic v0.21.6 // indirect
github.com/caddyserver/caddy/v2 v2.8.4 // indirect
github.com/caddyserver/certmagic v0.21.3 // indirect
github.com/caddyserver/zerossl v0.1.3 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/charmbracelet/keygen v0.5.1 // indirect
github.com/charmbracelet/log v0.4.0 // indirect
github.com/charmbracelet/x/ansi v0.6.0 // indirect
github.com/charmbracelet/x/ansi v0.4.5 // indirect
github.com/charmbracelet/x/conpty v0.1.0 // indirect
github.com/charmbracelet/x/errors v0.0.0-20250112114943-1775be7e67ae // indirect
github.com/charmbracelet/x/exp/term v0.0.0-20240503143715-36ea203beff4 // indirect
github.com/charmbracelet/x/errors v0.0.0-20241113152101-0af7d04e9f32 // indirect
github.com/charmbracelet/x/input v0.2.0 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/charmbracelet/x/termios v0.1.0 // indirect
github.com/chzyer/readline v1.5.1 // indirect
github.com/coreos/go-oidc/v3 v3.12.0 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/creack/pty v1.1.24 // indirect
github.com/darkweak/go-esi v0.0.6 // indirect
github.com/darkweak/storages/badger v0.0.11 // indirect
github.com/darkweak/storages/etcd v0.0.11 // indirect
github.com/darkweak/storages/nats v0.0.11 // indirect
github.com/darkweak/storages/nuts v0.0.11 // indirect
github.com/darkweak/storages/olric v0.0.11 // indirect
github.com/darkweak/go-esi v0.0.5 // indirect
github.com/darkweak/storages/badger v0.0.8 // indirect
github.com/darkweak/storages/etcd v0.0.8 // indirect
github.com/darkweak/storages/nats v0.0.8 // indirect
github.com/darkweak/storages/nuts v0.0.8 // indirect
github.com/darkweak/storages/olric v0.0.8 // indirect
github.com/darkweak/storages/otter v0.0.11 // indirect
github.com/darkweak/storages/redis v0.0.11 // indirect
github.com/darkweak/storages/redis v0.0.8 // indirect
github.com/delthas/go-libnp v0.0.0-20250105150050-96674b98150e // indirect
github.com/delthas/go-localeinfo v0.0.0-20240813094314-e5413e186769 // indirect
github.com/dgraph-io/badger v1.6.2 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/badger/v3 v3.2103.5 // indirect
github.com/dgraph-io/ristretto v0.2.0 // indirect
github.com/dgryski/go-farm v0.0.0-20240924180020-3414d57e47da // indirect
github.com/dgraph-io/ristretto v0.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/dlclark/regexp2 v1.11.4 // indirect
@@ -162,50 +162,55 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/forPelevin/gomoji v1.2.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/gammazero/deque v1.0.0 // indirect
github.com/gammazero/deque v0.2.1 // indirect
github.com/gkampitakis/ciinfo v0.3.0 // indirect
github.com/gkampitakis/go-diff v1.3.2 // indirect
github.com/go-errors/errors v1.5.1 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
github.com/go-kit/kit v0.13.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/go-xmlfmt/xmlfmt v1.1.3 // indirect
github.com/goccy/go-json v0.10.4 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect
github.com/go-xmlfmt/xmlfmt v1.1.2 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gofrs/flock v0.12.1 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
github.com/golang/geo v0.0.0-20230421003525-6adc56603217 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/golang/glog v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.1.3 // indirect
github.com/google/cel-go v0.22.1 // indirect
github.com/google/flatbuffers v24.12.23+incompatible // indirect
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/cel-go v0.20.1 // indirect
github.com/google/flatbuffers v23.1.21+incompatible // indirect
github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gorilla/css v1.0.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-metrics v0.5.4 // indirect
github.com/hashicorp/go-msgpack/v2 v2.1.2 // indirect
github.com/hashicorp/go-msgpack v0.5.5 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-sockaddr v1.0.7 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.6.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hashicorp/memberlist v0.5.2 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
github.com/hashicorp/memberlist v0.5.0 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.3 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.2 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/pgx/v4 v4.18.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.9 // indirect
@@ -217,19 +222,19 @@ require (
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/maruel/natural v1.1.1 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mattn/go-sixel v0.0.5 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/maypok86/otter v1.2.4 // indirect
github.com/maypok86/otter v1.2.1 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mholt/acmez/v3 v3.0.1 // indirect
github.com/mholt/acmez/v2 v2.0.1 // indirect
github.com/miekg/dns v1.1.62 // indirect
github.com/minio/madmin-go/v3 v3.0.86 // indirect
github.com/minio/madmin-go/v3 v3.0.77 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.83 // indirect
github.com/minio/minio-go/v7 v7.0.80 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
@@ -241,99 +246,98 @@ require (
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nats-io/nats.go v1.38.0 // indirect
github.com/nats-io/nkeys v0.4.9 // indirect
github.com/nats-io/nats.go v1.36.0 // indirect
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/neurosnap/go-jpeg-image-structure v0.0.0-20221010133817-70b1c1ff679e // indirect
github.com/nutsdb/nutsdb v1.0.4 // indirect
github.com/onsi/ginkgo/v2 v2.22.2 // indirect
github.com/onsi/ginkgo/v2 v2.15.0 // indirect
github.com/philhofer/fwd v1.1.3-0.20240916144458-20a13a1f6b7c // indirect
github.com/picosh/go-rsync-receiver v0.0.0-20240709135253-1daf4b12a9fc // indirect
github.com/pierrec/lz4/v4 v4.1.22 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/sftp v1.13.7 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/pquerna/cachecontrol v0.2.0 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.61.0 // indirect
github.com/prometheus/common v0.60.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/prometheus/prom2json v1.4.1 // indirect
github.com/prometheus/prometheus v0.301.0 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.48.2 // indirect
github.com/redis/rueidis v1.0.52 // indirect
github.com/prometheus/prometheus v0.300.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/quic-go v0.44.0 // indirect
github.com/redis/rueidis v1.0.39 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.13.2-0.20241226121412-a5dc8ff20d0a // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/xid v1.6.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/safchain/ethtool v0.5.9 // indirect
github.com/safchain/ethtool v0.4.1 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/secure-io/sio-go v0.3.1 // indirect
github.com/sendgrid/rest v2.6.9+incompatible // indirect
github.com/shirou/gopsutil/v3 v3.24.5 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/slackhq/nebula v1.9.5 // indirect
github.com/smallstep/certificates v0.28.1 // indirect
github.com/smallstep/cli-utils v0.10.0 // indirect
github.com/smallstep/nosql v0.7.0 // indirect
github.com/smallstep/pkcs7 v0.1.1 // indirect
github.com/smallstep/scep v0.0.0-20241223071629-a37a330173bc // indirect
github.com/slackhq/nebula v1.6.1 // indirect
github.com/smallstep/certificates v0.26.1 // indirect
github.com/smallstep/nosql v0.6.1 // indirect
github.com/smallstep/pkcs7 v0.0.0-20231024181729-3b98ecc1ca81 // indirect
github.com/smallstep/scep v0.0.0-20231024192529-aee96d7ad34d // indirect
github.com/smallstep/truststore v0.13.0 // indirect
github.com/soniakeys/quant v1.0.0 // indirect
github.com/spf13/cast v1.7.1 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/tailscale/tscert v0.0.0-20240608151842-d3f834017e53 // indirect
github.com/tidwall/btree v1.7.0 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/tailscale/tscert v0.0.0-20240517230440-bbccfbf48933 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/tidwall/gjson v1.17.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tidwall/redcon v1.6.2 // indirect
github.com/tidwall/sjson v1.2.5 // indirect
github.com/tinylib/msgp v1.2.5 // indirect
github.com/tinylib/msgp v1.2.4 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.9.0 // indirect
github.com/urfave/cli v1.22.16 // indirect
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/urfave/cli v1.22.14 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/xujiajun/mmap-go v1.0.1 // indirect
github.com/xujiajun/utils v0.0.0-20220904132955-5f7c5b914235 // indirect
github.com/yuin/goldmark-emoji v1.0.4 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
github.com/zeebo/blake3 v0.2.4 // indirect
go.etcd.io/bbolt v1.3.11 // indirect
go.etcd.io/etcd/api/v3 v3.5.17 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.17 // indirect
go.etcd.io/etcd/client/v3 v3.5.17 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
go.etcd.io/bbolt v1.3.9 // indirect
go.etcd.io/etcd/api/v3 v3.5.14 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.14 // indirect
go.etcd.io/etcd/client/v3 v3.5.14 // indirect
go.opencensus.io v0.24.0 // indirect
go.step.sm/crypto v0.56.0 // indirect
go.step.sm/linkedca v0.22.2 // indirect
go.step.sm/cli-utils v0.9.0 // indirect
go.step.sm/crypto v0.45.0 // indirect
go.step.sm/linkedca v0.20.1 // indirect
go.uber.org/automaxprocs v1.6.0 // indirect
go.uber.org/mock v0.5.0 // indirect
go.uber.org/mock v0.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
go.uber.org/zap/exp v0.3.0 // indirect
golang.org/x/crypto/x509roots/fallback v0.0.0-20250106144430-8929309228b4 // indirect
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8 // indirect
golang.org/x/image v0.23.0 // indirect
go.uber.org/zap/exp v0.2.0 // indirect
golang.org/x/crypto/x509roots/fallback v0.0.0-20240507223354-67b13616a595 // indirect
golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect
golang.org/x/image v0.21.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/oauth2 v0.25.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.9.0 // indirect
golang.org/x/tools v0.29.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250106144421-5f5ef82da422 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250106144421-5f5ef82da422 // indirect
google.golang.org/grpc v1.69.2 // indirect
golang.org/x/time v0.8.0 // indirect
golang.org/x/tools v0.27.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/grpc v1.67.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
howett.net/plist v1.0.1 // indirect
mvdan.cc/xurls/v2 v2.6.0 // indirect
howett.net/plist v1.0.0 // indirect
mvdan.cc/xurls/v2 v2.5.0 // indirect
)
901 changes: 426 additions & 475 deletions go.sum

Large diffs are not rendered by default.

125 changes: 83 additions & 42 deletions shared/senpai.go
Original file line number Diff line number Diff line change
@@ -10,61 +10,66 @@ import (
"github.com/containerd/console"
)

type consoleData struct {
data []byte
err error
}

type VConsole struct {
ssh.Session
pty ssh.Pty

sizeEnableOnce sync.Once
primaryAttrOnce sync.Once

sendSizeMu sync.Mutex
sendSize bool
sizeEnableOnce sync.Once

windowMu sync.Mutex
currentWindow ssh.Window

readReq chan []byte
dataChan chan consoleData

wg sync.WaitGroup
}

func (v *VConsole) Read(p []byte) (int, error) {
v.wg.Add(1)
defer v.wg.Done()
tot := 0

v.sizeEnableOnce.Do(func() {
tot += copy(p, []byte("\x1b[?2048h"))
v.sendSizeMu.Lock()
v.sendSize = true
v.sendSizeMu.Unlock()
})

if tot > 0 {
return tot, nil
}

ok := v.sendSizeMu.TryLock()
if ok {
if v.sendSize {
v.sendSize = false

v.windowMu.Lock()
tot += copy(p, []byte(fmt.Sprintf("\x1b[48;%d;%d;%d;%dt", v.currentWindow.Height, v.currentWindow.Width, v.currentWindow.HeightPixels, v.currentWindow.WidthPixels)))
v.windowMu.Unlock()
if len(v.readReq) == 0 {
select {
case v.readReq <- make([]byte, len(p)):
case <-v.Session.Context().Done():
return 0, v.Session.Context().Err()
}

v.sendSizeMu.Unlock()
}

if tot > 0 {
return tot, nil
}

v.primaryAttrOnce.Do(func() {
tot += copy(p, []byte("\x1b[?1;0c"))
v.sizeEnableOnce.Do(func() {
tot += copy(p, []byte("\x1b[?2048h"))
v.windowMu.Lock()
select {
case v.dataChan <- consoleData{[]byte(fmt.Sprintf("\x1b[48;%d;%d;%d;%dt", v.currentWindow.Height, v.currentWindow.Width, v.currentWindow.HeightPixels, v.currentWindow.WidthPixels)), nil}:
case <-v.Session.Context().Done():
return
}
v.windowMu.Unlock()
select {
case v.dataChan <- consoleData{[]byte("\x1b[?1;0c"), nil}:
case <-v.Session.Context().Done():
return
}
})

if tot > 0 {
return tot, nil
}

n, err := v.Session.Read(p)
return tot + n, err
select {
case data := <-v.dataChan:
tot += copy(p, data.data)
return tot, data.err
case <-v.Session.Context().Done():
return 0, v.Session.Context().Err()
}
}

func (v *VConsole) Resize(winSize console.WinSize) error {
@@ -110,6 +115,14 @@ func (v *VConsole) Name() string {
return v.pty.Name()
}

func (v *VConsole) Close() error {
err := v.Session.Close()
v.wg.Wait()
close(v.readReq)
close(v.dataChan)
return err
}

func NewSenpaiApp(sesh ssh.Session, username, pass string) (*senpai.App, error) {
pty, win, ok := sesh.Pty()
if !ok {
@@ -121,17 +134,45 @@ func NewSenpaiApp(sesh ssh.Session, username, pass string) (*senpai.App, error)
pty: pty,
Session: sesh,
currentWindow: pty.Window,
readReq: make(chan []byte, 100),
dataChan: make(chan consoleData, 100),
}

vty.wg.Add(2)

go func() {
defer vty.wg.Done()
for {
select {
case <-sesh.Context().Done():
return
case data := <-vty.readReq:
n, err := vty.Session.Read(data)
select {
case vty.dataChan <- consoleData{data[:n], err}:
case <-sesh.Context().Done():
return
}
}
}
}()

go func() {
for w := range win {
vty.windowMu.Lock()
vty.currentWindow = w
vty.windowMu.Unlock()

vty.sendSizeMu.Lock()
vty.sendSize = true
vty.sendSizeMu.Unlock()
defer vty.wg.Done()
for {
select {
case <-sesh.Context().Done():
return
case w := <-win:
vty.windowMu.Lock()
vty.currentWindow = w
vty.windowMu.Unlock()
select {
case vty.dataChan <- consoleData{[]byte(fmt.Sprintf("\x1b[48;%d;%d;%d;%dt", w.Height, w.Width, w.HeightPixels, w.WidthPixels)), nil}:
case <-sesh.Context().Done():
return
}
}
}
}()

0 comments on commit d4087e8

Please sign in to comment.