mirror of
https://github.com/livekit/livekit.git
synced 2026-08-29 09:49:24 +00:00
redis based router & roomstore
This commit is contained in:
+33
-1
@@ -1,8 +1,10 @@
|
||||
package routing
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
@@ -30,7 +32,7 @@ func NewLocalNode(conf *config.Config) (LocalNode, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &livekit.Node{
|
||||
Id: utils.NewGuid(utils.NodePrefix),
|
||||
Id: fmt.Sprintf("%s%16.16X", utils.NodePrefix, macUint64()),
|
||||
Ip: ip,
|
||||
NumCpus: uint32(runtime.NumCPU()),
|
||||
}, nil
|
||||
@@ -91,3 +93,33 @@ func GetLocalIP(stunServers []string) (string, error) {
|
||||
|
||||
return nodeIp, nil
|
||||
}
|
||||
|
||||
func macUint64() uint64 {
|
||||
interfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
for _, i := range interfaces {
|
||||
if i.Flags&net.FlagUp != 0 && bytes.Compare(i.HardwareAddr, nil) != 0 {
|
||||
|
||||
// Skip locally administered addresses
|
||||
if i.HardwareAddr[0]&2 == 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
var mac uint64
|
||||
for j, b := range i.HardwareAddr {
|
||||
if j >= 8 {
|
||||
break
|
||||
}
|
||||
mac <<= 8
|
||||
mac += uint64(b)
|
||||
}
|
||||
|
||||
return mac
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user