From 319198880190dfebb1581694073fb04bbf8b5b56 Mon Sep 17 00:00:00 2001 From: Jannis Mattheis Date: Fri, 23 Oct 2020 19:38:47 +0200 Subject: [PATCH] Don't fail on unknown session There may be a race condition if a user disconnects and the other peer just sent a p2p message. Fixes #14 --- ws/event_clientanswer.go | 11 ++++++++--- ws/event_clientice.go | 11 ++++++++--- ws/event_hostice.go | 11 ++++++++--- ws/event_hostoffer.go | 11 ++++++++--- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/ws/event_clientanswer.go b/ws/event_clientanswer.go index 4ac06923..52b727fe 100644 --- a/ws/event_clientanswer.go +++ b/ws/event_clientanswer.go @@ -2,7 +2,7 @@ package ws import ( "fmt" - + "github.com/rs/zerolog/log" "github.com/screego/server/ws/outgoing" ) @@ -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) diff --git a/ws/event_clientice.go b/ws/event_clientice.go index 45bf0b4e..29a4edd8 100644 --- a/ws/event_clientice.go +++ b/ws/event_clientice.go @@ -2,7 +2,7 @@ package ws import ( "fmt" - + "github.com/rs/zerolog/log" "github.com/screego/server/ws/outgoing" ) @@ -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) diff --git a/ws/event_hostice.go b/ws/event_hostice.go index 1f21a0e4..67d748bc 100644 --- a/ws/event_hostice.go +++ b/ws/event_hostice.go @@ -2,7 +2,7 @@ package ws import ( "fmt" - + "github.com/rs/zerolog/log" "github.com/screego/server/ws/outgoing" ) @@ -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) diff --git a/ws/event_hostoffer.go b/ws/event_hostoffer.go index dae32814..ad102673 100644 --- a/ws/event_hostoffer.go +++ b/ws/event_hostoffer.go @@ -2,7 +2,7 @@ package ws import ( "fmt" - + "github.com/rs/zerolog/log" "github.com/screego/server/ws/outgoing" ) @@ -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)