Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ import (
"time"
)

var lastMessageId int64

// GenerateMessageId отдает по сути unix timestamp но ужасно специфическим образом
// TODO: нахуя нужно битовое и на -4??
func GenerateMessageId() int64 {
func GenerateMessageId() (r int64) {
const billion = 1000 * 1000 * 1000
unixnano := time.Now().UnixNano()
seconds := unixnano / billion
nanoseconds := unixnano % billion
return (seconds << 32) | (nanoseconds & -4)
r = (seconds << 32) | (nanoseconds & -4)
if r == lastMessageId {
r += 4
}
lastMessageId = r
return r
}

func AuthKeyHash(key []byte) []byte {
Expand Down