Add trojan inbound/outbound

This commit is contained in:
世界
2022-08-08 08:56:04 +08:00
parent 6e057a3318
commit 769521cafe
19 changed files with 521 additions and 9 deletions

View File

@@ -18,6 +18,7 @@ type _Inbound struct {
MixedOptions HTTPMixedInboundOptions `json:"-"`
ShadowsocksOptions ShadowsocksInboundOptions `json:"-"`
VMessOptions VMessInboundOptions `json:"-"`
TrojanOptions TrojanInboundOptions `json:"-"`
}
type Inbound _Inbound
@@ -43,6 +44,8 @@ func (h Inbound) MarshalJSON() ([]byte, error) {
v = h.ShadowsocksOptions
case C.TypeVMess:
v = h.VMessOptions
case C.TypeTrojan:
v = h.TrojanOptions
default:
return nil, E.New("unknown inbound type: ", h.Type)
}
@@ -74,6 +77,8 @@ func (h *Inbound) UnmarshalJSON(bytes []byte) error {
v = &h.ShadowsocksOptions
case C.TypeVMess:
v = &h.VMessOptions
case C.TypeTrojan:
v = &h.TrojanOptions
default:
return E.New("unknown inbound type: ", h.Type)
}

View File

@@ -15,6 +15,7 @@ type _Outbound struct {
HTTPOptions HTTPOutboundOptions `json:"-"`
ShadowsocksOptions ShadowsocksOutboundOptions `json:"-"`
VMessOptions VMessOutboundOptions `json:"-"`
TrojanOptions TrojanOutboundOptions `json:"-"`
SelectorOptions SelectorOutboundOptions `json:"-"`
}
@@ -35,6 +36,8 @@ func (h Outbound) MarshalJSON() ([]byte, error) {
v = h.ShadowsocksOptions
case C.TypeVMess:
v = h.VMessOptions
case C.TypeTrojan:
v = h.TrojanOptions
case C.TypeSelector:
v = h.SelectorOptions
default:
@@ -62,6 +65,8 @@ func (h *Outbound) UnmarshalJSON(bytes []byte) error {
v = &h.ShadowsocksOptions
case C.TypeVMess:
v = &h.VMessOptions
case C.TypeTrojan:
v = &h.TrojanOptions
case C.TypeSelector:
v = &h.SelectorOptions
default:

21
option/trojan.go Normal file
View File

@@ -0,0 +1,21 @@
package option
type TrojanInboundOptions struct {
ListenOptions
Users []TrojanUser `json:"users,omitempty"`
TLS *InboundTLSOptions `json:"tls,omitempty"`
}
type TrojanUser struct {
Name string `json:"name"`
Password string `json:"password"`
}
type TrojanOutboundOptions struct {
OutboundDialerOptions
ServerOptions
Password string `json:"password"`
Network NetworkList `json:"network,omitempty"`
TLSOptions *OutboundTLSOptions `json:"tls,omitempty"`
MultiplexOptions *MultiplexOptions `json:"multiplex,omitempty"`
}