checkpoint
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package node
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/livekit/livekit-server/proto"
|
||||
)
|
||||
|
||||
// Router selects the best node for room interactions
|
||||
type Chooser interface {
|
||||
ChooseNodeForRoom(roomId string) (*proto.Node, error)
|
||||
GetNodeForRoom(roomId string) (*proto.Node, error)
|
||||
ClearRoom(roomId string) error
|
||||
}
|
||||
|
||||
func NewSingleNodeChooser(n *Node) *SingleNodeChooser {
|
||||
return &SingleNodeChooser{
|
||||
localNode: n,
|
||||
rooms: make(map[string]bool),
|
||||
}
|
||||
}
|
||||
|
||||
type SingleNodeChooser struct {
|
||||
localNode *Node
|
||||
rooms map[string]bool
|
||||
}
|
||||
|
||||
func (c *SingleNodeChooser) ChooseNodeForRoom(roomId string) (n *proto.Node, err error) {
|
||||
if c.rooms[roomId] {
|
||||
err = fmt.Errorf("Room already exists")
|
||||
return
|
||||
}
|
||||
c.rooms[roomId] = true
|
||||
n = &c.localNode.Node
|
||||
return
|
||||
}
|
||||
|
||||
func (c *SingleNodeChooser) GetNodeForRoom(roomId string) (*proto.Node, error) {
|
||||
if !c.rooms[roomId] {
|
||||
return nil, fmt.Errorf("room %d had not been created", roomId)
|
||||
}
|
||||
return &c.localNode.Node, nil
|
||||
}
|
||||
+7
-5
@@ -3,6 +3,8 @@ package node
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/pion/stun"
|
||||
|
||||
"github.com/livekit/livekit-server/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -10,9 +12,7 @@ const (
|
||||
)
|
||||
|
||||
type Node struct {
|
||||
ID string
|
||||
IP string
|
||||
Stats NodeStats
|
||||
proto.Node
|
||||
}
|
||||
|
||||
type NodeStats struct {
|
||||
@@ -29,7 +29,9 @@ func NewLocalNode() (*Node, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &Node{
|
||||
ID: id.String(),
|
||||
proto.Node{
|
||||
Id: id.String(),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -56,7 +58,7 @@ func (n *Node) DiscoverNetworkInfo() error {
|
||||
stunErr = err
|
||||
return
|
||||
}
|
||||
n.IP = xorAddr.IP.String()
|
||||
n.Ip = xorAddr.IP.String()
|
||||
})
|
||||
|
||||
if stunErr != nil {
|
||||
|
||||
Reference in New Issue
Block a user