Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/outbond ip #28

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/engine.example.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[engine]
# the network interface to bind
interface = "eth0"
# the network interface to bind, e.g.: 'eth0'
interface = ""
# the IP address to bind, empty allows the engine to get it from interface
address = ""
log-level = 10
Expand Down
23 changes: 18 additions & 5 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ func (engine *Engine) Loop() {
}
}

func getIPFromInterface(iname string, addr string) (string, error) {
if addr != "" {
return addr, nil
}

func getSpecificIPFromInterface(iname string) (string, error) {
ifaces, err := net.Interfaces()
if err != nil {
return "", err
Expand All @@ -112,6 +108,23 @@ func getIPFromInterface(iname string, addr string) (string, error) {
return "", fmt.Errorf("no address for interface %s", iname)
}

func getIPFromInterface(iname string, addr string) (string, error) {
if addr != "" {
return addr, nil
}
if iname != "" {
return getSpecificIPFromInterface(iname)
}

conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
return "", err
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP.String(), nil
}

type pmap struct {
sync.RWMutex
id string
Expand Down
5 changes: 1 addition & 4 deletions engine/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ type Peer struct {
}

func BuildPeer(rid, uid string, pc *webrtc.PeerConnection, callback string) *Peer {
cid, err := uuid.NewV4()
if err != nil {
panic(err)
}
cid := uuid.Must(uuid.NewV4())
peer := &Peer{rid: rid, uid: uid, cid: cid.String(), pc: pc}
peer.callback = callback
peer.connected = make(chan bool, 1)
Expand Down
3 changes: 1 addition & 2 deletions engine/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ func (r *Router) subscribe(rid, uid, cid string) (*webrtc.SessionDescription, er
ec <- buildError(ErrorServerSetLocalOffer, err)
return
}
c := <-gatherComplete
gc <- c
gc <- (<-gatherComplete)
}()

select {
Expand Down