use hostname instead of MAC address to work with docker environments
This commit is contained in:
+6
-1
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -31,8 +32,12 @@ func NewLocalNode(conf *config.Config) (LocalNode, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
hostname, err := os.Hostname()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return &livekit.Node{
|
return &livekit.Node{
|
||||||
Id: fmt.Sprintf("%s%16.16X", utils.NodePrefix, macUint64()),
|
Id: fmt.Sprintf("%s%s", utils.NodePrefix, utils.HashedID(hostname)[:8]),
|
||||||
Ip: ip,
|
Ip: ip,
|
||||||
NumCpus: uint32(runtime.NumCPU()),
|
NumCpus: uint32(runtime.NumCPU()),
|
||||||
Stats: &livekit.NodeStats{
|
Stats: &livekit.NodeStats{
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha1"
|
||||||
|
|
||||||
"github.com/lithammer/shortuuid/v3"
|
"github.com/lithammer/shortuuid/v3"
|
||||||
|
"github.com/lytics/base62"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -15,3 +18,12 @@ const (
|
|||||||
func NewGuid(prefix string) string {
|
func NewGuid(prefix string) string {
|
||||||
return prefix + shortuuid.New()[:12]
|
return prefix + shortuuid.New()[:12]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creates a hashed ID from a unique string
|
||||||
|
func HashedID(str string) string {
|
||||||
|
h := sha1.New()
|
||||||
|
h.Write([]byte(str))
|
||||||
|
val := h.Sum(nil)
|
||||||
|
|
||||||
|
return base62.StdEncoding.EncodeToString(val)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user