Skip to content

Commit 0497e46

Browse files
committed
Add log
1 parent 52e264f commit 0497e46

File tree

3 files changed

+164
-8
lines changed

3 files changed

+164
-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: 160 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,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+
133171
func (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
198353
func 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
249405
This func will return libv2ray binding version and V2Ray version used.
250406
*/
251407
func CheckVersionX() string {

0 commit comments

Comments
 (0)