mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 23:34:02 +03:00
Propagate to middle client
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"github.com/9seconds/mtg/config"
|
||||||
|
"github.com/9seconds/mtg/mtproto"
|
||||||
|
mtwrappers "github.com/9seconds/mtg/mtproto/wrappers"
|
||||||
|
"github.com/9seconds/mtg/wrappers"
|
||||||
|
)
|
||||||
|
|
||||||
|
func MiddleInit(conn net.Conn, conf *config.Config) (*mtproto.ConnectionOpts, wrappers.ReadWriteCloserWithAddr, error) {
|
||||||
|
opts, newConn, err := DirectInit(conn, conf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if opts.ConnectionType == mtproto.ConnectionTypeAbridged {
|
||||||
|
newConn = mtwrappers.NewAbridgedRWC(newConn, opts)
|
||||||
|
} else {
|
||||||
|
newConn = mtwrappers.NewIntermediateRWC(newConn, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
return opts, newConn, nil
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
@@ -16,8 +15,7 @@ import (
|
|||||||
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
kingpin "gopkg.in/alecthomas/kingpin.v2"
|
||||||
|
|
||||||
"github.com/9seconds/mtg/config"
|
"github.com/9seconds/mtg/config"
|
||||||
"github.com/9seconds/mtg/mtproto"
|
"github.com/9seconds/mtg/proxy"
|
||||||
"github.com/9seconds/mtg/telegram"
|
|
||||||
"github.com/juju/errors"
|
"github.com/juju/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -115,29 +113,15 @@ func main() {
|
|||||||
atom,
|
atom,
|
||||||
)).Sugar()
|
)).Sugar()
|
||||||
|
|
||||||
tg := telegram.NewMiddleTelegram(conf, logger)
|
stat := proxy.NewStats(conf)
|
||||||
connOpts := &mtproto.ConnectionOpts{
|
go stat.Serve()
|
||||||
DC: int16(1),
|
|
||||||
ConnectionType: mtproto.ConnectionTypeAbridged,
|
srv := proxy.NewServer(conf, logger, stat)
|
||||||
ConnectionProto: mtproto.ConnectionProtocolIPv4,
|
printURLs(conf.GetURLs())
|
||||||
|
|
||||||
|
if err := srv.Serve(); err != nil {
|
||||||
|
logger.Fatal(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
sock, err := tg.Dial(connOpts)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
_, err = tg.Init(connOpts, sock)
|
|
||||||
fmt.Println(err)
|
|
||||||
|
|
||||||
// stat := proxy.NewStats(conf)
|
|
||||||
// go stat.Serve()
|
|
||||||
|
|
||||||
// srv := proxy.NewServer(conf, logger, stat)
|
|
||||||
// printURLs(conf.GetURLs())
|
|
||||||
|
|
||||||
// if err := srv.Serve(); err != nil {
|
|
||||||
// logger.Fatal(err.Error())
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setRLimit() (err error) {
|
func setRLimit() (err error) {
|
||||||
|
|||||||
+10
-2
@@ -139,11 +139,19 @@ func (s *Server) pipe(dst io.Writer, src io.Reader, wait *sync.WaitGroup) {
|
|||||||
|
|
||||||
// NewServer creates new instance of MTPROTO proxy.
|
// NewServer creates new instance of MTPROTO proxy.
|
||||||
func NewServer(conf *config.Config, logger *zap.SugaredLogger, stat *Stats) *Server {
|
func NewServer(conf *config.Config, logger *zap.SugaredLogger, stat *Stats) *Server {
|
||||||
|
clientInit := client.DirectInit
|
||||||
|
tg := telegram.NewDirectTelegram
|
||||||
|
|
||||||
|
if len(conf.AdTag) > 0 {
|
||||||
|
clientInit = client.MiddleInit
|
||||||
|
tg = telegram.NewMiddleTelegram
|
||||||
|
}
|
||||||
|
|
||||||
return &Server{
|
return &Server{
|
||||||
conf: conf,
|
conf: conf,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
stats: stat,
|
stats: stat,
|
||||||
tg: telegram.NewDirectTelegram(conf),
|
tg: tg(conf, logger),
|
||||||
clientInit: client.DirectInit,
|
clientInit: clientInit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -4,6 +4,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/juju/errors"
|
"github.com/juju/errors"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
|
||||||
"github.com/9seconds/mtg/config"
|
"github.com/9seconds/mtg/config"
|
||||||
"github.com/9seconds/mtg/mtproto"
|
"github.com/9seconds/mtg/mtproto"
|
||||||
@@ -55,7 +56,7 @@ func (t *directTelegram) Init(connOpts *mtproto.ConnectionOpts, conn wrappers.Re
|
|||||||
|
|
||||||
// NewDirectTelegram returns Telegram instance which connects directly
|
// NewDirectTelegram returns Telegram instance which connects directly
|
||||||
// to Telegram bypassing middleproxies.
|
// to Telegram bypassing middleproxies.
|
||||||
func NewDirectTelegram(conf *config.Config) Telegram {
|
func NewDirectTelegram(conf *config.Config, _ *zap.SugaredLogger) Telegram {
|
||||||
return &directTelegram{baseTelegram{
|
return &directTelegram{baseTelegram{
|
||||||
dialer: tgDialer{
|
dialer: tgDialer{
|
||||||
Dialer: net.Dialer{Timeout: telegramDialTimeout},
|
Dialer: net.Dialer{Timeout: telegramDialTimeout},
|
||||||
|
|||||||
Reference in New Issue
Block a user