Skip to content

Commit b0c62e0

Browse files
committed
Add log
1 parent 52e264f commit b0c62e0

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module github.com/imannamdari/AndroidLibV2rayLite
33
go 1.19
44

55
require (
6-
github.com/imannamdari/v2ray-core/v5 v5.0.1
6+
github.com/imannamdari/v2ray-core/v5 v5.0.3
7+
github.com/miekg/dns v1.1.50
78
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028
89
golang.org/x/sys v0.5.0
910
)
@@ -29,7 +30,6 @@ require (
2930
github.com/klauspost/reedsolomon v1.9.3 // indirect
3031
github.com/leodido/go-urn v1.2.1 // indirect
3132
github.com/lunixbochs/struc v0.0.0-20200707160740-784aaebc1d40 // indirect
32-
github.com/miekg/dns v1.1.50 // indirect
3333
github.com/mustafaturan/bus v1.0.2 // indirect
3434
github.com/mustafaturan/monoton v1.0.0 // indirect
3535
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
150150
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
151151
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
152152
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
153-
github.com/imannamdari/v2ray-core/v5 v5.0.1 h1:Dd4A03fGH298iKQUvENnhSs4KIrU6cS4iyoE6T9nAK0=
154-
github.com/imannamdari/v2ray-core/v5 v5.0.1/go.mod h1:EIhvDDRH7gR8GvlVJf/lCS5wS8KkAoQZPkQIz8lNecI=
153+
github.com/imannamdari/v2ray-core/v5 v5.0.3 h1:VGObJK8J0eQWtB6O2ZTpyH2QAwg4bR5moQXE8VBwXO4=
154+
github.com/imannamdari/v2ray-core/v5 v5.0.3/go.mod h1:EIhvDDRH7gR8GvlVJf/lCS5wS8KkAoQZPkQIz8lNecI=
155155
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
156156
github.com/jhump/gopoet v0.0.0-20190322174617-17282ff210b3/go.mod h1:me9yfT6IJSlOL3FCfrg+L6yzUEZ+5jW6WHt4Sk+UPUI=
157157
github.com/jhump/gopoet v0.1.0/go.mod h1:me9yfT6IJSlOL3FCfrg+L6yzUEZ+5jW6WHt4Sk+UPUI=

interact.go

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
3739
This is territory of Go, so no getter and setters!
3840
*/
3941
type V2RayPoint struct {
@@ -111,7 +113,7 @@ func (v *V2RayPoint) StopLoop() (err error) {
111113
return
112114
}
113115

114-
//Delegate Funcation
116+
// Delegate Funcation
115117
func (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+
133171
func (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
198241
func 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
249293
This func will return libv2ray binding version and V2Ray version used.
250294
*/
251295
func CheckVersionX() string {

0 commit comments

Comments
 (0)