mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-27 11:01:27 +00:00
Revert: move common.go to common
This commit is contained in:
parent
4eb3acb4dd
commit
58bca70dfb
|
@ -1,4 +1,4 @@
|
||||||
package common
|
package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
|
@ -1,9 +0,0 @@
|
||||||
package common
|
|
||||||
|
|
||||||
import "github.com/xtls/xray-core/common/errors"
|
|
||||||
|
|
||||||
type errPathObjHolder struct{}
|
|
||||||
|
|
||||||
func newError(values ...interface{}) *errors.Error {
|
|
||||||
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
|
||||||
}
|
|
|
@ -1,7 +1,8 @@
|
||||||
package common_test
|
package conf_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/xtls/xray-core/infra/conf"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -11,12 +12,11 @@ import (
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
. "github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStringListUnmarshalError(t *testing.T) {
|
func TestStringListUnmarshalError(t *testing.T) {
|
||||||
rawJSON := `1234`
|
rawJSON := `1234`
|
||||||
list := new(StringList)
|
list := new(conf.StringList)
|
||||||
err := json.Unmarshal([]byte(rawJSON), list)
|
err := json.Unmarshal([]byte(rawJSON), list)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("expected error, but got nil")
|
t.Error("expected error, but got nil")
|
||||||
|
@ -25,7 +25,7 @@ func TestStringListUnmarshalError(t *testing.T) {
|
||||||
|
|
||||||
func TestStringListLen(t *testing.T) {
|
func TestStringListLen(t *testing.T) {
|
||||||
rawJSON := `"a, b, c, d"`
|
rawJSON := `"a, b, c, d"`
|
||||||
var list StringList
|
var list conf.StringList
|
||||||
err := json.Unmarshal([]byte(rawJSON), &list)
|
err := json.Unmarshal([]byte(rawJSON), &list)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
if r := cmp.Diff([]string(list), []string{"a", " b", " c", " d"}); r != "" {
|
if r := cmp.Diff([]string(list), []string{"a", " b", " c", " d"}); r != "" {
|
||||||
|
@ -35,7 +35,7 @@ func TestStringListLen(t *testing.T) {
|
||||||
|
|
||||||
func TestIPParsing(t *testing.T) {
|
func TestIPParsing(t *testing.T) {
|
||||||
rawJSON := "\"8.8.8.8\""
|
rawJSON := "\"8.8.8.8\""
|
||||||
var address Address
|
var address conf.Address
|
||||||
err := json.Unmarshal([]byte(rawJSON), &address)
|
err := json.Unmarshal([]byte(rawJSON), &address)
|
||||||
common.Must(err)
|
common.Must(err)
|
||||||
if r := cmp.Diff(address.IP(), net.IP{8, 8, 8, 8}); r != "" {
|
if r := cmp.Diff(address.IP(), net.IP{8, 8, 8, 8}); r != "" {
|
||||||
|
@ -45,7 +45,7 @@ func TestIPParsing(t *testing.T) {
|
||||||
|
|
||||||
func TestDomainParsing(t *testing.T) {
|
func TestDomainParsing(t *testing.T) {
|
||||||
rawJSON := "\"example.com\""
|
rawJSON := "\"example.com\""
|
||||||
var address Address
|
var address conf.Address
|
||||||
common.Must(json.Unmarshal([]byte(rawJSON), &address))
|
common.Must(json.Unmarshal([]byte(rawJSON), &address))
|
||||||
if address.Domain() != "example.com" {
|
if address.Domain() != "example.com" {
|
||||||
t.Error("domain: ", address.Domain())
|
t.Error("domain: ", address.Domain())
|
||||||
|
@ -55,7 +55,7 @@ func TestDomainParsing(t *testing.T) {
|
||||||
func TestURLParsing(t *testing.T) {
|
func TestURLParsing(t *testing.T) {
|
||||||
{
|
{
|
||||||
rawJSON := "\"https://dns.google/dns-query\""
|
rawJSON := "\"https://dns.google/dns-query\""
|
||||||
var address Address
|
var address conf.Address
|
||||||
common.Must(json.Unmarshal([]byte(rawJSON), &address))
|
common.Must(json.Unmarshal([]byte(rawJSON), &address))
|
||||||
if address.Domain() != "https://dns.google/dns-query" {
|
if address.Domain() != "https://dns.google/dns-query" {
|
||||||
t.Error("URL: ", address.Domain())
|
t.Error("URL: ", address.Domain())
|
||||||
|
@ -63,7 +63,7 @@ func TestURLParsing(t *testing.T) {
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
rawJSON := "\"https+local://dns.google/dns-query\""
|
rawJSON := "\"https+local://dns.google/dns-query\""
|
||||||
var address Address
|
var address conf.Address
|
||||||
common.Must(json.Unmarshal([]byte(rawJSON), &address))
|
common.Must(json.Unmarshal([]byte(rawJSON), &address))
|
||||||
if address.Domain() != "https+local://dns.google/dns-query" {
|
if address.Domain() != "https+local://dns.google/dns-query" {
|
||||||
t.Error("URL: ", address.Domain())
|
t.Error("URL: ", address.Domain())
|
||||||
|
@ -73,7 +73,7 @@ func TestURLParsing(t *testing.T) {
|
||||||
|
|
||||||
func TestInvalidAddressJson(t *testing.T) {
|
func TestInvalidAddressJson(t *testing.T) {
|
||||||
rawJSON := "1234"
|
rawJSON := "1234"
|
||||||
var address Address
|
var address conf.Address
|
||||||
err := json.Unmarshal([]byte(rawJSON), &address)
|
err := json.Unmarshal([]byte(rawJSON), &address)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("nil error")
|
t.Error("nil error")
|
||||||
|
@ -81,7 +81,7 @@ func TestInvalidAddressJson(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringNetwork(t *testing.T) {
|
func TestStringNetwork(t *testing.T) {
|
||||||
var network Network
|
var network conf.Network
|
||||||
common.Must(json.Unmarshal([]byte(`"tcp"`), &network))
|
common.Must(json.Unmarshal([]byte(`"tcp"`), &network))
|
||||||
if v := network.Build(); v != net.Network_TCP {
|
if v := network.Build(); v != net.Network_TCP {
|
||||||
t.Error("network: ", v)
|
t.Error("network: ", v)
|
||||||
|
@ -89,7 +89,7 @@ func TestStringNetwork(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArrayNetworkList(t *testing.T) {
|
func TestArrayNetworkList(t *testing.T) {
|
||||||
var list NetworkList
|
var list conf.NetworkList
|
||||||
common.Must(json.Unmarshal([]byte("[\"Tcp\"]"), &list))
|
common.Must(json.Unmarshal([]byte("[\"Tcp\"]"), &list))
|
||||||
|
|
||||||
nlist := list.Build()
|
nlist := list.Build()
|
||||||
|
@ -102,7 +102,7 @@ func TestArrayNetworkList(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringNetworkList(t *testing.T) {
|
func TestStringNetworkList(t *testing.T) {
|
||||||
var list NetworkList
|
var list conf.NetworkList
|
||||||
common.Must(json.Unmarshal([]byte("\"TCP, ip\""), &list))
|
common.Must(json.Unmarshal([]byte("\"TCP, ip\""), &list))
|
||||||
|
|
||||||
nlist := list.Build()
|
nlist := list.Build()
|
||||||
|
@ -115,7 +115,7 @@ func TestStringNetworkList(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidNetworkJson(t *testing.T) {
|
func TestInvalidNetworkJson(t *testing.T) {
|
||||||
var list NetworkList
|
var list conf.NetworkList
|
||||||
err := json.Unmarshal([]byte("0"), &list)
|
err := json.Unmarshal([]byte("0"), &list)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("nil error")
|
t.Error("nil error")
|
||||||
|
@ -123,10 +123,10 @@ func TestInvalidNetworkJson(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIntPort(t *testing.T) {
|
func TestIntPort(t *testing.T) {
|
||||||
var portRange PortRange
|
var portRange conf.PortRange
|
||||||
common.Must(json.Unmarshal([]byte("1234"), &portRange))
|
common.Must(json.Unmarshal([]byte("1234"), &portRange))
|
||||||
|
|
||||||
if r := cmp.Diff(portRange, PortRange{
|
if r := cmp.Diff(portRange, conf.PortRange{
|
||||||
From: 1234, To: 1234,
|
From: 1234, To: 1234,
|
||||||
}); r != "" {
|
}); r != "" {
|
||||||
t.Error(r)
|
t.Error(r)
|
||||||
|
@ -134,7 +134,7 @@ func TestIntPort(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOverRangeIntPort(t *testing.T) {
|
func TestOverRangeIntPort(t *testing.T) {
|
||||||
var portRange PortRange
|
var portRange conf.PortRange
|
||||||
err := json.Unmarshal([]byte("70000"), &portRange)
|
err := json.Unmarshal([]byte("70000"), &portRange)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("nil error")
|
t.Error("nil error")
|
||||||
|
@ -149,10 +149,10 @@ func TestOverRangeIntPort(t *testing.T) {
|
||||||
func TestEnvPort(t *testing.T) {
|
func TestEnvPort(t *testing.T) {
|
||||||
common.Must(os.Setenv("PORT", "1234"))
|
common.Must(os.Setenv("PORT", "1234"))
|
||||||
|
|
||||||
var portRange PortRange
|
var portRange conf.PortRange
|
||||||
common.Must(json.Unmarshal([]byte("\"env:PORT\""), &portRange))
|
common.Must(json.Unmarshal([]byte("\"env:PORT\""), &portRange))
|
||||||
|
|
||||||
if r := cmp.Diff(portRange, PortRange{
|
if r := cmp.Diff(portRange, conf.PortRange{
|
||||||
From: 1234, To: 1234,
|
From: 1234, To: 1234,
|
||||||
}); r != "" {
|
}); r != "" {
|
||||||
t.Error(r)
|
t.Error(r)
|
||||||
|
@ -160,10 +160,10 @@ func TestEnvPort(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSingleStringPort(t *testing.T) {
|
func TestSingleStringPort(t *testing.T) {
|
||||||
var portRange PortRange
|
var portRange conf.PortRange
|
||||||
common.Must(json.Unmarshal([]byte("\"1234\""), &portRange))
|
common.Must(json.Unmarshal([]byte("\"1234\""), &portRange))
|
||||||
|
|
||||||
if r := cmp.Diff(portRange, PortRange{
|
if r := cmp.Diff(portRange, conf.PortRange{
|
||||||
From: 1234, To: 1234,
|
From: 1234, To: 1234,
|
||||||
}); r != "" {
|
}); r != "" {
|
||||||
t.Error(r)
|
t.Error(r)
|
||||||
|
@ -171,10 +171,10 @@ func TestSingleStringPort(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStringPairPort(t *testing.T) {
|
func TestStringPairPort(t *testing.T) {
|
||||||
var portRange PortRange
|
var portRange conf.PortRange
|
||||||
common.Must(json.Unmarshal([]byte("\"1234-5678\""), &portRange))
|
common.Must(json.Unmarshal([]byte("\"1234-5678\""), &portRange))
|
||||||
|
|
||||||
if r := cmp.Diff(portRange, PortRange{
|
if r := cmp.Diff(portRange, conf.PortRange{
|
||||||
From: 1234, To: 5678,
|
From: 1234, To: 5678,
|
||||||
}); r != "" {
|
}); r != "" {
|
||||||
t.Error(r)
|
t.Error(r)
|
||||||
|
@ -182,7 +182,7 @@ func TestStringPairPort(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOverRangeStringPort(t *testing.T) {
|
func TestOverRangeStringPort(t *testing.T) {
|
||||||
var portRange PortRange
|
var portRange conf.PortRange
|
||||||
err := json.Unmarshal([]byte("\"65536\""), &portRange)
|
err := json.Unmarshal([]byte("\"65536\""), &portRange)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("nil error")
|
t.Error("nil error")
|
||||||
|
@ -205,7 +205,7 @@ func TestOverRangeStringPort(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUserParsing(t *testing.T) {
|
func TestUserParsing(t *testing.T) {
|
||||||
user := new(User)
|
user := new(conf.User)
|
||||||
common.Must(json.Unmarshal([]byte(`{
|
common.Must(json.Unmarshal([]byte(`{
|
||||||
"id": "96edb838-6d68-42ef-a933-25f7ac3a9d09",
|
"id": "96edb838-6d68-42ef-a933-25f7ac3a9d09",
|
||||||
"email": "love@example.com",
|
"email": "love@example.com",
|
||||||
|
@ -223,7 +223,7 @@ func TestUserParsing(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidUserJson(t *testing.T) {
|
func TestInvalidUserJson(t *testing.T) {
|
||||||
user := new(User)
|
user := new(conf.User)
|
||||||
err := json.Unmarshal([]byte(`{"email": 1234}`), user)
|
err := json.Unmarshal([]byte(`{"email": 1234}`), user)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("nil error")
|
t.Error("nil error")
|
|
@ -12,28 +12,27 @@ import (
|
||||||
"github.com/xtls/xray-core/common/matcher/geoip"
|
"github.com/xtls/xray-core/common/matcher/geoip"
|
||||||
"github.com/xtls/xray-core/common/matcher/geosite"
|
"github.com/xtls/xray-core/common/matcher/geosite"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type NameServerConfig struct {
|
type NameServerConfig struct {
|
||||||
Address *common.Address
|
Address *Address
|
||||||
Port uint16
|
Port uint16
|
||||||
Domains []string
|
Domains []string
|
||||||
ExpectIPs common.StringList
|
ExpectIPs StringList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *NameServerConfig) UnmarshalJSON(data []byte) error {
|
func (c *NameServerConfig) UnmarshalJSON(data []byte) error {
|
||||||
var address common.Address
|
var address Address
|
||||||
if err := json.Unmarshal(data, &address); err == nil {
|
if err := json.Unmarshal(data, &address); err == nil {
|
||||||
c.Address = &address
|
c.Address = &address
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var advanced struct {
|
var advanced struct {
|
||||||
Address *common.Address `json:"address"`
|
Address *Address `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Domains []string `json:"domains"`
|
Domains []string `json:"domains"`
|
||||||
ExpectIPs common.StringList `json:"expectIps"`
|
ExpectIPs StringList `json:"expectIps"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(data, &advanced); err == nil {
|
if err := json.Unmarshal(data, &advanced); err == nil {
|
||||||
c.Address = advanced.Address
|
c.Address = advanced.Address
|
||||||
|
@ -91,15 +90,15 @@ func (c *NameServerConfig) Build() (*dns.NameServer, error) {
|
||||||
|
|
||||||
// DNSConfig is a JSON serializable object for dns.Config.
|
// DNSConfig is a JSON serializable object for dns.Config.
|
||||||
type DNSConfig struct {
|
type DNSConfig struct {
|
||||||
Servers []*NameServerConfig `json:"servers"`
|
Servers []*NameServerConfig `json:"servers"`
|
||||||
Hosts map[string]*common.Address `json:"hosts"`
|
Hosts map[string]*Address `json:"hosts"`
|
||||||
ClientIP *common.Address `json:"clientIp"`
|
ClientIP *Address `json:"clientIp"`
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag"`
|
||||||
QueryStrategy string `json:"queryStrategy"`
|
QueryStrategy string `json:"queryStrategy"`
|
||||||
DisableCache bool `json:"disableCache"`
|
DisableCache bool `json:"disableCache"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHostMapping(addr *common.Address) *dns.Config_HostMapping {
|
func getHostMapping(addr *Address) *dns.Config_HostMapping {
|
||||||
if addr.Family().IsIP() {
|
if addr.Family().IsIP() {
|
||||||
return &dns.Config_HostMapping{
|
return &dns.Config_HostMapping{
|
||||||
Ip: [][]byte{[]byte(addr.IP())},
|
Ip: [][]byte{[]byte(addr.IP())},
|
||||||
|
|
|
@ -3,14 +3,13 @@ package conf
|
||||||
import (
|
import (
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
"github.com/xtls/xray-core/proxy/dns"
|
"github.com/xtls/xray-core/proxy/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DNSOutboundConfig struct {
|
type DNSOutboundConfig struct {
|
||||||
Network common.Network `json:"network"`
|
Network Network `json:"network"`
|
||||||
Address *common.Address `json:"address"`
|
Address *Address `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *DNSOutboundConfig) Build() (proto.Message, error) {
|
func (c *DNSOutboundConfig) Build() (proto.Message, error) {
|
||||||
|
|
|
@ -2,17 +2,16 @@ package conf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
"github.com/xtls/xray-core/proxy/dokodemo"
|
"github.com/xtls/xray-core/proxy/dokodemo"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DokodemoConfig struct {
|
type DokodemoConfig struct {
|
||||||
Host *common.Address `json:"address"`
|
Host *Address `json:"address"`
|
||||||
PortValue uint16 `json:"port"`
|
PortValue uint16 `json:"port"`
|
||||||
NetworkList *common.NetworkList `json:"network"`
|
NetworkList *NetworkList `json:"network"`
|
||||||
TimeoutValue uint32 `json:"timeout"`
|
TimeoutValue uint32 `json:"timeout"`
|
||||||
Redirect bool `json:"followRedirect"`
|
Redirect bool `json:"followRedirect"`
|
||||||
UserLevel uint32 `json:"userLevel"`
|
UserLevel uint32 `json:"userLevel"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *DokodemoConfig) Build() (proto.Message, error) {
|
func (v *DokodemoConfig) Build() (proto.Message, error) {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
"github.com/xtls/xray-core/proxy/http"
|
"github.com/xtls/xray-core/proxy/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ func (c *HTTPServerConfig) Build() (proto.Message, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTPRemoteConfig struct {
|
type HTTPRemoteConfig struct {
|
||||||
Address *common.Address `json:"address"`
|
Address *Address `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Users []json.RawMessage `json:"users"`
|
Users []json.RawMessage `json:"users"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"github.com/xtls/xray-core/common/matcher/geoip"
|
"github.com/xtls/xray-core/common/matcher/geoip"
|
||||||
"github.com/xtls/xray-core/common/matcher/geosite"
|
"github.com/xtls/xray-core/common/matcher/geosite"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type RouterRulesConfig struct {
|
type RouterRulesConfig struct {
|
||||||
|
@ -19,8 +18,8 @@ type RouterRulesConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type BalancingRule struct {
|
type BalancingRule struct {
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag"`
|
||||||
Selectors common.StringList `json:"selector"`
|
Selectors StringList `json:"selector"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *BalancingRule) Build() (*router.BalancingRule, error) {
|
func (r *BalancingRule) Build() (*router.BalancingRule, error) {
|
||||||
|
@ -151,17 +150,17 @@ func ParseIP(s string) (*geoip.CIDR, error) {
|
||||||
func parseFieldRule(msg json.RawMessage) (*router.RoutingRule, error) {
|
func parseFieldRule(msg json.RawMessage) (*router.RoutingRule, error) {
|
||||||
type RawFieldRule struct {
|
type RawFieldRule struct {
|
||||||
RouterRule
|
RouterRule
|
||||||
Domain *common.StringList `json:"domain"`
|
Domain *StringList `json:"domain"`
|
||||||
Domains *common.StringList `json:"domains"`
|
Domains *StringList `json:"domains"`
|
||||||
IP *common.StringList `json:"ip"`
|
IP *StringList `json:"ip"`
|
||||||
Port *common.PortList `json:"port"`
|
Port *PortList `json:"port"`
|
||||||
Network *common.NetworkList `json:"network"`
|
Network *NetworkList `json:"network"`
|
||||||
SourceIP *common.StringList `json:"source"`
|
SourceIP *StringList `json:"source"`
|
||||||
SourcePort *common.PortList `json:"sourcePort"`
|
SourcePort *PortList `json:"sourcePort"`
|
||||||
User *common.StringList `json:"user"`
|
User *StringList `json:"user"`
|
||||||
InboundTag *common.StringList `json:"inboundTag"`
|
InboundTag *StringList `json:"inboundTag"`
|
||||||
Protocols *common.StringList `json:"protocol"`
|
Protocols *StringList `json:"protocol"`
|
||||||
Attributes string `json:"attrs"`
|
Attributes string `json:"attrs"`
|
||||||
}
|
}
|
||||||
rawFieldRule := new(RawFieldRule)
|
rawFieldRule := new(RawFieldRule)
|
||||||
err := json.Unmarshal(msg, rawFieldRule)
|
err := json.Unmarshal(msg, rawFieldRule)
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
"github.com/xtls/xray-core/proxy/shadowsocks"
|
"github.com/xtls/xray-core/proxy/shadowsocks"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ type ShadowsocksServerConfig struct {
|
||||||
Level byte `json:"level"`
|
Level byte `json:"level"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Users []*ShadowsocksUserConfig `json:"clients"`
|
Users []*ShadowsocksUserConfig `json:"clients"`
|
||||||
NetworkList *common.NetworkList `json:"network"`
|
NetworkList *NetworkList `json:"network"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
|
func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
|
||||||
|
@ -94,12 +93,12 @@ func (v *ShadowsocksServerConfig) Build() (proto.Message, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShadowsocksServerTarget struct {
|
type ShadowsocksServerTarget struct {
|
||||||
Address *common.Address `json:"address"`
|
Address *Address `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Cipher string `json:"method"`
|
Cipher string `json:"method"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Level byte `json:"level"`
|
Level byte `json:"level"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShadowsocksClientConfig struct {
|
type ShadowsocksClientConfig struct {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
"github.com/xtls/xray-core/proxy/socks"
|
"github.com/xtls/xray-core/proxy/socks"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -31,7 +30,7 @@ type SocksServerConfig struct {
|
||||||
AuthMethod string `json:"auth"`
|
AuthMethod string `json:"auth"`
|
||||||
Accounts []*SocksAccount `json:"accounts"`
|
Accounts []*SocksAccount `json:"accounts"`
|
||||||
UDP bool `json:"udp"`
|
UDP bool `json:"udp"`
|
||||||
Host *common.Address `json:"ip"`
|
Host *Address `json:"ip"`
|
||||||
Timeout uint32 `json:"timeout"`
|
Timeout uint32 `json:"timeout"`
|
||||||
UserLevel uint32 `json:"userLevel"`
|
UserLevel uint32 `json:"userLevel"`
|
||||||
}
|
}
|
||||||
|
@ -66,7 +65,7 @@ func (v *SocksServerConfig) Build() (proto.Message, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SocksRemoteConfig struct {
|
type SocksRemoteConfig struct {
|
||||||
Address *common.Address `json:"address"`
|
Address *Address `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Users []json.RawMessage `json:"users"`
|
Users []json.RawMessage `json:"users"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
"github.com/xtls/xray-core/transport/internet/headers/http"
|
"github.com/xtls/xray-core/transport/internet/headers/http"
|
||||||
"github.com/xtls/xray-core/transport/internet/headers/noop"
|
"github.com/xtls/xray-core/transport/internet/headers/noop"
|
||||||
"github.com/xtls/xray-core/transport/internet/headers/srtp"
|
"github.com/xtls/xray-core/transport/internet/headers/srtp"
|
||||||
|
@ -58,13 +57,13 @@ func (DTLSAuthenticator) Build() (proto.Message, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthenticatorRequest struct {
|
type AuthenticatorRequest struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Method string `json:"method"`
|
Method string `json:"method"`
|
||||||
Path common.StringList `json:"path"`
|
Path StringList `json:"path"`
|
||||||
Headers map[string]*common.StringList `json:"headers"`
|
Headers map[string]*StringList `json:"headers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func sortMapKeys(m map[string]*common.StringList) []string {
|
func sortMapKeys(m map[string]*StringList) []string {
|
||||||
var keys []string
|
var keys []string
|
||||||
for key := range m {
|
for key := range m {
|
||||||
keys = append(keys, key)
|
keys = append(keys, key)
|
||||||
|
@ -134,10 +133,10 @@ func (v *AuthenticatorRequest) Build() (*http.RequestConfig, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuthenticatorResponse struct {
|
type AuthenticatorResponse struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Reason string `json:"reason"`
|
Reason string `json:"reason"`
|
||||||
Headers map[string]*common.StringList `json:"headers"`
|
Headers map[string]*StringList `json:"headers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *AuthenticatorResponse) Build() (*http.ResponseConfig, error) {
|
func (v *AuthenticatorResponse) Build() (*http.ResponseConfig, error) {
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/xtls/xray-core/common/platform/filesystem"
|
"github.com/xtls/xray-core/common/platform/filesystem"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
"github.com/xtls/xray-core/transport/internet/domainsocket"
|
"github.com/xtls/xray-core/transport/internet/domainsocket"
|
||||||
"github.com/xtls/xray-core/transport/internet/http"
|
"github.com/xtls/xray-core/transport/internet/http"
|
||||||
|
@ -180,8 +179,8 @@ func (c *WebSocketConfig) Build() (proto.Message, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type HTTPConfig struct {
|
type HTTPConfig struct {
|
||||||
Host *common.StringList `json:"host"`
|
Host *StringList `json:"host"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build implements Buildable.
|
// Build implements Buildable.
|
||||||
|
@ -312,16 +311,16 @@ func (c *TLSCertConfig) Build() (*tls.Certificate, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type TLSConfig struct {
|
type TLSConfig struct {
|
||||||
Insecure bool `json:"allowInsecure"`
|
Insecure bool `json:"allowInsecure"`
|
||||||
Certs []*TLSCertConfig `json:"certificates"`
|
Certs []*TLSCertConfig `json:"certificates"`
|
||||||
ServerName string `json:"serverName"`
|
ServerName string `json:"serverName"`
|
||||||
ALPN *common.StringList `json:"alpn"`
|
ALPN *StringList `json:"alpn"`
|
||||||
EnableSessionResumption bool `json:"enableSessionResumption"`
|
EnableSessionResumption bool `json:"enableSessionResumption"`
|
||||||
DisableSystemRoot bool `json:"disableSystemRoot"`
|
DisableSystemRoot bool `json:"disableSystemRoot"`
|
||||||
MinVersion string `json:"minVersion"`
|
MinVersion string `json:"minVersion"`
|
||||||
MaxVersion string `json:"maxVersion"`
|
MaxVersion string `json:"maxVersion"`
|
||||||
CipherSuites string `json:"cipherSuites"`
|
CipherSuites string `json:"cipherSuites"`
|
||||||
PreferServerCipherSuites bool `json:"preferServerCipherSuites"`
|
PreferServerCipherSuites bool `json:"preferServerCipherSuites"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build implements Buildable.
|
// Build implements Buildable.
|
||||||
|
@ -402,16 +401,16 @@ func (c *XTLSCertConfig) Build() (*xtls.Certificate, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type XTLSConfig struct {
|
type XTLSConfig struct {
|
||||||
Insecure bool `json:"allowInsecure"`
|
Insecure bool `json:"allowInsecure"`
|
||||||
Certs []*XTLSCertConfig `json:"certificates"`
|
Certs []*XTLSCertConfig `json:"certificates"`
|
||||||
ServerName string `json:"serverName"`
|
ServerName string `json:"serverName"`
|
||||||
ALPN *common.StringList `json:"alpn"`
|
ALPN *StringList `json:"alpn"`
|
||||||
EnableSessionResumption bool `json:"enableSessionResumption"`
|
EnableSessionResumption bool `json:"enableSessionResumption"`
|
||||||
DisableSystemRoot bool `json:"disableSystemRoot"`
|
DisableSystemRoot bool `json:"disableSystemRoot"`
|
||||||
MinVersion string `json:"minVersion"`
|
MinVersion string `json:"minVersion"`
|
||||||
MaxVersion string `json:"maxVersion"`
|
MaxVersion string `json:"maxVersion"`
|
||||||
CipherSuites string `json:"cipherSuites"`
|
CipherSuites string `json:"cipherSuites"`
|
||||||
PreferServerCipherSuites bool `json:"preferServerCipherSuites"`
|
PreferServerCipherSuites bool `json:"preferServerCipherSuites"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build implements Buildable.
|
// Build implements Buildable.
|
||||||
|
|
|
@ -11,18 +11,17 @@ import (
|
||||||
"github.com/xtls/xray-core/common/net"
|
"github.com/xtls/xray-core/common/net"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
"github.com/xtls/xray-core/proxy/trojan"
|
"github.com/xtls/xray-core/proxy/trojan"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TrojanServerTarget is configuration of a single trojan server
|
// TrojanServerTarget is configuration of a single trojan server
|
||||||
type TrojanServerTarget struct {
|
type TrojanServerTarget struct {
|
||||||
Address *common.Address `json:"address"`
|
Address *Address `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Level byte `json:"level"`
|
Level byte `json:"level"`
|
||||||
Flow string `json:"flow"`
|
Flow string `json:"flow"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TrojanClientConfig is configuration of trojan servers
|
// TrojanClientConfig is configuration of trojan servers
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/common/uuid"
|
"github.com/xtls/xray-core/common/uuid"
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
"github.com/xtls/xray-core/proxy/vless"
|
"github.com/xtls/xray-core/proxy/vless"
|
||||||
"github.com/xtls/xray-core/proxy/vless/inbound"
|
"github.com/xtls/xray-core/proxy/vless/inbound"
|
||||||
"github.com/xtls/xray-core/proxy/vless/outbound"
|
"github.com/xtls/xray-core/proxy/vless/outbound"
|
||||||
|
@ -138,7 +137,7 @@ func (c *VLessInboundConfig) Build() (proto.Message, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type VLessOutboundVnext struct {
|
type VLessOutboundVnext struct {
|
||||||
Address *common.Address `json:"address"`
|
Address *Address `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Users []json.RawMessage `json:"users"`
|
Users []json.RawMessage `json:"users"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
"github.com/xtls/xray-core/common/uuid"
|
"github.com/xtls/xray-core/common/uuid"
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
"github.com/xtls/xray-core/proxy/vmess"
|
"github.com/xtls/xray-core/proxy/vmess"
|
||||||
"github.com/xtls/xray-core/proxy/vmess/inbound"
|
"github.com/xtls/xray-core/proxy/vmess/inbound"
|
||||||
"github.com/xtls/xray-core/proxy/vmess/outbound"
|
"github.com/xtls/xray-core/proxy/vmess/outbound"
|
||||||
|
@ -124,7 +123,7 @@ func (c *VMessInboundConfig) Build() (proto.Message, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type VMessOutboundTarget struct {
|
type VMessOutboundTarget struct {
|
||||||
Address *common.Address `json:"address"`
|
Address *Address `json:"address"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
Users []json.RawMessage `json:"users"`
|
Users []json.RawMessage `json:"users"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ import (
|
||||||
"github.com/xtls/xray-core/common/matcher/geoip"
|
"github.com/xtls/xray-core/common/matcher/geoip"
|
||||||
"github.com/xtls/xray-core/common/serial"
|
"github.com/xtls/xray-core/common/serial"
|
||||||
core "github.com/xtls/xray-core/core"
|
core "github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/infra/conf/common"
|
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
"github.com/xtls/xray-core/transport/internet/xtls"
|
"github.com/xtls/xray-core/transport/internet/xtls"
|
||||||
)
|
)
|
||||||
|
@ -64,11 +63,11 @@ func toProtocolList(s []string) ([]proxyman.KnownProtocols, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SniffingConfig struct {
|
type SniffingConfig struct {
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
DestOverride *common.StringList `json:"destOverride"`
|
DestOverride *StringList `json:"destOverride"`
|
||||||
DomainsExcluded *common.StringList `json:"domainsExcluded"`
|
DomainsExcluded *StringList `json:"domainsExcluded"`
|
||||||
IPsExcluded *common.StringList `json:"ipsExcluded"`
|
IPsExcluded *StringList `json:"ipsExcluded"`
|
||||||
MetadataOnly bool `json:"metadataOnly"`
|
MetadataOnly bool `json:"metadataOnly"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build implements Buildable.
|
// Build implements Buildable.
|
||||||
|
@ -176,13 +175,13 @@ func (c *InboundDetourAllocationConfig) Build() (*proxyman.AllocationStrategy, e
|
||||||
|
|
||||||
type InboundDetourConfig struct {
|
type InboundDetourConfig struct {
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
PortRange *common.PortRange `json:"port"`
|
PortRange *PortRange `json:"port"`
|
||||||
ListenOn *common.Address `json:"listen"`
|
ListenOn *Address `json:"listen"`
|
||||||
Settings *json.RawMessage `json:"settings"`
|
Settings *json.RawMessage `json:"settings"`
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag"`
|
||||||
Allocation *InboundDetourAllocationConfig `json:"allocate"`
|
Allocation *InboundDetourAllocationConfig `json:"allocate"`
|
||||||
StreamSetting *StreamConfig `json:"streamSettings"`
|
StreamSetting *StreamConfig `json:"streamSettings"`
|
||||||
DomainOverride *common.StringList `json:"domainOverride"`
|
DomainOverride *StringList `json:"domainOverride"`
|
||||||
SniffingConfig *SniffingConfig `json:"sniffing"`
|
SniffingConfig *SniffingConfig `json:"sniffing"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,7 +283,7 @@ func (c *InboundDetourConfig) Build() (*core.InboundHandlerConfig, error) {
|
||||||
|
|
||||||
type OutboundDetourConfig struct {
|
type OutboundDetourConfig struct {
|
||||||
Protocol string `json:"protocol"`
|
Protocol string `json:"protocol"`
|
||||||
SendThrough *common.Address `json:"sendThrough"`
|
SendThrough *Address `json:"sendThrough"`
|
||||||
Tag string `json:"tag"`
|
Tag string `json:"tag"`
|
||||||
Settings *json.RawMessage `json:"settings"`
|
Settings *json.RawMessage `json:"settings"`
|
||||||
StreamSetting *StreamConfig `json:"streamSettings"`
|
StreamSetting *StreamConfig `json:"streamSettings"`
|
||||||
|
@ -642,7 +641,7 @@ func (c *Config) Build() (*core.Config, error) {
|
||||||
|
|
||||||
// Backward compatibility.
|
// Backward compatibility.
|
||||||
if len(inbounds) > 0 && inbounds[0].PortRange == nil && c.Port > 0 {
|
if len(inbounds) > 0 && inbounds[0].PortRange == nil && c.Port > 0 {
|
||||||
inbounds[0].PortRange = &common.PortRange{
|
inbounds[0].PortRange = &PortRange{
|
||||||
From: uint32(c.Port),
|
From: uint32(c.Port),
|
||||||
To: uint32(c.Port),
|
To: uint32(c.Port),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue