Parcourir la source

Propagate adtag

tags/0.9
9seconds il y a 7 ans
Parent
révision
c35c482de7
3 fichiers modifiés avec 17 ajouts et 3 suppressions
  1. 11
    1
      config/config.go
  2. 2
    1
      main.go
  3. 4
    1
      telegram/middle.go

+ 11
- 1
config/config.go Voir le fichier

38
 	StatsIP    net.IP
38
 	StatsIP    net.IP
39
 
39
 
40
 	Secret []byte
40
 	Secret []byte
41
+	AdTag  []byte
41
 }
42
 }
42
 
43
 
43
 // URLs contains links to the proxy (tg://, t.me) and their QR codes.
44
 // URLs contains links to the proxy (tg://, t.me) and their QR codes.
89
 	publicIPv4 net.IP, PublicIPv4Port uint16,
90
 	publicIPv4 net.IP, PublicIPv4Port uint16,
90
 	publicIPv6 net.IP, publicIPv6Port uint16,
91
 	publicIPv6 net.IP, publicIPv6Port uint16,
91
 	statsIP net.IP, statsPort uint16,
92
 	statsIP net.IP, statsPort uint16,
92
-	secret string) (*Config, error) {
93
+	secret, adtag string) (*Config, error) {
93
 	if len(secret) != 32 {
94
 	if len(secret) != 32 {
94
 		return nil, errors.New("Telegram demands secret of length 32")
95
 		return nil, errors.New("Telegram demands secret of length 32")
95
 	}
96
 	}
98
 		return nil, errors.Annotate(err, "Cannot create config")
99
 		return nil, errors.Annotate(err, "Cannot create config")
99
 	}
100
 	}
100
 
101
 
102
+	var adTagBytes []byte
103
+	if len(adtag) != 0 {
104
+		adTagBytes, err = hex.DecodeString(adtag)
105
+		if err != nil {
106
+			return nil, errors.Annotate(err, "Cannot create config")
107
+		}
108
+	}
109
+
101
 	if publicIPv4 == nil {
110
 	if publicIPv4 == nil {
102
 		publicIPv4, err = getGlobalIPv4()
111
 		publicIPv4, err = getGlobalIPv4()
103
 		if err != nil {
112
 		if err != nil {
138
 		StatsIP:        statsIP,
147
 		StatsIP:        statsIP,
139
 		StatsPort:      statsPort,
148
 		StatsPort:      statsPort,
140
 		Secret:         secretBytes,
149
 		Secret:         secretBytes,
150
+		AdTag:          adTagBytes,
141
 	}
151
 	}
142
 
152
 
143
 	return conf, nil
153
 	return conf, nil

+ 2
- 1
main.go Voir le fichier

72
 			Uint16()
72
 			Uint16()
73
 
73
 
74
 	secret = app.Arg("secret", "Secret of this proxy.").Required().String()
74
 	secret = app.Arg("secret", "Secret of this proxy.").Required().String()
75
+	adtag  = app.Arg("adtag", "ADTag of the proxy.").String()
75
 )
76
 )
76
 
77
 
77
 func init() {
78
 func init() {
93
 		*publicIPv4, *publicIPv4Port,
94
 		*publicIPv4, *publicIPv4Port,
94
 		*publicIPv6, *publicIPv6Port,
95
 		*publicIPv6, *publicIPv6Port,
95
 		*statsIP, *statsPort,
96
 		*statsIP, *statsPort,
96
-		*secret,
97
+		*secret, *adtag,
97
 	)
98
 	)
98
 	if err != nil {
99
 	if err != nil {
99
 		usage(err.Error())
100
 		usage(err.Error())

+ 4
- 1
telegram/middle.go Voir le fichier

19
 
19
 
20
 type middleTelegram struct {
20
 type middleTelegram struct {
21
 	middleTelegramCaller
21
 	middleTelegramCaller
22
+
23
+	adtag []byte
22
 }
24
 }
23
 
25
 
24
 func NewMiddleTelegram(conf *config.Config, logger *zap.SugaredLogger) Telegram {
26
 func NewMiddleTelegram(conf *config.Config, logger *zap.SugaredLogger) Telegram {
36
 			},
38
 			},
37
 			dialerMutex: &sync.RWMutex{},
39
 			dialerMutex: &sync.RWMutex{},
38
 		},
40
 		},
41
+		adtag: conf.AdTag,
39
 	}
42
 	}
40
 
43
 
41
 	if err := tg.update(); err != nil {
44
 	if err := tg.update(); err != nil {
70
 		return nil, err
73
 		return nil, err
71
 	}
74
 	}
72
 
75
 
73
-	return nil, nil
76
+	return mtwrappers.NewProxyRequestRWC(secureConn, connOpts, t.adtag)
74
 }
77
 }
75
 
78
 
76
 func (t *middleTelegram) sendRPCNonceRequest(conn io.Writer) (*rpc.RPCNonceRequest, error) {
79
 func (t *middleTelegram) sendRPCNonceRequest(conn io.Writer) (*rpc.RPCNonceRequest, error) {

Chargement…
Annuler
Enregistrer