3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

Make message IDs much shorter (thanks @prawnsalad!)

This commit is contained in:
Daniel Oaks 2018-01-04 00:13:32 +10:00
parent 713fc59691
commit 63bd52d471

View File

@ -395,7 +395,13 @@ func (server *Server) createListener(addr string, tlsConfig *tls.Config) *Listen
// generateMessageID returns a network-unique message ID. // generateMessageID returns a network-unique message ID.
func (server *Server) generateMessageID() string { func (server *Server) generateMessageID() string {
return fmt.Sprintf("%s-%s", strconv.FormatInt(time.Now().UTC().UnixNano(), 10), strconv.FormatInt(rand.Int63(), 10)) // 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)
if 5 < len(lastbit) {
lastbit = lastbit[:5]
}
return fmt.Sprintf("%s%s", strconv.FormatInt(time.Now().UTC().UnixNano(), 16), lastbit)
} }
// //