ax(batch): fix abbreviated names in comment examples and locals
h→hash/histogram, e→miningError, a/b→current/previous, n→count, user/pass→username/password, passMatch→passwordMatch in comment examples and auth.go locals. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
4a7c19689a
commit
3bf5496fce
4 changed files with 15 additions and 16 deletions
|
|
@ -179,16 +179,15 @@ func (digestAuth *DigestAuth) validateDigest(c *gin.Context, authHeader string)
|
|||
// valid := digestAuth.validateBasic(c, c.GetHeader("Authorization"))
|
||||
func (digestAuth *DigestAuth) validateBasic(c *gin.Context, authHeader string) bool {
|
||||
// Gin has built-in basic auth, but we do manual validation for consistency
|
||||
user, pass, ok := c.Request.BasicAuth()
|
||||
username, password, ok := c.Request.BasicAuth()
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
// Constant-time comparison to prevent timing attacks
|
||||
userMatch := subtle.ConstantTimeCompare([]byte(user), []byte(digestAuth.config.Username)) == 1
|
||||
passMatch := subtle.ConstantTimeCompare([]byte(pass), []byte(digestAuth.config.Password)) == 1
|
||||
userMatch := subtle.ConstantTimeCompare([]byte(username), []byte(digestAuth.config.Username)) == 1
|
||||
passwordMatch := subtle.ConstantTimeCompare([]byte(password), []byte(digestAuth.config.Password)) == 1
|
||||
|
||||
return userMatch && passMatch
|
||||
return userMatch && passwordMatch
|
||||
}
|
||||
|
||||
// nonce := digestAuth.generateNonce() // 32-char hex string, cryptographically random
|
||||
|
|
@ -253,7 +252,7 @@ func parseDigestParams(header string) map[string]string {
|
|||
return params
|
||||
}
|
||||
|
||||
// h := md5Hash("user:realm:pass") // "5f4dcc3b5aa765d61d8327deb882cf99"
|
||||
// hash := md5Hash("user:realm:pass") // "5f4dcc3b5aa765d61d8327deb882cf99"
|
||||
func md5Hash(input string) string {
|
||||
digest := md5.Sum([]byte(input))
|
||||
return hex.EncodeToString(digest[:])
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ const (
|
|||
ErrCodeInternalError = "INTERNAL_ERROR"
|
||||
)
|
||||
|
||||
// e := &MiningError{Code: ErrCodeStartFailed, Message: "failed to start xmrig", HTTPStatus: 500}
|
||||
// e.WithCause(err).WithSuggestion("check logs")
|
||||
// miningError := &MiningError{Code: ErrCodeStartFailed, Message: "failed to start xmrig", HTTPStatus: 500}
|
||||
// miningError.WithCause(err).WithSuggestion("check logs")
|
||||
type MiningError struct {
|
||||
Code string // Machine-readable error code
|
||||
Message string // Human-readable message
|
||||
|
|
|
|||
|
|
@ -34,15 +34,15 @@ type Metrics struct {
|
|||
P2PConnectionsTotal atomic.Int64
|
||||
}
|
||||
|
||||
// h := mining.NewLatencyHistogram(1000)
|
||||
// h.Record(42 * time.Millisecond)
|
||||
// histogram := mining.NewLatencyHistogram(1000)
|
||||
// histogram.Record(42 * time.Millisecond)
|
||||
type LatencyHistogram struct {
|
||||
mutex sync.Mutex
|
||||
samples []time.Duration
|
||||
maxSize int
|
||||
}
|
||||
|
||||
// h := mining.NewLatencyHistogram(1000) // retain up to 1000 latency samples
|
||||
// histogram := mining.NewLatencyHistogram(1000) // retain up to 1000 latency samples
|
||||
func NewLatencyHistogram(maxSize int) *LatencyHistogram {
|
||||
return &LatencyHistogram{
|
||||
samples: make([]time.Duration, 0, maxSize),
|
||||
|
|
|
|||
|
|
@ -285,9 +285,9 @@ func (b *BaseMiner) InstallFromURL(url string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// a := parseVersion("6.24.0") // [6, 24, 0]
|
||||
// b := parseVersion("5.0.1") // [5, 0, 1]
|
||||
// if compareVersions(a, b) > 0 { /* a is newer */ }
|
||||
// current := parseVersion("6.24.0") // [6, 24, 0]
|
||||
// previous := parseVersion("5.0.1") // [5, 0, 1]
|
||||
// if compareVersions(current, previous) > 0 { /* current is newer */ }
|
||||
func parseVersion(versionString string) []int {
|
||||
parts := strings.Split(versionString, ".")
|
||||
intParts := make([]int, len(parts))
|
||||
|
|
@ -435,14 +435,14 @@ func (b *BaseMiner) AddHashratePoint(point HashratePoint) {
|
|||
b.HashrateHistory = append(b.HashrateHistory, point)
|
||||
}
|
||||
|
||||
// n := miner.GetHighResHistoryLength() // 0..30 points (last 5 min at 10s resolution)
|
||||
// count := miner.GetHighResHistoryLength() // 0..30 points (last 5 min at 10s resolution)
|
||||
func (b *BaseMiner) GetHighResHistoryLength() int {
|
||||
b.mutex.RLock()
|
||||
defer b.mutex.RUnlock()
|
||||
return len(b.HashrateHistory)
|
||||
}
|
||||
|
||||
// n := miner.GetLowResHistoryLength() // 0..1440 points (last 24h at 1min resolution)
|
||||
// count := miner.GetLowResHistoryLength() // 0..1440 points (last 24h at 1min resolution)
|
||||
func (b *BaseMiner) GetLowResHistoryLength() int {
|
||||
b.mutex.RLock()
|
||||
defer b.mutex.RUnlock()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue