Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sfu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alain Takoudjou
sfu
Commits
7126394e
Commit
7126394e
authored
Sep 13, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix locking in group.go.
Also export some fields as thread-safe methods.
parent
938d231b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
29 deletions
+61
-29
group.go
group.go
+54
-14
webclient.go
webclient.go
+5
-13
webserver.go
webserver.go
+2
-2
No files found.
group.go
View file @
7126394e
...
@@ -13,7 +13,6 @@ import (
...
@@ -13,7 +13,6 @@ import (
"sort"
"sort"
"strings"
"strings"
"sync"
"sync"
"sync/atomic"
"time"
"time"
"github.com/pion/webrtc/v3"
"github.com/pion/webrtc/v3"
...
@@ -32,15 +31,46 @@ const (
...
@@ -32,15 +31,46 @@ const (
type
group
struct
{
type
group
struct
{
name
string
name
string
dead
bool
description
*
groupDescription
locked
uint32
mu
sync
.
Mutex
mu
sync
.
Mutex
description
*
groupDescription
// indicates that the group no longer exists, but it still has clients
dead
bool
locked
bool
clients
map
[
string
]
client
clients
map
[
string
]
client
history
[]
chatHistoryEntry
history
[]
chatHistoryEntry
}
}
func
(
g
*
group
)
Locked
()
bool
{
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
return
g
.
locked
}
func
(
g
*
group
)
SetLocked
(
locked
bool
)
{
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
g
.
locked
=
locked
}
func
(
g
*
group
)
Public
()
bool
{
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
return
g
.
description
.
Public
}
func
(
g
*
group
)
Redirect
()
string
{
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
return
g
.
description
.
Redirect
}
func
(
g
*
group
)
AllowRecording
()
bool
{
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
return
g
.
description
.
AllowRecording
}
var
groups
struct
{
var
groups
struct
{
mu
sync
.
Mutex
mu
sync
.
Mutex
groups
map
[
string
]
*
group
groups
map
[
string
]
*
group
...
@@ -94,9 +124,19 @@ func addGroup(name string, desc *groupDescription) (*group, error) {
...
@@ -94,9 +124,19 @@ func addGroup(name string, desc *groupDescription) (*group, error) {
clients
:
make
(
map
[
string
]
client
),
clients
:
make
(
map
[
string
]
client
),
}
}
groups
.
groups
[
name
]
=
g
groups
.
groups
[
name
]
=
g
}
else
if
desc
!=
nil
{
return
g
,
nil
}
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
if
desc
!=
nil
{
g
.
description
=
desc
g
.
description
=
desc
}
else
if
g
.
dead
||
time
.
Since
(
g
.
description
.
loadTime
)
>
5
*
time
.
Second
{
g
.
dead
=
false
return
g
,
nil
}
if
g
.
dead
||
time
.
Since
(
g
.
description
.
loadTime
)
>
5
*
time
.
Second
{
changed
,
err
:=
descriptionChanged
(
name
,
g
.
description
)
changed
,
err
:=
descriptionChanged
(
name
,
g
.
description
)
if
err
!=
nil
{
if
err
!=
nil
{
if
!
os
.
IsNotExist
(
err
)
{
if
!
os
.
IsNotExist
(
err
)
{
...
@@ -176,6 +216,9 @@ func addClient(name string, c client) (*group, error) {
...
@@ -176,6 +216,9 @@ func addClient(name string, c client) (*group, error) {
return
nil
,
err
return
nil
,
err
}
}
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
perms
,
err
:=
getPermission
(
g
.
description
,
c
.
Credentials
())
perms
,
err
:=
getPermission
(
g
.
description
,
c
.
Credentials
())
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -183,13 +226,10 @@ func addClient(name string, c client) (*group, error) {
...
@@ -183,13 +226,10 @@ func addClient(name string, c client) (*group, error) {
c
.
SetPermissions
(
perms
)
c
.
SetPermissions
(
perms
)
if
!
perms
.
Op
&&
atomic
.
LoadUint32
(
&
g
.
locked
)
!=
0
{
if
!
perms
.
Op
&&
g
.
locked
{
return
nil
,
userError
(
"group is locked"
)
return
nil
,
userError
(
"group is locked"
)
}
}
g
.
mu
.
Lock
()
defer
g
.
mu
.
Unlock
()
if
!
perms
.
Op
&&
g
.
description
.
MaxClients
>
0
{
if
!
perms
.
Op
&&
g
.
description
.
MaxClients
>
0
{
if
len
(
g
.
clients
)
>=
g
.
description
.
MaxClients
{
if
len
(
g
.
clients
)
>=
g
.
description
.
MaxClients
{
return
nil
,
userError
(
"too many users"
)
return
nil
,
userError
(
"too many users"
)
...
@@ -423,8 +463,8 @@ type publicGroup struct {
...
@@ -423,8 +463,8 @@ type publicGroup struct {
func
getPublicGroups
()
[]
publicGroup
{
func
getPublicGroups
()
[]
publicGroup
{
gs
:=
make
([]
publicGroup
,
0
)
gs
:=
make
([]
publicGroup
,
0
)
rangeGroups
(
func
(
g
*
group
)
bool
{
rangeGroups
(
func
(
g
*
group
)
bool
{
if
g
.
description
.
Public
{
if
g
.
Public
()
{
gs
=
append
(
gs
,
publicGroup
{
gs
=
append
(
gs
,
publicGroup
{
Name
:
g
.
name
,
Name
:
g
.
name
,
ClientCount
:
len
(
g
.
clients
),
ClientCount
:
len
(
g
.
clients
),
...
...
webclient.go
View file @
7126394e
...
@@ -12,7 +12,6 @@ import (
...
@@ -12,7 +12,6 @@ import (
"os"
"os"
"strings"
"strings"
"sync"
"sync"
"sync/atomic"
"time"
"time"
"sfu/estimator"
"sfu/estimator"
...
@@ -713,10 +712,10 @@ func startClient(conn *websocket.Conn) (err error) {
...
@@ -713,10 +712,10 @@ func startClient(conn *websocket.Conn) (err error) {
}
}
return
return
}
}
if
g
.
description
.
R
edirect
!=
""
{
if
redirect
:=
g
.
Redirect
();
r
edirect
!=
""
{
// We normally redirect at the HTTP level, but the group
// We normally redirect at the HTTP level, but the group
// description could have been edited in the meantime.
// description could have been edited in the meantime.
err
=
userError
(
"group is now at "
+
g
.
description
.
R
edirect
)
err
=
userError
(
"group is now at "
+
r
edirect
)
return
return
}
}
c
.
group
=
g
c
.
group
=
g
...
@@ -940,10 +939,7 @@ func failConnection(c *webClient, id string, message string) error {
...
@@ -940,10 +939,7 @@ func failConnection(c *webClient, id string, message string) error {
}
}
func
setPermissions
(
g
*
group
,
id
string
,
perm
string
)
error
{
func
setPermissions
(
g
*
group
,
id
string
,
perm
string
)
error
{
g
.
mu
.
Lock
()
client
:=
g
.
getClient
(
id
)
defer
g
.
mu
.
Unlock
()
client
:=
g
.
getClientUnlocked
(
id
)
if
client
==
nil
{
if
client
==
nil
{
return
userError
(
"no such user"
)
return
userError
(
"no such user"
)
}
}
...
@@ -956,7 +952,7 @@ func setPermissions(g *group, id string, perm string) error {
...
@@ -956,7 +952,7 @@ func setPermissions(g *group, id string, perm string) error {
switch
perm
{
switch
perm
{
case
"op"
:
case
"op"
:
c
.
permissions
.
Op
=
true
c
.
permissions
.
Op
=
true
if
g
.
description
.
AllowRecording
{
if
g
.
AllowRecording
()
{
c
.
permissions
.
Record
=
true
c
.
permissions
.
Record
=
true
}
}
case
"unop"
:
case
"unop"
:
...
@@ -1071,11 +1067,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
...
@@ -1071,11 +1067,7 @@ func handleClientMessage(c *webClient, m clientMessage) error {
if
!
c
.
permissions
.
Op
{
if
!
c
.
permissions
.
Op
{
return
c
.
error
(
userError
(
"not authorised"
))
return
c
.
error
(
userError
(
"not authorised"
))
}
}
var
locked
uint32
c
.
group
.
SetLocked
(
m
.
Kind
==
"lock"
)
if
m
.
Kind
==
"lock"
{
locked
=
1
}
atomic
.
StoreUint32
(
&
c
.
group
.
locked
,
locked
)
case
"record"
:
case
"record"
:
if
!
c
.
permissions
.
Record
{
if
!
c
.
permissions
.
Record
{
return
c
.
error
(
userError
(
"not authorised"
))
return
c
.
error
(
userError
(
"not authorised"
))
...
...
webserver.go
View file @
7126394e
...
@@ -151,8 +151,8 @@ func groupHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -151,8 +151,8 @@ func groupHandler(w http.ResponseWriter, r *http.Request) {
return
return
}
}
if
g
.
description
.
R
edirect
!=
""
{
if
redirect
:=
g
.
Redirect
();
r
edirect
!=
""
{
http
.
Redirect
(
w
,
r
,
g
.
description
.
R
edirect
,
http
.
Redirect
(
w
,
r
,
r
edirect
,
http
.
StatusPermanentRedirect
)
http
.
StatusPermanentRedirect
)
return
return
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment