feat: ignoreClientBandwidth

This commit is contained in:
Toby
2023-08-07 16:34:35 -07:00
parent f95a31120d
commit cc0d0181e1
8 changed files with 156 additions and 84 deletions

View File

@@ -17,26 +17,52 @@ const (
StatusAuthOK = 233
)
func AuthRequestDataFromHeader(h http.Header) (auth string, rx uint64) {
auth = h.Get(RequestHeaderAuth)
rx, _ = strconv.ParseUint(h.Get(CommonHeaderCCRX), 10, 64)
return
// AuthRequest is what client sends to server for authentication.
type AuthRequest struct {
Auth string
Rx uint64 // 0 = unknown, client asks server to use bandwidth detection
}
func AuthRequestDataToHeader(h http.Header, auth string, rx uint64) {
h.Set(RequestHeaderAuth, auth)
h.Set(CommonHeaderCCRX, strconv.FormatUint(rx, 10))
// AuthResponse is what server sends to client when authentication is passed.
type AuthResponse struct {
UDPEnabled bool
Rx uint64 // 0 = unlimited
RxAuto bool // true = server asks client to use bandwidth detection
}
func AuthRequestFromHeader(h http.Header) AuthRequest {
rx, _ := strconv.ParseUint(h.Get(CommonHeaderCCRX), 10, 64)
return AuthRequest{
Auth: h.Get(RequestHeaderAuth),
Rx: rx,
}
}
func AuthRequestToHeader(h http.Header, req AuthRequest) {
h.Set(RequestHeaderAuth, req.Auth)
h.Set(CommonHeaderCCRX, strconv.FormatUint(req.Rx, 10))
h.Set(CommonHeaderPadding, authRequestPadding.String())
}
func AuthResponseDataFromHeader(h http.Header) (udp bool, rx uint64) {
udp, _ = strconv.ParseBool(h.Get(ResponseHeaderUDPEnabled))
rx, _ = strconv.ParseUint(h.Get(CommonHeaderCCRX), 10, 64)
return
func AuthResponseFromHeader(h http.Header) AuthResponse {
resp := AuthResponse{}
resp.UDPEnabled, _ = strconv.ParseBool(h.Get(ResponseHeaderUDPEnabled))
rxStr := h.Get(CommonHeaderCCRX)
if rxStr == "auto" {
// Special case for server requesting client to use bandwidth detection
resp.RxAuto = true
} else {
resp.Rx, _ = strconv.ParseUint(rxStr, 10, 64)
}
return resp
}
func AuthResponseDataToHeader(h http.Header, udp bool, rx uint64) {
h.Set(ResponseHeaderUDPEnabled, strconv.FormatBool(udp))
h.Set(CommonHeaderCCRX, strconv.FormatUint(rx, 10))
func AuthResponseToHeader(h http.Header, resp AuthResponse) {
h.Set(ResponseHeaderUDPEnabled, strconv.FormatBool(resp.UDPEnabled))
if resp.RxAuto {
h.Set(CommonHeaderCCRX, "auto")
} else {
h.Set(CommonHeaderCCRX, strconv.FormatUint(resp.Rx, 10))
}
h.Set(CommonHeaderPadding, authResponsePadding.String())
}