Propagate adtag

This commit is contained in:
9seconds
2018-07-04 18:08:04 +03:00
parent 69c4997fd4
commit c35c482de7
3 changed files with 17 additions and 3 deletions
+11 -1
View File
@@ -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
+2 -1
View File
@@ -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())
+4 -1
View File
@@ -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) {