@@ -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,6 +132,42 @@ 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" )
135173 config , err := v2serial .LoadJSONConfig (strings .NewReader (v .ConfigureFileContent ))
@@ -139,6 +177,11 @@ func (v *V2RayPoint) pointloop() error {
139177 }
140178
141179 log .Println ("new v2ray core" )
180+ log .Printf ("file config = %s\n " , v .ConfigureFileContent )
181+ log .Printf ("v2ray config = %v\n " , config )
182+ ech , _ := fetchECH ()
183+ log .Printf ("ech before v2ray = %s\n " , ech )
184+
142185 v .Vpoint , err = v2core .New (config )
143186 if err != nil {
144187 v .Vpoint = nil
@@ -194,7 +237,7 @@ func InitV2Env(envPath string) {
194237 }
195238}
196239
197- //Delegate Funcation
240+ // Delegate Funcation
198241func TestConfig (ConfigureFileContent string ) error {
199242 _ , err := v2serial .LoadJSONConfig (strings .NewReader (ConfigureFileContent ))
200243 return err
@@ -245,7 +288,8 @@ func CheckVersion() int {
245288 return 23
246289}
247290
248- /*CheckVersionX string
291+ /*
292+ CheckVersionX string
249293This func will return libv2ray binding version and V2Ray version used.
250294*/
251295func CheckVersionX () string {
0 commit comments