Browse Source

queuedID packs the seeds (3 uint64) in to a single 192 bit number before hashing it

flashmob 5 years ago
parent
commit
b103debfb5
2 changed files with 8 additions and 5 deletions
  1. 6 3
      mail/envelope.go
  2. 2 2
      mail/envelope_test.go

+ 6 - 3
mail/envelope.go

@@ -173,9 +173,12 @@ func NewEnvelope(remoteAddr string, clientID uint64, serverID int) *Envelope {
 
 
 func queuedID(clientID uint64, serverID int) string {
 func queuedID(clientID uint64, serverID int) string {
 	h := fnv.New128a()
 	h := fnv.New128a()
-	tmp := make([]byte, 8)
-	binary.LittleEndian.PutUint64(tmp, uint64(time.Now().UnixNano())+clientID+uint64(serverID))
-	h.Write(tmp)
+	var n [24]byte
+	// pack the seeds and hash them
+	binary.BigEndian.PutUint64(n[0:8], uint64(time.Now().UnixNano()))
+	binary.BigEndian.PutUint64(n[8:16], clientID)
+	binary.BigEndian.PutUint64(n[16:24], uint64(serverID))
+	h.Write(n[:])
 	return fmt.Sprintf("%x", h.Sum([]byte{}))
 	return fmt.Sprintf("%x", h.Sum([]byte{}))
 }
 }
 
 

+ 2 - 2
mail/envelope_test.go

@@ -162,11 +162,11 @@ func TestEncodedWordAhead(t *testing.T) {
 }
 }
 
 
 func TestQueuedID(t *testing.T) {
 func TestQueuedID(t *testing.T) {
-	str := queuedID(555, 1)
+	str := queuedID(5550000000, 1)
 	if len(str) != 32 {
 	if len(str) != 32 {
 		t.Error("queuedID needs to be 32 bytes in length")
 		t.Error("queuedID needs to be 32 bytes in length")
 	}
 	}
-	str2 := queuedID(555, 1)
+	str2 := queuedID(5550000000, 1)
 	if str == str2 {
 	if str == str2 {
 		t.Error("hashes should not be equal")
 		t.Error("hashes should not be equal")
 	}
 	}