mirror of
https://github.com/dalbodeule/hop-gate.git
synced 2025-12-12 06:40:11 +09:00
Fix DTLS buffer size issue by wrapping sessions with buffered readers
- Add dtlsReadBufferSize constant (8KB) matching pion/dtls limits - Wrap DTLS sessions with bufio.Reader in client and server code - Update tests to use buffered readers for datagram-based connections - All tests passing successfully Co-authored-by: dalbodeule <11470513+dalbodeule@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
@@ -34,9 +35,10 @@ import (
|
||||
var version = "dev"
|
||||
|
||||
type dtlsSessionWrapper struct {
|
||||
sess dtls.Session
|
||||
mu sync.Mutex
|
||||
nextStreamID uint64
|
||||
sess dtls.Session
|
||||
bufferedReader *bufio.Reader
|
||||
mu sync.Mutex
|
||||
nextStreamID uint64
|
||||
}
|
||||
|
||||
func getEnvOrPanic(logger logging.Logger, key string) string {
|
||||
@@ -302,7 +304,7 @@ func (w *dtlsSessionWrapper) ForwardHTTP(ctx context.Context, logger logging.Log
|
||||
|
||||
for {
|
||||
var env protocol.Envelope
|
||||
if err := codec.Decode(w.sess, &env); err != nil {
|
||||
if err := codec.Decode(w.bufferedReader, &env); err != nil {
|
||||
log.Error("failed to decode stream response envelope", logging.Fields{
|
||||
"error": err.Error(),
|
||||
})
|
||||
@@ -502,7 +504,10 @@ func registerSessionForDomain(domain string, sess dtls.Session, logger logging.L
|
||||
if d == "" {
|
||||
return
|
||||
}
|
||||
w := &dtlsSessionWrapper{sess: sess}
|
||||
w := &dtlsSessionWrapper{
|
||||
sess: sess,
|
||||
bufferedReader: bufio.NewReaderSize(sess, protocol.GetDTLSReadBufferSize()),
|
||||
}
|
||||
sessionsMu.Lock()
|
||||
sessionsByDomain[d] = w
|
||||
sessionsMu.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user