From 77e0f360b3904c505ffb65de790dd0deb376c2f8 Mon Sep 17 00:00:00 2001 From: zhiyi Date: Tue, 21 Nov 2023 21:39:51 +0800 Subject: [PATCH] debug variable unlocks limited webrtc peer connections --- client/client.go | 2 +- client/conn.go | 14 ++++++++------ client/idle.go | 14 +++++++++----- client/peer.go | 6 ++++-- predef/debug.go | 2 +- server/server.go | 4 ---- 6 files changed, 23 insertions(+), 19 deletions(-) diff --git a/client/client.go b/client/client.go index 09ffbc85..f2d40408 100644 --- a/client/client.go +++ b/client/client.go @@ -484,7 +484,7 @@ func (c *Client) Start() (err error) { } if c.Config().WebRTCRemoteConnections < 1 { c.Config().WebRTCRemoteConnections = 1 - } else if c.Config().WebRTCRemoteConnections > 50 { + } else if !predef.Debug && c.Config().WebRTCRemoteConnections > 50 { c.Config().WebRTCRemoteConnections = 50 } c.idleManager = newIdleManager(c.Config().RemoteIdleConnections) diff --git a/client/conn.go b/client/conn.go index 670f0146..3e12dd52 100644 --- a/client/conn.go +++ b/client/conn.go @@ -510,12 +510,14 @@ func (c *conn) processP2P(id uint32, r *bufio.LimitedReader) { func (c *conn) newPeerTask(id uint32) (t *peerTask, ok bool) { c.client.peersRWMtx.Lock() defer c.client.peersRWMtx.Unlock() - l := uint(len(c.client.peers)) - if l >= c.client.Config().WebRTCRemoteConnections { - respAndClose(id, c, [][]byte{ - []byte("HTTP/1.1 403 Forbidden\r\nConnection: Closed\r\n\r\n"), - }) - return + if !predef.Debug { + l := uint(len(c.client.peers)) + if l >= c.client.Config().WebRTCRemoteConnections { + respAndClose(id, c, [][]byte{ + []byte("HTTP/1.1 403 Forbidden\r\nConnection: Closed\r\n\r\n"), + }) + return + } } t = &peerTask{} diff --git a/client/idle.go b/client/idle.go index 074c5a79..58236682 100644 --- a/client/idle.go +++ b/client/idle.go @@ -147,7 +147,7 @@ func (m *idleManager) SetRunningWithTaskCount(id uint, taskCount uint32) { m.statusMtx.RUnlock() if s == running { if taskCount >= 3 { - m.statusCond.Signal() + m.statusCond.Broadcast() } return } @@ -176,14 +176,18 @@ func (m *idleManager) WaitIdle(id uint) { defer m.statusMtx.Unlock() for !m.close.Load() { - wait := false - for _, s := range m.status { + m.status[id] = wait + w := false + for i, s := range m.status { + if i == id { + continue + } if s == idle { - wait = true + w = true break } } - if wait { + if w { m.statusCond.Wait() continue } diff --git a/client/peer.go b/client/peer.go index 3ef2fa30..e9b8f274 100644 --- a/client/peer.go +++ b/client/peer.go @@ -240,8 +240,10 @@ func (pt *peerTask) process(r io.Reader, writer http.ResponseWriter, initFn func if err != nil { writer.WriteHeader(http.StatusBadRequest) } - if e := recover(); e != nil { - pt.Logger.Info().Interface("panic", e).Msg("processOffer panic") + if !predef.Debug { + if e := recover(); e != nil { + pt.Logger.Info().Interface("panic", e).Msg("processOffer panic") + } } pt.Logger.Info().Err(err).Msg("processOffer done") }() diff --git a/predef/debug.go b/predef/debug.go index 7f6cde38..a507a62d 100644 --- a/predef/debug.go +++ b/predef/debug.go @@ -29,7 +29,7 @@ import ( var Debug = false func init() { - env, ok := os.LookupEnv("DEBUG_REQ") + env, ok := os.LookupEnv("DEBUG_VAR") if ok { if strings.ToLower(env) == "true" { Debug = true diff --git a/server/server.go b/server/server.go index f28f6767..80c2c8c2 100644 --- a/server/server.go +++ b/server/server.go @@ -494,10 +494,6 @@ func (s *Server) startSTUNServer() (err error) { Realm: "ao.space", LoggerFactory: factory, AuthHandler: func(username, realm string, srcAddr net.Addr) (key []byte, ok bool) { - value, ok := s.users.Load(username) - if ok { - key = []byte(value.(string)) - } return }, PacketConnConfigs: []turn.PacketConnConfig{