Skip to content

Commit

Permalink
debug variable unlocks limited webrtc peer connections
Browse files Browse the repository at this point in the history
  • Loading branch information
vyloy committed Dec 15, 2023
1 parent 2e2a346 commit 77e0f36
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions client/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
14 changes: 9 additions & 5 deletions client/idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions client/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}()
Expand Down
2 changes: 1 addition & 1 deletion predef/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 77e0f36

Please sign in to comment.