Skip to content

Commit

Permalink
webtransport message size limit
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Oct 30, 2024
1 parent 5f2b890 commit d1e0ed6
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/FZambia/eagle v0.1.0
github.com/FZambia/statik v0.1.2-0.20180217151304-b9f012bb2a1b
github.com/centrifugal/centrifuge v0.33.5-0.20241026095149-106d43f21426
github.com/centrifugal/protocol v0.13.4
github.com/centrifugal/protocol v0.13.5-0.20241030063749-f2e17f373602
github.com/cristalhq/jwt/v5 v5.4.0
github.com/go-viper/mapstructure/v2 v2.1.0
github.com/gobwas/glob v0.2.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/centrifugal/centrifuge v0.33.5-0.20241026095149-106d43f21426 h1:g5zZaCr/BybYgq8Nqrnrvqvb3jGGO/Dloil3cFGzzbg=
github.com/centrifugal/centrifuge v0.33.5-0.20241026095149-106d43f21426/go.mod h1:Ck+7H3eVwoeyabKcj3L55oSunaORIOGPAIVB5xrQyGU=
github.com/centrifugal/protocol v0.13.4 h1:I0YxXtFNfn/ndDIZp5RkkqQcSSNH7DNPUbXKYtJXDzs=
github.com/centrifugal/protocol v0.13.4/go.mod h1:7V5vI30VcoxJe4UD87xi7bOsvI0bmEhvbQuMjrFM2L4=
github.com/centrifugal/protocol v0.13.5-0.20241030063749-f2e17f373602 h1:GdltAOXAFqR9i/q/DWbGzWFXv6x5ff/oPgZFuwlIZFQ=
github.com/centrifugal/protocol v0.13.5-0.20241030063749-f2e17f373602/go.mod h1:7V5vI30VcoxJe4UD87xi7bOsvI0bmEhvbQuMjrFM2L4=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
Expand Down
1 change: 0 additions & 1 deletion internal/api/const.go

This file was deleted.

5 changes: 3 additions & 2 deletions internal/configtypes/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ type HTTPStream struct {
}

type WebTransport struct {
Enabled bool `mapstructure:"enabled" json:"enabled" envconfig:"enabled" yaml:"enabled" toml:"enabled"`
HandlerPrefix string `mapstructure:"handler_prefix" json:"handler_prefix" envconfig:"handler_prefix" default:"/connection/webtransport" yaml:"handler_prefix" toml:"handler_prefix"`
Enabled bool `mapstructure:"enabled" json:"enabled" envconfig:"enabled" yaml:"enabled" toml:"enabled"`
HandlerPrefix string `mapstructure:"handler_prefix" json:"handler_prefix" envconfig:"handler_prefix" default:"/connection/webtransport" yaml:"handler_prefix" toml:"handler_prefix"`
MessageSizeLimit int `mapstructure:"message_size_limit" json:"message_size_limit" envconfig:"message_size_limit" default:"65536" yaml:"message_size_limit" toml:"message_size_limit"`
}

type UniWebSocket struct {
Expand Down
7 changes: 5 additions & 2 deletions internal/wt/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,17 @@ func (s *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {

var decoder protocol.StreamCommandDecoder
if protoType == centrifuge.ProtocolTypeJSON {
decoder = protocol.NewJSONStreamCommandDecoder(stream)
decoder = protocol.GetStreamCommandDecoder(protocol.TypeJSON, stream, s.config.MessageSizeLimit)
defer protocol.PutStreamCommandDecoder(protocol.TypeJSON, decoder)
} else {
decoder = protocol.NewProtobufStreamCommandDecoder(stream)
decoder = protocol.NewProtobufStreamCommandDecoder(stream, s.config.MessageSizeLimit)
defer protocol.PutStreamCommandDecoder(protocol.TypeProtobuf, decoder)
}

for {
cmd, cmdSize, err := decoder.Decode()
if err != nil {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelError, "error decoding command", map[string]any{"client": c.ID(), "transport": transportName, "error": err.Error()}))
return
}
ok := c.HandleCommand(cmd, cmdSize)
Expand Down

0 comments on commit d1e0ed6

Please sign in to comment.