Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shwap/shrex): enable recovery middleware in shrex server #3897

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions share/shwap/p2p/shrex/shrexeds/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ type Server struct {

store *store.Store

params *Parameters
params *Parameters
// TODO: decouple middleware metrics from shrex and remove middleware from Server
middleware *shrex.Middleware
metrics *shrex.Metrics
}
Expand All @@ -55,7 +56,10 @@ func (s *Server) Start(context.Context) error {
ctx, cancel := context.WithCancel(context.Background())
s.cancel = cancel

s.host.SetStreamHandler(s.protocolID, s.middleware.RateLimitHandler(s.streamHandler(ctx)))
handler := s.streamHandler(ctx)
withRateLimit := s.middleware.RateLimitHandler(handler)
withRecovery := shrex.RecoveryMiddleware(withRateLimit)
s.host.SetStreamHandler(s.protocolID, withRecovery)
return nil
}

Expand Down
8 changes: 6 additions & 2 deletions share/shwap/p2p/shrex/shrexnd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ type Server struct {
handler network.StreamHandler
store *store.Store

params *Parameters
params *Parameters
// TODO: decouple middleware metrics from shrex and remove middleware from Server
middleware *shrex.Middleware
metrics *shrex.Metrics
}
Expand All @@ -54,7 +55,10 @@ func NewServer(params *Parameters, host host.Host, store *store.Store) (*Server,
ctx, cancel := context.WithCancel(context.Background())
srv.cancel = cancel

srv.handler = srv.middleware.RateLimitHandler(srv.streamHandler(ctx))
handler := srv.streamHandler(ctx)
withRateLimit := srv.middleware.RateLimitHandler(handler)
withRecovery := shrex.RecoveryMiddleware(withRateLimit)
srv.handler = withRecovery
return srv, nil
}

Expand Down