mirror of
https://github.com/dalbodeule/hop-gate.git
synced 2025-12-09 13:25:44 +09:00
[feat](protocol): redesign application protocol with stream-based DTLS tunneling
- Replaced single-envelope JSON model with a stream/frame-based protocol using `StreamOpen`, `StreamData`, and `StreamClose` for chunked transmission. - Added application-level ARQ with selective retransmission (`StreamAck`) for reliability over DTLS/UDP. - Defined MTU-safe chunk sizes and sequence-based flow control to handle large HTTP bodies effectively. - Updated `internal/protocol` for structured stream message handling, including ACK/NACK support. - Documented potential transition to binary serialization for performance optimization.
This commit is contained in:
@@ -41,10 +41,17 @@ const (
|
||||
MessageTypeStreamOpen MessageType = "stream_open"
|
||||
|
||||
// MessageTypeStreamData 는 열린 스트림에 대한 양방향 데이터 프레임을 의미합니다.
|
||||
// HTTP 바디 chunk 를 비롯한 실제 payload 는 이 타입을 통해 전송됩니다.
|
||||
// Stream data frames for an already-opened stream (HTTP body chunks, etc.).
|
||||
MessageTypeStreamData MessageType = "stream_data"
|
||||
|
||||
// MessageTypeStreamClose 는 스트림 종료(정상/에러)를 의미합니다.
|
||||
// Normal or error-termination of a stream.
|
||||
MessageTypeStreamClose MessageType = "stream_close"
|
||||
|
||||
// MessageTypeStreamAck 는 스트림 데이터 프레임에 대한 ACK/NACK 및 재전송 힌트를 전달합니다.
|
||||
// Stream-level ACK/NACK frames for selective retransmission hints.
|
||||
MessageTypeStreamAck MessageType = "stream_ack"
|
||||
)
|
||||
|
||||
// Envelope 는 DTLS 세션 위에서 교환되는 상위 레벨 메시지 컨테이너입니다.
|
||||
@@ -60,6 +67,10 @@ type Envelope struct {
|
||||
StreamOpen *StreamOpen `json:"stream_open,omitempty"`
|
||||
StreamData *StreamData `json:"stream_data,omitempty"`
|
||||
StreamClose *StreamClose `json:"stream_close,omitempty"`
|
||||
|
||||
// 스트림 제어 메시지 (ACK/NACK, 재전송 힌트 등)
|
||||
// Stream-level control messages (ACK/NACK, retransmission hints, etc.).
|
||||
StreamAck *StreamAck `json:"stream_ack,omitempty"`
|
||||
}
|
||||
|
||||
// StreamID 는 스트림(예: 특정 WebSocket 연결 또는 TCP 커넥션)을 구분하기 위한 식별자입니다.
|
||||
@@ -77,11 +88,44 @@ type StreamOpen struct {
|
||||
}
|
||||
|
||||
// StreamData 는 이미 열린 스트림에 대해 한 방향으로 전송되는 데이터 프레임을 표현합니다.
|
||||
// DTLS/UDP 특성상 손실/중복/순서 뒤바뀜을 감지하고 재전송할 수 있도록
|
||||
// 각 스트림 내에서 0부터 시작하는 시퀀스 번호(Seq)를 포함합니다.
|
||||
//
|
||||
// StreamData represents a unidirectional data frame on an already-opened stream.
|
||||
// To support loss/duplication/reordering detection and retransmission over DTLS/UDP,
|
||||
// it carries a per-stream sequence number (Seq) starting from 0.
|
||||
type StreamData struct {
|
||||
ID StreamID `json:"id"`
|
||||
Seq uint64 `json:"seq"`
|
||||
Data []byte `json:"data"`
|
||||
}
|
||||
|
||||
// StreamAck 는 스트림 데이터 프레임에 대한 ACK/NACK 및 선택적 재전송 요청 정보를 전달합니다.
|
||||
// AckSeq 는 수신 측에서 "연속적으로" 수신 완료한 마지막 Seq 를 의미하며,
|
||||
// LostSeqs 는 그 이후 구간에서 누락된 시퀀스 번호(선택적)를 나타냅니다.
|
||||
//
|
||||
// StreamAck conveys ACK/NACK and optional retransmission hints for stream data frames.
|
||||
// AckSeq denotes the last sequence number received contiguously by the receiver,
|
||||
// while LostSeqs can list additional missing sequence numbers beyond AckSeq.
|
||||
type StreamAck struct {
|
||||
ID StreamID `json:"id"`
|
||||
|
||||
// AckSeq 는 수신 측에서 0부터 시작해 연속으로 수신 완료한 마지막 Seq 입니다.
|
||||
// AckSeq is the last contiguously received sequence number starting from 0.
|
||||
AckSeq uint64 `json:"ack_seq"`
|
||||
|
||||
// LostSeqs 는 AckSeq 이후 구간에서 누락된 시퀀스 번호 목록입니다(선택).
|
||||
// 이 필드는 선택적 selective retransmission 힌트를 제공하기 위해 사용됩니다.
|
||||
//
|
||||
// LostSeqs is an optional list of missing sequence numbers beyond AckSeq,
|
||||
// used as a hint for selective retransmission.
|
||||
LostSeqs []uint64 `json:"lost_seqs,omitempty"`
|
||||
|
||||
// WindowSize 는 수신 측이 허용 가능한 in-flight 프레임 수를 나타내는 선택적 힌트입니다.
|
||||
// WindowSize is an optional hint for the allowed number of in-flight frames.
|
||||
WindowSize uint32 `json:"window_size,omitempty"`
|
||||
}
|
||||
|
||||
// StreamClose 는 스트림 종료를 알리는 메시지입니다.
|
||||
type StreamClose struct {
|
||||
ID StreamID `json:"id"`
|
||||
|
||||
Reference in New Issue
Block a user