Skip to content

Commit cae0c4a

Browse files
committed
Update queue-manager.go
1 parent 3eaebae commit cae0c4a

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

queue-manager.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,25 @@ func (qm *QueueManager) getClientID(rw http.ResponseWriter, req *http.Request) (
228228

229229
// generateUniqueID creates a unique identifier for a client
230230
func generateUniqueID(req *http.Request) string {
231-
// Create unique ID based on current time, remote IP, and some randomness
231+
// Create unique ID based on current time, remote IP, and cryptographic randomness
232232
timestamp := time.Now().UnixNano()
233233
clientIP := getClientIP(req)
234-
return fmt.Sprintf("%d-%s-%d", timestamp, clientIP, timestamp%1000)
234+
235+
// Add randomness to ensure uniqueness
236+
randBytes := make([]byte, 8)
237+
for i := range randBytes {
238+
randBytes[i] = byte(timestamp % 256)
239+
timestamp /= 256
240+
}
241+
242+
// Create a hash from the random bytes
243+
hasher := md5.New()
244+
hasher.Write(randBytes)
245+
hasher.Write([]byte(clientIP))
246+
randHash := hex.EncodeToString(hasher.Sum(nil))[:12]
247+
248+
// Format: timestamp-ip-randomhash
249+
return fmt.Sprintf("%d-%s-%s", time.Now().UnixNano(), clientIP, randHash)
235250
}
236251

237252
// generateClientHash creates a hash from client attributes

0 commit comments

Comments
 (0)