1752b29df9
Implement UDP tunneling over HTTP/3 using HTTP Datagrams (RFC 9297): - Add masque handler for server-side CONNECT-UDP - Add masque connector and h3-masque dialer for client-side - Add enableDatagrams option to HTTP/3 listener - Add shared utilities for datagram connections and path parsing Resource management and connection caching: - Add deferred stream cleanup in connector on error paths - Add IsClosed() and Close() methods to Client for proper session management - Clean up stale cached clients in dialer before reuse - Close underlying stream when DatagramConn is closed - Move RequestStream opening from connector to dialer to enable dead connection detection and cache invalidation (follows QUIC dialer pattern)
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package masque
|
|
|
|
import (
|
|
"time"
|
|
|
|
mdata "github.com/go-gost/core/metadata"
|
|
mdutil "github.com/go-gost/x/metadata/util"
|
|
)
|
|
|
|
const (
|
|
defaultBufferSize = 4096
|
|
defaultRealm = "gost"
|
|
)
|
|
|
|
type metadata struct {
|
|
hash string
|
|
bufferSize int
|
|
authBasicRealm string
|
|
|
|
observerPeriod time.Duration
|
|
observerResetTraffic bool
|
|
limiterRefreshInterval time.Duration
|
|
limiterCleanupInterval time.Duration
|
|
}
|
|
|
|
func (h *masqueHandler) parseMetadata(md mdata.Metadata) (err error) {
|
|
h.md.hash = mdutil.GetString(md, "hash")
|
|
|
|
h.md.bufferSize = mdutil.GetInt(md, "bufferSize", "udp.bufferSize")
|
|
if h.md.bufferSize <= 0 {
|
|
h.md.bufferSize = defaultBufferSize
|
|
}
|
|
|
|
h.md.authBasicRealm = mdutil.GetString(md, "authBasicRealm")
|
|
|
|
h.md.observerPeriod = mdutil.GetDuration(md, "observePeriod", "observer.period", "observer.observePeriod")
|
|
if h.md.observerPeriod == 0 {
|
|
h.md.observerPeriod = 5 * time.Second
|
|
}
|
|
if h.md.observerPeriod < time.Second {
|
|
h.md.observerPeriod = time.Second
|
|
}
|
|
|
|
h.md.observerResetTraffic = mdutil.GetBool(md, "observer.resetTraffic")
|
|
h.md.limiterRefreshInterval = mdutil.GetDuration(md, "limiter.refreshInterval")
|
|
h.md.limiterCleanupInterval = mdutil.GetDuration(md, "limiter.cleanupInterval")
|
|
|
|
return nil
|
|
}
|