Files
livekit/pkg/routing/node.go
Mathew Kamkar 700a879c0b Redis Router graceful stop (#116)
* prestop and hasparticipants in interface

* add prestop function to existing routers

* fakerouter prestop

* update protocol version

* read lock

* redis router graceful stop

* test fix

* force stop
2021-09-15 13:07:44 -07:00

47 lines
938 B
Go

package routing
import (
"crypto/sha1"
"fmt"
"os"
"runtime"
"time"
"github.com/jxskiss/base62"
livekit "github.com/livekit/protocol/proto"
"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()),
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)
}