diff --git a/config/config.go b/config/config.go index d988c38..6235b8c 100644 --- a/config/config.go +++ b/config/config.go @@ -38,6 +38,7 @@ type Config struct { StatsIP net.IP Secret []byte + AdTag []byte } // URLs contains links to the proxy (tg://, t.me) and their QR codes. @@ -89,7 +90,7 @@ func NewConfig(debug, verbose bool, // nolint: gocyclo publicIPv4 net.IP, PublicIPv4Port uint16, publicIPv6 net.IP, publicIPv6Port uint16, statsIP net.IP, statsPort uint16, - secret string) (*Config, error) { + secret, adtag string) (*Config, error) { if len(secret) != 32 { return nil, errors.New("Telegram demands secret of length 32") } @@ -98,6 +99,14 @@ func NewConfig(debug, verbose bool, // nolint: gocyclo return nil, errors.Annotate(err, "Cannot create config") } + var adTagBytes []byte + if len(adtag) != 0 { + adTagBytes, err = hex.DecodeString(adtag) + if err != nil { + return nil, errors.Annotate(err, "Cannot create config") + } + } + if publicIPv4 == nil { publicIPv4, err = getGlobalIPv4() if err != nil { @@ -138,6 +147,7 @@ func NewConfig(debug, verbose bool, // nolint: gocyclo StatsIP: statsIP, StatsPort: statsPort, Secret: secretBytes, + AdTag: adTagBytes, } return conf, nil diff --git a/main.go b/main.go index 8154f6f..fcb2599 100644 --- a/main.go +++ b/main.go @@ -72,6 +72,7 @@ var ( Uint16() secret = app.Arg("secret", "Secret of this proxy.").Required().String() + adtag = app.Arg("adtag", "ADTag of the proxy.").String() ) func init() { @@ -93,7 +94,7 @@ func main() { *publicIPv4, *publicIPv4Port, *publicIPv6, *publicIPv6Port, *statsIP, *statsPort, - *secret, + *secret, *adtag, ) if err != nil { usage(err.Error()) diff --git a/telegram/middle.go b/telegram/middle.go index 03d70cd..91f22d5 100644 --- a/telegram/middle.go +++ b/telegram/middle.go @@ -19,6 +19,8 @@ import ( type middleTelegram struct { middleTelegramCaller + + adtag []byte } func NewMiddleTelegram(conf *config.Config, logger *zap.SugaredLogger) Telegram { @@ -36,6 +38,7 @@ func NewMiddleTelegram(conf *config.Config, logger *zap.SugaredLogger) Telegram }, dialerMutex: &sync.RWMutex{}, }, + adtag: conf.AdTag, } if err := tg.update(); err != nil { @@ -70,7 +73,7 @@ func (t *middleTelegram) Init(connOpts *mtproto.ConnectionOpts, conn wrappers.Re return nil, err } - return nil, nil + return mtwrappers.NewProxyRequestRWC(secureConn, connOpts, t.adtag) } func (t *middleTelegram) sendRPCNonceRequest(conn io.Writer) (*rpc.RPCNonceRequest, error) {