Skip to content

Commit 9391c75

Browse files
New transports and api changes for V2RaySocks (#685)
* New transports and api changes for V2RaySocks * version++
1 parent eb16b70 commit 9391c75

File tree

3 files changed

+67
-32
lines changed

3 files changed

+67
-32
lines changed

api/v2raysocks/model.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package v2raysocks
22

33
type UserTraffic struct {
4-
UID int `json:"user_id"`
4+
UID int `json:"uid"`
55
Upload int64 `json:"u"`
66
Download int64 `json:"d"`
77
}
@@ -19,6 +19,10 @@ type NodeOnline struct {
1919
IP string `json:"ip"`
2020
}
2121

22+
type IllegalItem struct {
23+
UID int `json:"uid"`
24+
}
25+
2226
type REALITYConfig struct {
2327
Dest string `json:"dest,omitempty"`
2428
ProxyProtocolVer uint64 `json:"proxy_protocol_ver,omitempty"`

api/v2raysocks/v2raysocks.go

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
159159
res, err := c.client.R().
160160
SetHeader("If-None-Match", c.eTags["config"]).
161161
SetQueryParams(map[string]string{
162-
"act": "config",
163-
"nodetype": nodeType,
162+
"act": "config",
163+
"node_type": nodeType,
164164
}).
165165
ForceContentType("application/json").
166166
Get(c.APIHost)
@@ -213,8 +213,8 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
213213
res, err := c.client.R().
214214
SetHeader("If-None-Match", c.eTags["user"]).
215215
SetQueryParams(map[string]string{
216-
"act": "user",
217-
"nodetype": nodeType,
216+
"act": "user",
217+
"node_type": nodeType,
218218
}).
219219
ForceContentType("application/json").
220220
Get(c.APIHost)
@@ -239,22 +239,21 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
239239
user.UID = response.Get("data").GetIndex(i).Get("id").MustInt()
240240
switch c.NodeType {
241241
case "Shadowsocks":
242-
user.Email = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("secret").MustString()
243-
user.Passwd = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("secret").MustString()
244-
user.Method = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("cipher").MustString()
245-
user.SpeedLimit = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("speed_limit").MustUint64() * 1000000 / 8
246-
user.DeviceLimit = response.Get("data").GetIndex(i).Get("shadowsocks_user").Get("device_limit").MustInt()
242+
user.Email = response.Get("data").GetIndex(i).Get("secret").MustString()
243+
user.Passwd = response.Get("data").GetIndex(i).Get("secret").MustString()
244+
user.Method = response.Get("data").GetIndex(i).Get("cipher").MustString()
245+
user.SpeedLimit = response.Get("data").GetIndex(i).Get("st").MustUint64() * 1000000 / 8
246+
user.DeviceLimit = response.Get("data").GetIndex(i).Get("dt").MustInt()
247247
case "Trojan":
248-
user.UUID = response.Get("data").GetIndex(i).Get("trojan_user").Get("password").MustString()
249-
user.Email = response.Get("data").GetIndex(i).Get("trojan_user").Get("password").MustString()
250-
user.SpeedLimit = response.Get("data").GetIndex(i).Get("trojan_user").Get("speed_limit").MustUint64() * 1000000 / 8
251-
user.DeviceLimit = response.Get("data").GetIndex(i).Get("trojan_user").Get("device_limit").MustInt()
248+
user.UUID = response.Get("data").GetIndex(i).Get("password").MustString()
249+
user.Email = response.Get("data").GetIndex(i).Get("password").MustString()
250+
user.SpeedLimit = response.Get("data").GetIndex(i).Get("st").MustUint64() * 1000000 / 8
251+
user.DeviceLimit = response.Get("data").GetIndex(i).Get("dt").MustInt()
252252
case "V2ray", "Vmess", "Vless":
253-
user.UUID = response.Get("data").GetIndex(i).Get("v2ray_user").Get("uuid").MustString()
254-
user.Email = response.Get("data").GetIndex(i).Get("v2ray_user").Get("email").MustString()
255-
user.AlterID = uint16(response.Get("data").GetIndex(i).Get("v2ray_user").Get("alter_id").MustUint64())
256-
user.SpeedLimit = response.Get("data").GetIndex(i).Get("v2ray_user").Get("speed_limit").MustUint64() * 1000000 / 8
257-
user.DeviceLimit = response.Get("data").GetIndex(i).Get("v2ray_user").Get("device_limit").MustInt()
253+
user.UUID = response.Get("data").GetIndex(i).Get("uuid").MustString()
254+
user.Email = user.UUID + "@x.com"
255+
user.SpeedLimit = response.Get("data").GetIndex(i).Get("st").MustUint64() * 1000000 / 8
256+
user.DeviceLimit = response.Get("data").GetIndex(i).Get("dt").MustInt()
258257
}
259258
if c.SpeedLimit > 0 {
260259
user.SpeedLimit = uint64((c.SpeedLimit * 1000000) / 8)
@@ -283,8 +282,8 @@ func (c *APIClient) ReportUserTraffic(userTraffic *[]api.UserTraffic) error {
283282
res, err := c.client.R().
284283
SetQueryParam("node_id", strconv.Itoa(c.NodeID)).
285284
SetQueryParams(map[string]string{
286-
"act": "submit",
287-
"nodetype": strings.ToLower(c.NodeType),
285+
"act": "submit",
286+
"node_type": strings.ToLower(c.NodeType),
288287
}).
289288
SetBody(data).
290289
ForceContentType("application/json").
@@ -327,8 +326,8 @@ func (c *APIClient) ReportNodeStatus(nodeStatus *api.NodeStatus) (err error) {
327326
res, err := c.client.R().
328327
SetQueryParam("node_id", strconv.Itoa(c.NodeID)).
329328
SetQueryParams(map[string]string{
330-
"act": "nodestatus",
331-
"nodetype": strings.ToLower(c.NodeType),
329+
"act": "nodestatus",
330+
"node_type": strings.ToLower(c.NodeType),
332331
}).
333332
SetBody(systemload).
334333
ForceContentType("application/json").
@@ -350,8 +349,8 @@ func (c *APIClient) ReportNodeOnlineUsers(onlineUserList *[]api.OnlineUser) erro
350349
res, err := c.client.R().
351350
SetQueryParam("node_id", strconv.Itoa(c.NodeID)).
352351
SetQueryParams(map[string]string{
353-
"act": "onlineusers",
354-
"nodetype": strings.ToLower(c.NodeType),
352+
"act": "onlineusers",
353+
"node_type": strings.ToLower(c.NodeType),
355354
}).
356355
SetBody(data).
357356
ForceContentType("application/json").
@@ -365,6 +364,26 @@ func (c *APIClient) ReportNodeOnlineUsers(onlineUserList *[]api.OnlineUser) erro
365364

366365
// ReportIllegal implements the API interface
367366
func (c *APIClient) ReportIllegal(detectResultList *[]api.DetectResult) error {
367+
data := make([]IllegalItem, len(*detectResultList))
368+
for i, r := range *detectResultList {
369+
data[i] = IllegalItem{
370+
UID: r.UID,
371+
}
372+
}
373+
374+
res, err := c.client.R().
375+
SetQueryParam("node_id", strconv.Itoa(c.NodeID)).
376+
SetQueryParams(map[string]string{
377+
"act": "illegal",
378+
"node_type": strings.ToLower(c.NodeType),
379+
}).
380+
SetBody(data).
381+
ForceContentType("application/json").
382+
Post(c.APIHost)
383+
_, err = c.parseResponse(res, "", err)
384+
if err != nil {
385+
return err
386+
}
368387
return nil
369388
}
370389

@@ -423,7 +442,7 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
423442
var enableTLS bool
424443
var enableVless bool
425444
var enableReality bool
426-
var alterID uint16 = 0
445+
var vlessFlow string
427446

428447
tmpInboundInfo := nodeInfoResponse.Get("inbounds").MustArray()
429448
marshalByte, _ := json.Marshal(tmpInboundInfo[0].(map[string]interface{}))
@@ -436,6 +455,12 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
436455
case "ws":
437456
path = inboundInfo.Get("streamSettings").Get("wsSettings").Get("path").MustString()
438457
host = inboundInfo.Get("streamSettings").Get("wsSettings").Get("headers").Get("Host").MustString()
458+
case "httpupgrade":
459+
host = inboundInfo.Get("streamSettings").Get("httpupgradeSettings").Get("Host").MustString()
460+
path = inboundInfo.Get("streamSettings").Get("httpupgradeSettings").Get("path").MustString()
461+
case "splithttp":
462+
host = inboundInfo.Get("streamSettings").Get("splithttpSettings").Get("Host").MustString()
463+
path = inboundInfo.Get("streamSettings").Get("splithttpSettings").Get("path").MustString()
439464
case "grpc":
440465
if data, ok := inboundInfo.Get("streamSettings").Get("grpcSettings").CheckGet("serviceName"); ok {
441466
serviceName = data.MustString()
@@ -448,12 +473,11 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
448473
header = httpHeader
449474
}
450475
}
451-
452476
}
453477

454478
enableTLS = inboundInfo.Get("streamSettings").Get("security").MustString() == "tls"
455-
enableVless = inboundInfo.Get("streamSettings").Get("security").MustString() == "reality"
456-
enableReality = enableVless
479+
enableVless = inboundInfo.Get("protocol").MustString() == "vless"
480+
enableReality = inboundInfo.Get("streamSettings").Get("security").MustString() == "reality"
457481

458482
realityConfig := new(api.REALITYConfig)
459483
if enableVless {
@@ -470,19 +494,26 @@ func (c *APIClient) ParseV2rayNodeResponse(nodeInfoResponse *simplejson.Json) (*
470494
}
471495
}
472496

497+
// XTLS only supports TLS and REALITY directly for now
498+
if transportProtocol == "tcp" && enableReality {
499+
vlessFlow = "xtls-rprx-vision"
500+
} else {
501+
vlessFlow = c.VlessFlow
502+
}
503+
473504
// Create GeneralNodeInfo
474505
// AlterID will be updated after next sync
475506
nodeInfo := &api.NodeInfo{
476507
NodeType: c.NodeType,
477508
NodeID: c.NodeID,
478509
Port: port,
479-
AlterID: alterID,
510+
AlterID: 0,
480511
TransportProtocol: transportProtocol,
481512
EnableTLS: enableTLS,
482513
Path: path,
483514
Host: host,
484515
EnableVless: enableVless,
485-
VlessFlow: c.VlessFlow,
516+
VlessFlow: vlessFlow,
486517
ServiceName: serviceName,
487518
Header: header,
488519
EnableREALITY: enableReality,

cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
var (
10-
version = "0.9.4"
10+
version = "0.9.5"
1111
codename = "XrayR"
1212
intro = "A Xray backend that supports many panels"
1313
)

0 commit comments

Comments
 (0)