mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 21:54:01 +03:00
Success path for fake tls is implemented
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package faketls
|
||||
|
||||
import (
|
||||
"container/ring"
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/9seconds/mtg/config"
|
||||
)
|
||||
|
||||
var (
|
||||
connectionServerInstance connectionServer
|
||||
connectionServerInitOnce sync.Once
|
||||
)
|
||||
|
||||
const (
|
||||
connectionServerKeepCertificates = 5
|
||||
connectionServerUpdateEvery = 10 * time.Minute
|
||||
)
|
||||
|
||||
func Init(ctx context.Context) {
|
||||
connectionServerInitOnce.Do(func() {
|
||||
if config.C.CloakHost == "" {
|
||||
return
|
||||
}
|
||||
|
||||
connectionServerInstance = connectionServer{
|
||||
channelGet: make(chan chan<- []byte),
|
||||
ctx: ctx,
|
||||
}
|
||||
|
||||
cert, err := connectionServerInstance.fetch()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
r := ring.New(connectionServerKeepCertificates)
|
||||
|
||||
for i := 0; i < connectionServerKeepCertificates; i++ {
|
||||
r.Value = cert
|
||||
r = r.Next()
|
||||
}
|
||||
|
||||
connectionServerInstance.nextWriteItem = r
|
||||
connectionServerInstance.nextReadItem = r
|
||||
|
||||
go connectionServerInstance.run(connectionServerUpdateEvery)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user