2022-08-22 18:53:47 +08:00
|
|
|
package option
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/sagernet/sing-box/common/json"
|
|
|
|
C "github.com/sagernet/sing-box/constant"
|
|
|
|
E "github.com/sagernet/sing/common/exceptions"
|
|
|
|
)
|
|
|
|
|
2022-08-22 20:20:56 +08:00
|
|
|
type _V2RayTransportOptions struct {
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
GRPCOptions V2RayGRPCOptions `json:"-"`
|
|
|
|
WebsocketOptions V2RayWebsocketOptions `json:"-"`
|
2022-08-22 18:53:47 +08:00
|
|
|
}
|
|
|
|
|
2022-08-22 20:20:56 +08:00
|
|
|
type V2RayTransportOptions _V2RayTransportOptions
|
2022-08-22 18:53:47 +08:00
|
|
|
|
2022-08-22 20:20:56 +08:00
|
|
|
func (o V2RayTransportOptions) MarshalJSON() ([]byte, error) {
|
2022-08-22 18:53:47 +08:00
|
|
|
var v any
|
|
|
|
switch o.Type {
|
|
|
|
case "":
|
|
|
|
return nil, nil
|
|
|
|
case C.V2RayTransportTypeGRPC:
|
|
|
|
v = o.GRPCOptions
|
2022-08-22 20:20:56 +08:00
|
|
|
case C.V2RayTransportTypeWebsocket:
|
|
|
|
v = o.WebsocketOptions
|
2022-08-22 18:53:47 +08:00
|
|
|
default:
|
|
|
|
return nil, E.New("unknown transport type: " + o.Type)
|
|
|
|
}
|
2022-08-22 20:20:56 +08:00
|
|
|
return MarshallObjects((_V2RayTransportOptions)(o), v)
|
2022-08-22 18:53:47 +08:00
|
|
|
}
|
|
|
|
|
2022-08-22 20:20:56 +08:00
|
|
|
func (o *V2RayTransportOptions) UnmarshalJSON(bytes []byte) error {
|
|
|
|
err := json.Unmarshal(bytes, (*_V2RayTransportOptions)(o))
|
2022-08-22 18:53:47 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var v any
|
|
|
|
switch o.Type {
|
|
|
|
case C.V2RayTransportTypeGRPC:
|
|
|
|
v = &o.GRPCOptions
|
|
|
|
default:
|
|
|
|
return E.New("unknown transport type: " + o.Type)
|
|
|
|
}
|
2022-08-22 20:20:56 +08:00
|
|
|
err = UnmarshallExcluded(bytes, (*_V2RayTransportOptions)(o), v)
|
2022-08-22 18:53:47 +08:00
|
|
|
if err != nil {
|
|
|
|
return E.Cause(err, "vmess transport options")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-08-22 20:20:56 +08:00
|
|
|
/*type _V2RayOutboundTransportOptions struct {
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
GRPCOptions V2RayGRPCOptions `json:"-"`
|
|
|
|
WebsocketOptions V2RayWebsocketOptions `json:"-"`
|
2022-08-22 18:53:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type V2RayOutboundTransportOptions _V2RayOutboundTransportOptions
|
|
|
|
|
|
|
|
func (o V2RayOutboundTransportOptions) MarshalJSON() ([]byte, error) {
|
|
|
|
var v any
|
|
|
|
switch o.Type {
|
|
|
|
case "":
|
|
|
|
return nil, nil
|
|
|
|
case C.V2RayTransportTypeGRPC:
|
|
|
|
v = o.GRPCOptions
|
2022-08-22 20:20:56 +08:00
|
|
|
case C.V2RayTransportTypeWebsocket:
|
|
|
|
v = o.WebsocketOptions
|
2022-08-22 18:53:47 +08:00
|
|
|
default:
|
|
|
|
return nil, E.New("unknown transport type: " + o.Type)
|
|
|
|
}
|
|
|
|
return MarshallObjects((_V2RayOutboundTransportOptions)(o), v)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o *V2RayOutboundTransportOptions) UnmarshalJSON(bytes []byte) error {
|
|
|
|
err := json.Unmarshal(bytes, (*_V2RayOutboundTransportOptions)(o))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var v any
|
|
|
|
switch o.Type {
|
|
|
|
case C.V2RayTransportTypeGRPC:
|
|
|
|
v = &o.GRPCOptions
|
2022-08-22 20:20:56 +08:00
|
|
|
case C.V2RayTransportTypeWebsocket:
|
|
|
|
v = &o.WebsocketOptions
|
2022-08-22 18:53:47 +08:00
|
|
|
default:
|
|
|
|
return E.New("unknown transport type: " + o.Type)
|
|
|
|
}
|
|
|
|
err = UnmarshallExcluded(bytes, (*_V2RayOutboundTransportOptions)(o), v)
|
|
|
|
if err != nil {
|
|
|
|
return E.Cause(err, "vmess transport options")
|
|
|
|
}
|
|
|
|
return nil
|
2022-08-22 20:20:56 +08:00
|
|
|
}*/
|
2022-08-22 18:53:47 +08:00
|
|
|
|
|
|
|
type V2RayGRPCOptions struct {
|
|
|
|
ServiceName string `json:"service_name,omitempty"`
|
|
|
|
}
|
2022-08-22 20:20:56 +08:00
|
|
|
|
|
|
|
type V2RayWebsocketOptions struct {
|
|
|
|
Path string `json:"path,omitempty"`
|
|
|
|
Headers map[string]string `json:"headers,omitempty"`
|
|
|
|
MaxEarlyData uint32 `json:"max_early_data,omitempty"`
|
|
|
|
EarlyDataHeaderName string `json:"early_data_header_name,omitempty"`
|
|
|
|
}
|