Files
livekit/pkg/routing/node.go
T
David Zhao 2d93ccd668 Updated protocol from protocol/proto -> protocol/livekit (#242)
* Updated protocol from protocol/proto -> protocol/livekit

* separate MediaTrack from PublishedTrack
2021-12-08 13:58:38 -08:00

48 lines
964 B
Go

package routing
import (
"crypto/sha1"
"fmt"
"os"
"runtime"
"time"
"github.com/jxskiss/base62"
livekit "github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/utils"
"github.com/livekit/livekit-server/pkg/config"
)
type LocalNode *livekit.Node
func NewLocalNode(conf *config.Config) (LocalNode, error) {
hostname, err := os.Hostname()
if err != nil {
return nil, err
}
if conf.RTC.NodeIP == "" {
return nil, ErrIPNotSet
}
return &livekit.Node{
Id: fmt.Sprintf("%s%s", utils.NodePrefix, HashedID(hostname)[:8]),
Ip: conf.RTC.NodeIP,
NumCpus: uint32(runtime.NumCPU()),
Region: conf.Region,
State: livekit.NodeState_SERVING,
Stats: &livekit.NodeStats{
StartedAt: time.Now().Unix(),
UpdatedAt: time.Now().Unix(),
},
}, nil
}
// Creates a hashed ID from a unique string
func HashedID(id string) string {
h := sha1.New()
h.Write([]byte(id))
val := h.Sum(nil)
return base62.EncodeToString(val)
}