mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-27 20:36:29 -04:00
Append UNIX timestamp to device ID to guarantee uniqueness
This commit is contained in:
+4
-1
@@ -5,15 +5,18 @@ import (
|
||||
"github.com/rwinkhart/MUTN/src/backend"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DeviceIDGen generates a new client device ID and registers it with the server
|
||||
// device IDs are only needed for online synchronization
|
||||
// device IDs are guaranteed unique as the current UNIX time is appended to them
|
||||
// returns the remote EntryRoot and OS type (OS type is a bool: backend.IsWindows)
|
||||
func DeviceIDGen() (string, string) {
|
||||
deviceIDPrefix, _ := os.Hostname()
|
||||
deviceIDSuffix := backend.StringGen(rand.Intn(48)+48, false, 0) // TODO consider using complex string generator and removing unsafe characters manually
|
||||
deviceIDSuffix := backend.StringGen(rand.Intn(32)+48, false, 0) + "-" + strconv.FormatInt(time.Now().Unix(), 10) // TODO consider using complex string generator and removing unsafe characters manually
|
||||
deviceID := deviceIDPrefix + "-" + deviceIDSuffix
|
||||
_, err := os.Create(backend.ConfigDir + backend.PathSeparator + "devices" + backend.PathSeparator + deviceID) // TODO remove existing device ID file if it exists (from both client and server)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user