Skip to content

Commit 77e0f36

Browse files
committed
debug variable unlocks limited webrtc peer connections
1 parent 2e2a346 commit 77e0f36

File tree

6 files changed

+23
-19
lines changed

6 files changed

+23
-19
lines changed

client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ func (c *Client) Start() (err error) {
484484
}
485485
if c.Config().WebRTCRemoteConnections < 1 {
486486
c.Config().WebRTCRemoteConnections = 1
487-
} else if c.Config().WebRTCRemoteConnections > 50 {
487+
} else if !predef.Debug && c.Config().WebRTCRemoteConnections > 50 {
488488
c.Config().WebRTCRemoteConnections = 50
489489
}
490490
c.idleManager = newIdleManager(c.Config().RemoteIdleConnections)

client/conn.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,14 @@ func (c *conn) processP2P(id uint32, r *bufio.LimitedReader) {
510510
func (c *conn) newPeerTask(id uint32) (t *peerTask, ok bool) {
511511
c.client.peersRWMtx.Lock()
512512
defer c.client.peersRWMtx.Unlock()
513-
l := uint(len(c.client.peers))
514-
if l >= c.client.Config().WebRTCRemoteConnections {
515-
respAndClose(id, c, [][]byte{
516-
[]byte("HTTP/1.1 403 Forbidden\r\nConnection: Closed\r\n\r\n"),
517-
})
518-
return
513+
if !predef.Debug {
514+
l := uint(len(c.client.peers))
515+
if l >= c.client.Config().WebRTCRemoteConnections {
516+
respAndClose(id, c, [][]byte{
517+
[]byte("HTTP/1.1 403 Forbidden\r\nConnection: Closed\r\n\r\n"),
518+
})
519+
return
520+
}
519521
}
520522

521523
t = &peerTask{}

client/idle.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (m *idleManager) SetRunningWithTaskCount(id uint, taskCount uint32) {
147147
m.statusMtx.RUnlock()
148148
if s == running {
149149
if taskCount >= 3 {
150-
m.statusCond.Signal()
150+
m.statusCond.Broadcast()
151151
}
152152
return
153153
}
@@ -176,14 +176,18 @@ func (m *idleManager) WaitIdle(id uint) {
176176
defer m.statusMtx.Unlock()
177177

178178
for !m.close.Load() {
179-
wait := false
180-
for _, s := range m.status {
179+
m.status[id] = wait
180+
w := false
181+
for i, s := range m.status {
182+
if i == id {
183+
continue
184+
}
181185
if s == idle {
182-
wait = true
186+
w = true
183187
break
184188
}
185189
}
186-
if wait {
190+
if w {
187191
m.statusCond.Wait()
188192
continue
189193
}

client/peer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,10 @@ func (pt *peerTask) process(r io.Reader, writer http.ResponseWriter, initFn func
240240
if err != nil {
241241
writer.WriteHeader(http.StatusBadRequest)
242242
}
243-
if e := recover(); e != nil {
244-
pt.Logger.Info().Interface("panic", e).Msg("processOffer panic")
243+
if !predef.Debug {
244+
if e := recover(); e != nil {
245+
pt.Logger.Info().Interface("panic", e).Msg("processOffer panic")
246+
}
245247
}
246248
pt.Logger.Info().Err(err).Msg("processOffer done")
247249
}()

predef/debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
var Debug = false
3030

3131
func init() {
32-
env, ok := os.LookupEnv("DEBUG_REQ")
32+
env, ok := os.LookupEnv("DEBUG_VAR")
3333
if ok {
3434
if strings.ToLower(env) == "true" {
3535
Debug = true

server/server.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,6 @@ func (s *Server) startSTUNServer() (err error) {
494494
Realm: "ao.space",
495495
LoggerFactory: factory,
496496
AuthHandler: func(username, realm string, srcAddr net.Addr) (key []byte, ok bool) {
497-
value, ok := s.users.Load(username)
498-
if ok {
499-
key = []byte(value.(string))
500-
}
501497
return
502498
},
503499
PacketConnConfigs: []turn.PacketConnConfig{

0 commit comments

Comments
 (0)