Skip to content

Commit

Permalink
Don't fail on unknown session
Browse files Browse the repository at this point in the history
There may be a race condition if a user disconnects and the other peer
just sent a p2p message.

Fixes #14
  • Loading branch information
jmattheis committed Oct 23, 2020
1 parent 6365bf6 commit 3191988
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
11 changes: 8 additions & 3 deletions ws/event_clientanswer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ws

import (
"fmt"

"github.com/rs/zerolog/log"
"github.com/screego/server/ws/outgoing"
)

Expand All @@ -26,8 +26,13 @@ func (e *ClientAnswer) Execute(rooms *Rooms, current ClientInfo) error {

session, ok := room.Sessions[e.SID]

if !ok || session.Client != current.ID {
return fmt.Errorf("session with id %s does not exist", current.RoomID)
if !ok {
log.Debug().Str("id", e.SID.String()).Msg("unknown session")
return nil
}

if session.Client != current.ID {
return fmt.Errorf("permission denied for session %s", e.SID)
}

room.Users[session.Host].Write <- outgoing.ClientAnswer(*e)
Expand Down
11 changes: 8 additions & 3 deletions ws/event_clientice.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ws

import (
"fmt"

"github.com/rs/zerolog/log"
"github.com/screego/server/ws/outgoing"
)

Expand All @@ -26,8 +26,13 @@ func (e *ClientICE) Execute(rooms *Rooms, current ClientInfo) error {

session, ok := room.Sessions[e.SID]

if !ok || session.Client != current.ID {
return fmt.Errorf("session with id %s does not exist", current.RoomID)
if !ok {
log.Debug().Str("id", e.SID.String()).Msg("unknown session")
return nil
}

if session.Client != current.ID {
return fmt.Errorf("permission denied for session %s", e.SID)
}

room.Users[session.Host].Write <- outgoing.ClientICE(*e)
Expand Down
11 changes: 8 additions & 3 deletions ws/event_hostice.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ws

import (
"fmt"

"github.com/rs/zerolog/log"
"github.com/screego/server/ws/outgoing"
)

Expand All @@ -26,8 +26,13 @@ func (e *HostICE) Execute(rooms *Rooms, current ClientInfo) error {

session, ok := room.Sessions[e.SID]

if !ok || session.Host != current.ID {
return fmt.Errorf("session with id %s does not exist", current.RoomID)
if !ok {
log.Debug().Str("id", e.SID.String()).Msg("unknown session")
return nil
}

if session.Host != current.ID {
return fmt.Errorf("permission denied for session %s", e.SID)
}

room.Users[session.Client].Write <- outgoing.HostICE(*e)
Expand Down
11 changes: 8 additions & 3 deletions ws/event_hostoffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ws

import (
"fmt"

"github.com/rs/zerolog/log"
"github.com/screego/server/ws/outgoing"
)

Expand All @@ -26,8 +26,13 @@ func (e *HostOffer) Execute(rooms *Rooms, current ClientInfo) error {

session, ok := room.Sessions[e.SID]

if !ok || session.Host != current.ID {
return fmt.Errorf("session with id %s does not exist", current.RoomID)
if !ok {
log.Debug().Str("id", e.SID.String()).Msg("unknown session")
return nil
}

if session.Host != current.ID {
return fmt.Errorf("permission denied for session %s", e.SID)
}

room.Users[session.Client].Write <- outgoing.HostOffer(*e)
Expand Down

0 comments on commit 3191988

Please sign in to comment.