Fix node IP discovery, force to ipv4

This commit is contained in:
David Zhao
2020-12-05 23:36:45 -08:00
parent 2b9fee45c4
commit d4f30c126f
3 changed files with 45 additions and 14 deletions
+14 -3
View File
@@ -24,13 +24,24 @@ To run a peer publishing to a room, do the following:
2. Create a room
```
./bin/livekit-cli create-room --room-id hello
./bin/livekit-cli create-room
```
It'll print out something like this. note the room id
```json
{
"sid": "RM_CkjigXb6oZQyZ4JNFZqBen",
"node_ip": "98.35.19.21",
"creation_time": 1607240104,
"token": "b9e8c9f6-fbb3-46d5-b6fc-5517186510a6"
}
```
3. Join room as publishing client
```
./ bin/livekit-cli join --room-id hello --audio <path/to/ogg> --video <path/to/ivf>
./ bin/livekit-cli join --audio <path/to/ogg> --video <path/to/ivf> --room-id <room_sid>
```
That's it, join the room with another peer id and see it receiving those tracks
@@ -48,7 +59,7 @@ see `rtc.proto` for the message structure.
The flow for interaction is:
1. Establish WebSocket to ws://<host>:<port>/rtc
1. Server will send back a `SignalResponse` with a `join` response. It'll include the new participant's details (and in the future, room info)
1. Server will send back a `SignalResponse` with a `join` response. It'll include the new participant's details, and what other participants are in the room
1. Client sends a `SignalRequest` with an WebRTC `offer`
1. Server will send back a `SignalResponse` with an `answer`
1. Client and server will exchange ice candidates via `trickle` in the request & responses
+1 -1
View File
@@ -26,7 +26,7 @@ var (
)
func PrintJSON(obj interface{}) {
txt, _ := json.Marshal(obj)
txt, _ := json.MarshalIndent(obj, "", " ")
fmt.Println(string(txt))
}
+30 -10
View File
@@ -1,18 +1,19 @@
package node
import (
"errors"
"context"
"fmt"
"time"
"github.com/google/wire"
"github.com/pion/stun"
"github.com/pkg/errors"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/utils"
"github.com/livekit/livekit-server/proto/livekit"
)
const ()
var NodeSet = wire.NewSet(NewLocalNode)
type Node struct {
@@ -46,7 +47,7 @@ func (n *Node) DiscoverNetworkInfo() error {
if len(n.config.RTC.StunServers) == 0 {
return errors.New("STUN servers are required but not defined")
}
c, err := stun.Dial("udp", n.config.RTC.StunServers[0])
c, err := stun.Dial("udp4", n.config.RTC.StunServers[0])
if err != nil {
return err
}
@@ -58,7 +59,7 @@ func (n *Node) DiscoverNetworkInfo() error {
}
var stunErr error
err = c.Do(message, func(res stun.Event) {
err = c.Start(message, func(res stun.Event) {
if res.Error != nil {
stunErr = res.Error
return
@@ -69,11 +70,30 @@ func (n *Node) DiscoverNetworkInfo() error {
stunErr = err
return
}
n.Ip = xorAddr.IP.String()
ip := xorAddr.IP.To4()
if ip != nil {
n.Ip = ip.String()
}
})
if stunErr != nil {
err = stunErr
if err != nil {
return err
}
return err
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
for n.Ip == "" {
select {
case <-ctx.Done():
msg := "could not determine public IP"
if stunErr != nil {
return errors.Wrap(stunErr, msg)
} else {
return fmt.Errorf(msg)
}
case <-time.After(100 * time.Millisecond):
continue
}
}
return nil
}