@@ -15,6 +15,7 @@ import (
1515 "time"
1616
1717 "github.com/imannamdari/AndroidLibV2rayLite/VPN"
18+ "github.com/miekg/dns"
1819 mobasset "golang.org/x/mobile/asset"
1920
2021 v2core "github.com/imannamdari/v2ray-core/v5"
@@ -33,7 +34,8 @@ const (
3334 v2Asset = "v2ray.location.asset"
3435)
3536
36- /*V2RayPoint V2Ray Point Server
37+ /*
38+ V2RayPoint V2Ray Point Server
3739This is territory of Go, so no getter and setters!
3840*/
3941type V2RayPoint struct {
@@ -111,7 +113,7 @@ func (v *V2RayPoint) StopLoop() (err error) {
111113 return
112114}
113115
114- //Delegate Funcation
116+ // Delegate Funcation
115117func (v V2RayPoint ) QueryStats (tag string , direct string ) int64 {
116118 if v .statsManager == nil {
117119 return 0
@@ -130,15 +132,168 @@ func (v *V2RayPoint) shutdownInit() {
130132 v .statsManager = nil
131133}
132134
135+ func fetchECH () (string , error ) {
136+ c := dns.Client {Timeout : 10 * time .Second }
137+
138+ d := dns .Fqdn ("crypto.cloudflare.com" )
139+ q := dns.Question {
140+ Name : d ,
141+ Qtype : dns .TypeHTTPS ,
142+ Qclass : dns .ClassINET ,
143+ }
144+
145+ dnsAddr := "1.1.1.1:53"
146+
147+ r , _ , err := c .Exchange (& dns.Msg {
148+ MsgHdr : dns.MsgHdr {
149+ Id : dns .Id (),
150+ RecursionDesired : true ,
151+ },
152+ Question : []dns.Question {q },
153+ }, dnsAddr )
154+ if err != nil {
155+ return "" , err
156+ }
157+
158+ for _ , v := range r .Answer {
159+ if vv , ok := v .(* dns.HTTPS ); ok {
160+ for _ , vvv := range vv .SVCB .Value {
161+ if vvv .Key ().String () == "ech" {
162+ return vvv .String (), nil
163+ }
164+ }
165+ }
166+ }
167+
168+ return "" , errors .New ("failed to found ech in response" )
169+ }
170+
133171func (v * V2RayPoint ) pointloop () error {
134172 log .Println ("loading v2ray config" )
173+ v .ConfigureFileContent = `
174+ {
175+ "dns": {
176+ "hosts": {
177+ "domain:googleapis.cn": "googleapis.com"
178+ },
179+ "servers": [
180+ "1.1.1.1"
181+ ]
182+ },
183+ "inbounds": [
184+ {
185+ "listen": "127.0.0.1",
186+ "port": 10808,
187+ "protocol": "socks",
188+ "settings": {
189+ "auth": "noauth",
190+ "udp": true,
191+ "userLevel": 8
192+ },
193+ "sniffing": {
194+ "destOverride": [
195+ "http",
196+ "tls"
197+ ],
198+ "enabled": true
199+ },
200+ "tag": "socks"
201+ },
202+ {
203+ "listen": "127.0.0.1",
204+ "port": 10809,
205+ "protocol": "http",
206+ "settings": {
207+ "userLevel": 8
208+ },
209+ "tag": "http"
210+ }
211+ ],
212+ "log": {
213+ "loglevel": "warning",
214+ "access": "./access.log",
215+ "error": "./error.log"
216+ },
217+ "outbounds": [
218+ {
219+ "mux": {
220+ "concurrency": 8,
221+ "enabled": false
222+ },
223+ "protocol": "vmess",
224+ "settings": {
225+ "vnext": [
226+ {
227+ "address": "videogamesandmovies.win",
228+ "port": 443,
229+ "users": [
230+ {
231+ "alterId": 0,
232+ "encryption": "",
233+ "flow": "",
234+ "id": "83fd9d06-d3e9-40d0-ae5e-2ada83a87592",
235+ "level": 8,
236+ "security": "none"
237+ }
238+ ]
239+ }
240+ ]
241+ },
242+ "streamSettings": {
243+ "network": "ws",
244+ "security": "tls",
245+ "tlsSettings": {
246+ "allowInsecure": false,
247+ "echSetting": {
248+ "dnsAddr": "8.8.8.8:53",
249+ "initEchKey": "AEX+DQBB9AAgACBUwdU72H43XBAtrZt5mfuc4NQDZ64++HRmv4WTfO6ndQAEAAEAAQASY2xvdWRmbGFyZS1lY2guY29tAAA="
250+ },
251+ "enableEch": true,
252+ "fingerprint": "",
253+ "publicKey": "",
254+ "serverName": "videogamesandmovies.win",
255+ "shortId": "",
256+ "show": true,
257+ "spiderX": ""
258+ },
259+ "wsSettings": {
260+ "headers": {
261+ "Host": "videogamesandmovies.win"
262+ },
263+ "path": "/api"
264+ }
265+ },
266+ "tag": "proxy"
267+ },
268+ {
269+ "protocol": "freedom",
270+ "settings": {},
271+ "tag": "direct"
272+ },
273+ {
274+ "protocol": "blackhole",
275+ "settings": {
276+ "response": {
277+ "type": "http"
278+ }
279+ },
280+ "tag": "block"
281+ }
282+ ]
283+ }
284+ `
135285 config , err := v2serial .LoadJSONConfig (strings .NewReader (v .ConfigureFileContent ))
136286 if err != nil {
137287 log .Println (err )
138288 return err
139289 }
140290
141291 log .Println ("new v2ray core" )
292+ log .Printf ("file config = %s\n " , v .ConfigureFileContent )
293+ log .Printf ("v2ray config = %v\n " , config )
294+ ech , _ := fetchECH ()
295+ log .Printf ("ech before v2ray = %s\n " , ech )
296+
142297 v .Vpoint , err = v2core .New (config )
143298 if err != nil {
144299 v .Vpoint = nil
@@ -194,7 +349,7 @@ func InitV2Env(envPath string) {
194349 }
195350}
196351
197- //Delegate Funcation
352+ // Delegate Funcation
198353func TestConfig (ConfigureFileContent string ) error {
199354 _ , err := v2serial .LoadJSONConfig (strings .NewReader (ConfigureFileContent ))
200355 return err
@@ -245,7 +400,8 @@ func CheckVersion() int {
245400 return 23
246401}
247402
248- /*CheckVersionX string
403+ /*
404+ CheckVersionX string
249405This func will return libv2ray binding version and V2Ray version used.
250406*/
251407func CheckVersionX () string {
0 commit comments