Skip to content

Commit b6f90e1

Browse files
committed
Multiple updates
1 parent 2ae50b9 commit b6f90e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1928
-657
lines changed

cmd/streamd/main.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package main
22

33
import (
44
"context"
5+
"crypto/tls"
56
"log"
6-
"net"
77
"net/http"
88
_ "net/http/pprof"
99
"os"
@@ -19,11 +19,13 @@ import (
1919
"github.com/getsentry/sentry-go"
2020
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
2121
"github.com/spf13/pflag"
22+
"github.com/xaionaro-go/eventbus"
2223
"github.com/xaionaro-go/grpcproxy/grpcproxyserver"
2324
"github.com/xaionaro-go/grpcproxy/protobuf/go/proxy_grpc"
2425
"github.com/xaionaro-go/obs-grpc-proxy/protobuf/go/obs_grpc"
2526
"github.com/xaionaro-go/observability"
2627
"github.com/xaionaro-go/streamctl/cmd/streamd/ui"
28+
"github.com/xaionaro-go/streamctl/pkg/cert"
2729
"github.com/xaionaro-go/streamctl/pkg/streamcontrol"
2830
"github.com/xaionaro-go/streamctl/pkg/streamd"
2931
"github.com/xaionaro-go/streamctl/pkg/streamd/config"
@@ -127,6 +129,8 @@ func main() {
127129
}
128130
defer belt.Flush(ctx)
129131

132+
eventbus.LoggingEnabled = true
133+
130134
configPathExpanded, err := xpath.Expand(*configPath)
131135
if err != nil {
132136
l.Fatalf("unable to get the path to the data file: %v", err)
@@ -181,7 +185,16 @@ func main() {
181185
}
182186
})
183187

184-
listener, err := net.Listen("tcp", *listenAddr)
188+
cert, err := cert.GenerateSelfSignedForServer()
189+
if err != nil {
190+
logger.Panicf(ctx, "unable to generate the certificate: %v", err)
191+
}
192+
193+
listener, err := tls.Listen("tcp", *listenAddr, &tls.Config{
194+
Certificates: []tls.Certificate{cert},
195+
NextProtos: []string{"h2"},
196+
})
197+
//listener, err := net.Listen("tcp", *listenAddr)
185198
if err != nil {
186199
log.Fatalf("failed to listen: %v", err)
187200
}

cmd/streampanel/FyneApp.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Website = "https://github.com/xaionaro/streamctl"
55
Name = "streampanel"
66
ID = "center.dx.streampanel"
77
Version = "0.1.0"
8-
Build = 432
8+
Build = 433

cmd/streampanel/runtime.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/facebookincubator/go-belt"
1717
"github.com/facebookincubator/go-belt/tool/logger"
1818
"github.com/prometheus/client_golang/prometheus/promhttp"
19+
"github.com/xaionaro-go/eventbus"
1920
"github.com/xaionaro-go/observability"
2021
)
2122

@@ -115,6 +116,8 @@ func initRuntime(
115116

116117
seppukuIfMemHugeLeak(ctx)
117118

119+
eventbus.LoggingEnabled = true
120+
118121
ctx, cancelFn := context.WithCancel(ctx)
119122
return ctx, func() {
120123
defer belt.Flush(ctx)

cmd/streampanel/streamd.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"bytes"
55
"context"
6+
"crypto/tls"
67
"encoding/gob"
78
"fmt"
89
"net"
@@ -20,6 +21,7 @@ import (
2021
"github.com/xaionaro-go/obs-grpc-proxy/protobuf/go/obs_grpc"
2122
"github.com/xaionaro-go/observability"
2223
"github.com/xaionaro-go/streamctl/cmd/streamd/ui"
24+
"github.com/xaionaro-go/streamctl/pkg/cert"
2325
"github.com/xaionaro-go/streamctl/pkg/mainprocess"
2426
"github.com/xaionaro-go/streamctl/pkg/streamcontrol"
2527
"github.com/xaionaro-go/streamctl/pkg/streamd"
@@ -257,7 +259,17 @@ func initGRPCServers(
257259
) (net.Listener, *grpc.Server, *server.GRPCServer, obs_grpc.OBSServer, proxy_grpc.NetworkProxyServer) {
258260
logger.Debugf(ctx, "initGRPCServers")
259261
defer logger.Debugf(ctx, "/initGRPCServers")
260-
listener, err := net.Listen("tcp", listenAddr)
262+
263+
cert, err := cert.GenerateSelfSignedForServer()
264+
if err != nil {
265+
logger.Panicf(ctx, "unable to generate the certificate: %v", err)
266+
}
267+
268+
logger.Debugf(ctx, "generated certificate %#+v", cert)
269+
listener, err := tls.Listen("tcp", listenAddr, &tls.Config{
270+
Certificates: []tls.Certificate{cert},
271+
NextProtos: []string{"h2"},
272+
})
261273
if err != nil {
262274
logger.Panicf(ctx, "failed to listen: %v", err)
263275
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ replace github.com/asticode/go-astiav v0.36.0 => github.com/xaionaro-go/astiav v
2727

2828
replace github.com/bluenviron/mediacommon/v2 v2.0.1-0.20250324151931-b8ce69d15d3d => github.com/xaionaro-go/mediacommon/v2 v2.0.0-20250420012906-03d6d69ac3b7
2929

30-
replace github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef => github.com/mysteriumnetwork/EventBus v0.0.0-20220414214953-84469ec2b111
31-
3230
require (
3331
github.com/facebookincubator/go-belt v0.0.0-20250308011339-62fb7027b11f
3432
github.com/go-git/go-billy/v5 v5.6.2
3533
github.com/goccy/go-yaml v1.17.1
3634
github.com/hashicorp/go-multierror v1.1.1
3735
github.com/nicklaw5/helix/v2 v2.30.1-0.20240715193454-0151ccccf980
3836
github.com/spf13/cobra v1.8.1
37+
github.com/xaionaro-go/eventbus v0.0.0-20250712220612-3cb9e775fb98
3938
github.com/xaionaro-go/logrustash v0.0.0-20240804141650-d48034780a5f // indirect
4039
golang.org/x/oauth2 v0.30.0
4140
google.golang.org/api v0.239.0
@@ -256,7 +255,6 @@ require (
256255
github.com/adeithe/go-twitch v0.3.1
257256
github.com/andreykaipov/goobs v1.4.1
258257
github.com/anthonynsimon/bild v0.14.0
259-
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
260258
github.com/asticode/go-astiav v0.36.0
261259
github.com/bamiaux/rez v0.0.0-20170731184118-29f4463c688b
262260
github.com/bluenviron/gortsplib/v4 v4.12.4-0.20250324174248-61372cfa6800
@@ -326,6 +324,8 @@ require (
326324
require (
327325
github.com/BurntSushi/xgbutil v0.0.0-20190907113008-ad855c713046
328326
github.com/cloudwego/eino-ext/components/model/openai v0.0.0-20250424061409-ccd60fbc7c1c
327+
github.com/coder/websocket v1.8.13
328+
github.com/joeyak/go-twitch-eventsub/v3 v3.0.0
329329
github.com/phuslu/goid v1.0.2 // indirect
330330
github.com/pion/datachannel v1.5.10 // indirect
331331
github.com/pion/dtls/v2 v2.2.12 // indirect

go.sum

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH
216216
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
217217
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
218218
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
219+
github.com/coder/websocket v1.8.13 h1:f3QZdXy7uGVz+4uCJy2nTZyM0yTBj8yANEHhqlXZ9FE=
220+
github.com/coder/websocket v1.8.13/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
219221
github.com/coreos/go-oidc/v3 v3.11.0 h1:Ia3MxdwpSw702YW0xgfmP1GVCMA9aEFWu12XUZ3/OtI=
220222
github.com/coreos/go-oidc/v3 v3.11.0/go.mod h1:gE3LgjOgFoHi9a4ce4/tJczr0Ai2/BoDhf0r5lltWI0=
221223
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
@@ -613,6 +615,8 @@ github.com/jfreymuth/oggvorbis v1.0.5 h1:u+Ck+R0eLSRhgq8WTmffYnrVtSztJcYrl588DM4
613615
github.com/jfreymuth/oggvorbis v1.0.5/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHixthRlBeD6uII=
614616
github.com/jfreymuth/vorbis v1.0.2 h1:m1xH6+ZI4thH927pgKD8JOH4eaGRm18rEE9/0WKjvNE=
615617
github.com/jfreymuth/vorbis v1.0.2/go.mod h1:DoftRo4AznKnShRl1GxiTFCseHr4zR9BN3TWXyuzrqQ=
618+
github.com/joeyak/go-twitch-eventsub/v3 v3.0.0 h1:6BDgmYJynNDyCP7P+wM9jPQnE3leJAi58nohDnzliJ4=
619+
github.com/joeyak/go-twitch-eventsub/v3 v3.0.0/go.mod h1:rpqOjYP1ftWDj3H4D8fA58AdOpkvK9YvODoduDpPCQU=
616620
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
617621
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
618622
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
@@ -741,8 +745,6 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
741745
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
742746
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
743747
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
744-
github.com/mysteriumnetwork/EventBus v0.0.0-20220414214953-84469ec2b111 h1:7s+VqlctjdVjy1z0slV2giUawTnv1A6vWj9oKKfgPhI=
745-
github.com/mysteriumnetwork/EventBus v0.0.0-20220414214953-84469ec2b111/go.mod h1:ef8wV5ITJhXSTG1sUkcHPAQF7lh83c7l875IvrYU7H0=
746748
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
747749
github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
748750
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
@@ -1088,6 +1090,8 @@ github.com/xaionaro-go/avpipeline v0.0.0-20250525204026-17104bc4baca h1:Cls4rEim
10881090
github.com/xaionaro-go/avpipeline v0.0.0-20250525204026-17104bc4baca/go.mod h1:LMh5Qi7cuntcktUezfA9toVCUCCsx9pjyGDWe9GLt9A=
10891091
github.com/xaionaro-go/datacounter v1.0.4 h1:+QMZLmu73R5WGkQfUPwlXF/JFN+Weo4iuDZkiL2wVm8=
10901092
github.com/xaionaro-go/datacounter v1.0.4/go.mod h1:Sf9vBevuV6w5iE6K3qJ9pWVKcyS60clWBUSQLjt5++c=
1093+
github.com/xaionaro-go/eventbus v0.0.0-20250712220612-3cb9e775fb98 h1:8Dtop2JCrZl9bRpIVPDIQWio1gXjDmcaVKjMeT8sZQ0=
1094+
github.com/xaionaro-go/eventbus v0.0.0-20250712220612-3cb9e775fb98/go.mod h1:zSbWHZpDvsRhjD3Sr3bruqqsWotjXvsIKmx6/THwXFw=
10911095
github.com/xaionaro-go/fyne/v2 v2.0.0-20250622004601-3a26ee69528a h1:awMQXlaweeiSZB4rSNfMmJGJriyn1ca/m/lglBi9uyA=
10921096
github.com/xaionaro-go/fyne/v2 v2.0.0-20250622004601-3a26ee69528a/go.mod h1:0GOXKqyvNwk3DLmsFu9v0oYM0ZcD1ysGnlHCerKoAmo=
10931097
github.com/xaionaro-go/go-rtmp v0.0.0-20241009130244-1e3160f27f42 h1:izCjREd+62HDF9FRYqUI7dgJNdUxAIysEuqed8lBcDY=

pkg/cert/generate_self_signed.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package cert
2+
3+
import (
4+
"crypto/ed25519"
5+
"crypto/rand"
6+
"crypto/tls"
7+
"crypto/x509"
8+
"crypto/x509/pkix"
9+
"encoding/pem"
10+
"math/big"
11+
"time"
12+
)
13+
14+
func GenerateSelfSignedForServer() (tls.Certificate, error) {
15+
pub, priv, err := ed25519.GenerateKey(rand.Reader)
16+
if err != nil {
17+
return tls.Certificate{}, err
18+
}
19+
20+
tmpl := x509.Certificate{
21+
SerialNumber: big.NewInt(1),
22+
Subject: pkix.Name{
23+
Organization: []string{"DX.center"},
24+
},
25+
NotBefore: time.Now(),
26+
NotAfter: time.Now().Add(10 * 365 * 24 * time.Hour),
27+
28+
KeyUsage: x509.KeyUsageDigitalSignature,
29+
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
30+
DNSNames: []string{"wingout.dx.center"},
31+
}
32+
33+
certDER, err := x509.CreateCertificate(rand.Reader, &tmpl, &tmpl, pub, priv)
34+
if err != nil {
35+
return tls.Certificate{}, err
36+
}
37+
38+
keyBytes, err := x509.MarshalPKCS8PrivateKey(priv)
39+
40+
certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certDER})
41+
keyPEM := pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes})
42+
43+
return tls.X509KeyPair(certPEM, keyPEM)
44+
}

pkg/chatmessagesstorage/load.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func (s *ChatMessagesStorage) loadLocked(ctx context.Context) (_err error) {
3333
if err != nil {
3434
return fmt.Errorf("unable to parse file '%s': %w", s.FilePath, err)
3535
}
36+
logger.Debugf(ctx, "loaded %d messages", len(s.Messages))
3637
s.sortAndDeduplicateAndTruncate(ctx)
3738
return nil
3839
}

pkg/ringbuffer/ring_buffer.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package ringbuffer
2+
3+
import (
4+
"context"
5+
"slices"
6+
7+
"github.com/xaionaro-go/xsync"
8+
)
9+
10+
type RingBuffer[T comparable] struct {
11+
Storage []T
12+
CurrentWriteIndex uint
13+
Locker xsync.Mutex
14+
}
15+
16+
func New[T comparable](size uint) *RingBuffer[T] {
17+
return &RingBuffer[T]{
18+
Storage: make([]T, 0, size),
19+
}
20+
}
21+
22+
func (r *RingBuffer[T]) Add(item T) {
23+
r.Locker.Do(context.TODO(), func() {
24+
if r.CurrentWriteIndex >= uint(len(r.Storage)) {
25+
r.Storage = r.Storage[:len(r.Storage)+1]
26+
}
27+
r.Storage[r.CurrentWriteIndex] = item
28+
r.CurrentWriteIndex++
29+
if r.CurrentWriteIndex >= uint(cap(r.Storage)) {
30+
r.CurrentWriteIndex = 0
31+
}
32+
})
33+
}
34+
35+
func (r *RingBuffer[T]) Contains(item T) bool {
36+
return xsync.DoR1(context.TODO(), &r.Locker, func() bool {
37+
return slices.Contains(r.Storage, item)
38+
})
39+
}

pkg/streamcontrol/kick/kick.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
http "github.com/Danny-Dasilva/fhttp"
1313
"github.com/davecgh/go-spew/spew"
14+
"github.com/facebookincubator/go-belt"
1415
"github.com/facebookincubator/go-belt/tool/logger"
1516
"github.com/google/uuid"
1617
"github.com/scorfly/gokick"
@@ -64,6 +65,7 @@ func New(
6465
cfg Config,
6566
saveCfgFn func(Config) error,
6667
) (*Kick, error) {
68+
ctx = belt.WithField(ctx, "controller", ID)
6769
if cfg.Config.Channel == "" {
6870
return nil, fmt.Errorf("channel is not set")
6971
}

0 commit comments

Comments
 (0)