Skip to content

Commit

Permalink
Update main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddify-com authored Aug 4, 2023
1 parent 6bb8217 commit ddbf8e1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ func main() {
result := rdb.SIsMember(ctx, "ssh-server:users", userString)
res, err := result.Result()
doneCh := ctx.Done()
log.Printf("UserString -%s- err -%s- res -%s-", userString,res,err)
log.Printf("UserString -%s- res -%s- err -%s-", userString,res,err)
if err != nil || !res || doneCh == nil {
log.Printf("returning false 1")
return false
}
userConnectionCountMutex.Lock()
Expand All @@ -211,17 +212,21 @@ func main() {
connCntStr, _ := hget_res.Result()
connCnt, err2 := strconv.ParseInt(connCntStr, 10, 32)
if err2 == nil && connCnt >= maxConns {
log.Printf("returning false 2")
log.Printf("Client %s trying to have more than %d connections\n", userString, maxConns)
return false // No duplicate connections
}
hincr_res := rdb.HIncrBy(ctx, "ssh-server:connections", userId, 1)
if hincr_res.Err() != nil {
log.Printf("returning false 3 %s",hincr_res.Err())
return false
}
go func() {
<-doneCh
log.Printf("4---",userId)
rdb.HIncrBy(context.Background(), "ssh-server:connections", userId, -1)
}()
log.Printf("returning true ")
return true
},
IdleTimeout: time.Minute * 1,
Expand Down

0 comments on commit ddbf8e1

Please sign in to comment.