mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 16:14:02 +03:00
Proxy is working in a simple mode now
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/9seconds/mtg/v2/mtglib/internal/obfuscated2"
|
||||
"github.com/9seconds/mtg/v2/mtglib/internal/relay"
|
||||
"github.com/9seconds/mtg/v2/mtglib/internal/telegram"
|
||||
"github.com/panjf2000/ants/v2"
|
||||
)
|
||||
@@ -19,6 +20,7 @@ type Proxy struct {
|
||||
streamWaitGroup sync.WaitGroup
|
||||
|
||||
idleTimeout time.Duration
|
||||
bufferSize int
|
||||
workerPool *ants.PoolWithFunc
|
||||
telegram *telegram.Telegram
|
||||
|
||||
@@ -64,6 +66,13 @@ func (p *Proxy) ServeConn(conn net.Conn) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
rel := relay.AcquireRelay(ctx, p.logger.Named("relay"), p.bufferSize, p.idleTimeout)
|
||||
defer relay.ReleaseRelay(rel)
|
||||
|
||||
if err := rel.Process(ctx.clientConn, ctx.telegramConn); err != nil {
|
||||
p.logger.DebugError("relay has been finished", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Proxy) Serve(listener net.Listener) error {
|
||||
@@ -185,6 +194,11 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) { // nolint: cyclop
|
||||
idleTimeout = DefaultIdleTimeout
|
||||
}
|
||||
|
||||
bufferSize := opts.BufferSize
|
||||
if bufferSize < 1 {
|
||||
bufferSize = DefaultBufferSize
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
proxy := &Proxy{
|
||||
ctx: ctx,
|
||||
@@ -195,6 +209,7 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) { // nolint: cyclop
|
||||
eventStream: opts.EventStream,
|
||||
logger: opts.Logger.Named("proxy"),
|
||||
idleTimeout: idleTimeout,
|
||||
bufferSize: int(bufferSize),
|
||||
telegram: tg,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user