mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 16:14:02 +03:00
Propagate adtag
This commit is contained in:
+11
-1
@@ -38,6 +38,7 @@ type Config struct {
|
|||||||
StatsIP net.IP
|
StatsIP net.IP
|
||||||
|
|
||||||
Secret []byte
|
Secret []byte
|
||||||
|
AdTag []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// URLs contains links to the proxy (tg://, t.me) and their QR codes.
|
// 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,
|
publicIPv4 net.IP, PublicIPv4Port uint16,
|
||||||
publicIPv6 net.IP, publicIPv6Port uint16,
|
publicIPv6 net.IP, publicIPv6Port uint16,
|
||||||
statsIP net.IP, statsPort uint16,
|
statsIP net.IP, statsPort uint16,
|
||||||
secret string) (*Config, error) {
|
secret, adtag string) (*Config, error) {
|
||||||
if len(secret) != 32 {
|
if len(secret) != 32 {
|
||||||
return nil, errors.New("Telegram demands secret of length 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")
|
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 {
|
if publicIPv4 == nil {
|
||||||
publicIPv4, err = getGlobalIPv4()
|
publicIPv4, err = getGlobalIPv4()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -138,6 +147,7 @@ func NewConfig(debug, verbose bool, // nolint: gocyclo
|
|||||||
StatsIP: statsIP,
|
StatsIP: statsIP,
|
||||||
StatsPort: statsPort,
|
StatsPort: statsPort,
|
||||||
Secret: secretBytes,
|
Secret: secretBytes,
|
||||||
|
AdTag: adTagBytes,
|
||||||
}
|
}
|
||||||
|
|
||||||
return conf, nil
|
return conf, nil
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ var (
|
|||||||
Uint16()
|
Uint16()
|
||||||
|
|
||||||
secret = app.Arg("secret", "Secret of this proxy.").Required().String()
|
secret = app.Arg("secret", "Secret of this proxy.").Required().String()
|
||||||
|
adtag = app.Arg("adtag", "ADTag of the proxy.").String()
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -93,7 +94,7 @@ func main() {
|
|||||||
*publicIPv4, *publicIPv4Port,
|
*publicIPv4, *publicIPv4Port,
|
||||||
*publicIPv6, *publicIPv6Port,
|
*publicIPv6, *publicIPv6Port,
|
||||||
*statsIP, *statsPort,
|
*statsIP, *statsPort,
|
||||||
*secret,
|
*secret, *adtag,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
usage(err.Error())
|
usage(err.Error())
|
||||||
|
|||||||
+4
-1
@@ -19,6 +19,8 @@ import (
|
|||||||
|
|
||||||
type middleTelegram struct {
|
type middleTelegram struct {
|
||||||
middleTelegramCaller
|
middleTelegramCaller
|
||||||
|
|
||||||
|
adtag []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMiddleTelegram(conf *config.Config, logger *zap.SugaredLogger) Telegram {
|
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{},
|
dialerMutex: &sync.RWMutex{},
|
||||||
},
|
},
|
||||||
|
adtag: conf.AdTag,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := tg.update(); err != nil {
|
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, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return mtwrappers.NewProxyRequestRWC(secureConn, connOpts, t.adtag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *middleTelegram) sendRPCNonceRequest(conn io.Writer) (*rpc.RPCNonceRequest, error) {
|
func (t *middleTelegram) sendRPCNonceRequest(conn io.Writer) (*rpc.RPCNonceRequest, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user