3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00

Use base 36 when generating message IDs, gives us full 0-9a-z to use while preserving uniqueness nicely

This commit is contained in:
Daniel Oaks 2018-01-04 00:21:35 +10:00
parent 63bd52d471
commit 3ba8af714e

View File

@ -397,11 +397,11 @@ func (server *Server) createListener(addr string, tlsConfig *tls.Config) *Listen
func (server *Server) generateMessageID() string {
// we don't need the full like 30 chars since the unixnano below handles
// most of our uniqueness requirements, so just truncate at 5
lastbit := strconv.FormatInt(rand.Int63(), 16)
lastbit := strconv.FormatInt(rand.Int63(), 36)
if 5 < len(lastbit) {
lastbit = lastbit[:5]
lastbit = lastbit[:4]
}
return fmt.Sprintf("%s%s", strconv.FormatInt(time.Now().UTC().UnixNano(), 16), lastbit)
return fmt.Sprintf("%s%s", strconv.FormatInt(time.Now().UTC().UnixNano(), 36), lastbit)
}
//