-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
v2ray_transport.go
87 lines (78 loc) · 2.73 KB
/
v2ray_transport.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package option
import (
"github.com/sagernet/sing-box/common/json"
C "github.com/sagernet/sing-box/constant"
E "github.com/sagernet/sing/common/exceptions"
)
type _V2RayTransportOptions struct {
Type string `json:"type,omitempty"`
HTTPOptions V2RayHTTPOptions `json:"-"`
WebsocketOptions V2RayWebsocketOptions `json:"-"`
QUICOptions V2RayQUICOptions `json:"-"`
GRPCOptions V2RayGRPCOptions `json:"-"`
}
type V2RayTransportOptions _V2RayTransportOptions
func (o V2RayTransportOptions) MarshalJSON() ([]byte, error) {
var v any
switch o.Type {
case "":
return nil, nil
case C.V2RayTransportTypeHTTP:
v = o.HTTPOptions
case C.V2RayTransportTypeWebsocket:
v = o.WebsocketOptions
case C.V2RayTransportTypeQUIC:
v = o.QUICOptions
case C.V2RayTransportTypeGRPC:
v = o.GRPCOptions
default:
return nil, E.New("unknown transport type: " + o.Type)
}
return MarshallObjects((_V2RayTransportOptions)(o), v)
}
func (o *V2RayTransportOptions) UnmarshalJSON(bytes []byte) error {
err := json.Unmarshal(bytes, (*_V2RayTransportOptions)(o))
if err != nil {
return err
}
var v any
switch o.Type {
case C.V2RayTransportTypeHTTP:
v = &o.HTTPOptions
case C.V2RayTransportTypeWebsocket:
v = &o.WebsocketOptions
case C.V2RayTransportTypeQUIC:
v = &o.QUICOptions
case C.V2RayTransportTypeGRPC:
v = &o.GRPCOptions
default:
return E.New("unknown transport type: " + o.Type)
}
err = UnmarshallExcluded(bytes, (*_V2RayTransportOptions)(o), v)
if err != nil {
return E.Cause(err, "vmess transport options")
}
return nil
}
type V2RayHTTPOptions struct {
Host Listable[string] `json:"host,omitempty"`
Path string `json:"path,omitempty"`
Method string `json:"method,omitempty"`
Headers map[string]Listable[string] `json:"headers,omitempty"`
IdleTimeout Duration `json:"idle_timeout,omitempty"`
PingTimeout Duration `json:"ping_timeout,omitempty"`
}
type V2RayWebsocketOptions struct {
Path string `json:"path,omitempty"`
Headers map[string]Listable[string] `json:"headers,omitempty"`
MaxEarlyData uint32 `json:"max_early_data,omitempty"`
EarlyDataHeaderName string `json:"early_data_header_name,omitempty"`
}
type V2RayQUICOptions struct{}
type V2RayGRPCOptions struct {
ServiceName string `json:"service_name,omitempty"`
IdleTimeout Duration `json:"idle_timeout,omitempty"`
PingTimeout Duration `json:"ping_timeout,omitempty"`
PermitWithoutStream bool `json:"permit_without_stream,omitempty"`
ForceLite bool `json:"-"` // for test
}