You've already forked v2ray-core
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
869cd46450 | ||
|
|
790f6c038c | ||
|
|
1cdd3e6647 | ||
|
|
fb1dda5a19 | ||
|
|
46b81b7e98 | ||
|
|
12e72509a5 | ||
|
|
f4ec19625e | ||
|
|
d48ac4418f | ||
|
|
794b5081e3 |
@@ -1,5 +1,10 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
routerconfig "github.com/v2ray/v2ray-core/app/router/config"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
type DetourTag string
|
||||
|
||||
type ConnectionConfig interface {
|
||||
@@ -11,14 +16,9 @@ type LogConfig interface {
|
||||
AccessLog() string
|
||||
}
|
||||
|
||||
type PortRange interface {
|
||||
From() uint16
|
||||
To() uint16
|
||||
}
|
||||
|
||||
type InboundDetourConfig interface {
|
||||
Protocol() string
|
||||
PortRange() PortRange
|
||||
PortRange() v2net.PortRange
|
||||
Settings() interface{}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,9 @@ type OutboundDetourConfig interface {
|
||||
type PointConfig interface {
|
||||
Port() uint16
|
||||
LogConfig() LogConfig
|
||||
RouterConfig() routerconfig.RouterConfig
|
||||
InboundConfig() ConnectionConfig
|
||||
OutboundConfig() ConnectionConfig
|
||||
InboundDetours() []InboundDetourConfig
|
||||
OutboundDetours() []OutboundDetourConfig
|
||||
}
|
||||
|
||||
@@ -3,21 +3,22 @@ package json
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/v2ray/v2ray-core/app/point/config"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
v2netjson "github.com/v2ray/v2ray-core/common/net/json"
|
||||
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
|
||||
)
|
||||
|
||||
type InboundDetourConfig struct {
|
||||
ProtocolValue string `json:"protocol"`
|
||||
PortRangeValue *PortRange `json:"port"`
|
||||
SettingsValue json.RawMessage `json:"settings"`
|
||||
ProtocolValue string `json:"protocol"`
|
||||
PortRangeValue *v2netjson.PortRange `json:"port"`
|
||||
SettingsValue json.RawMessage `json:"settings"`
|
||||
}
|
||||
|
||||
func (this *InboundDetourConfig) Protocol() string {
|
||||
return this.ProtocolValue
|
||||
}
|
||||
|
||||
func (this *InboundDetourConfig) PortRange() config.PortRange {
|
||||
func (this *InboundDetourConfig) PortRange() v2net.PortRange {
|
||||
return this.PortRangeValue
|
||||
}
|
||||
|
||||
|
||||
@@ -6,18 +6,21 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/v2ray/v2ray-core/app/point/config"
|
||||
routerconfig "github.com/v2ray/v2ray-core/app/router/config"
|
||||
routerconfigjson "github.com/v2ray/v2ray-core/app/router/config/json"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
|
||||
)
|
||||
|
||||
// Config is the config for Point server.
|
||||
type Config struct {
|
||||
PortValue uint16 `json:"port"` // Port of this Point server.
|
||||
LogConfigValue *LogConfig `json:"log"`
|
||||
InboundConfigValue *ConnectionConfig `json:"inbound"`
|
||||
OutboundConfigValue *ConnectionConfig `json:"outbound"`
|
||||
InboundDetoursValue []*InboundDetourConfig `json:"inboundDetour"`
|
||||
OutboundDetoursValue []*OutboundDetourConfig `json:"outboundDetour"`
|
||||
PortValue uint16 `json:"port"` // Port of this Point server.
|
||||
LogConfigValue *LogConfig `json:"log"`
|
||||
RouterConfigValue *routerconfigjson.RouterConfig `json:"routing"`
|
||||
InboundConfigValue *ConnectionConfig `json:"inbound"`
|
||||
OutboundConfigValue *ConnectionConfig `json:"outbound"`
|
||||
InboundDetoursValue []*InboundDetourConfig `json:"inboundDetour"`
|
||||
OutboundDetoursValue []*OutboundDetourConfig `json:"outboundDetour"`
|
||||
}
|
||||
|
||||
func (config *Config) Port() uint16 {
|
||||
@@ -31,6 +34,13 @@ func (config *Config) LogConfig() config.LogConfig {
|
||||
return config.LogConfigValue
|
||||
}
|
||||
|
||||
func (this *Config) RouterConfig() routerconfig.RouterConfig {
|
||||
if this.RouterConfigValue == nil {
|
||||
return nil
|
||||
}
|
||||
return this.RouterConfigValue
|
||||
}
|
||||
|
||||
func (config *Config) InboundConfig() config.ConnectionConfig {
|
||||
if config.InboundConfigValue == nil {
|
||||
return nil
|
||||
|
||||
@@ -2,6 +2,8 @@ package mocks
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/app/point/config"
|
||||
routerconfig "github.com/v2ray/v2ray-core/app/router/config"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
type ConnectionConfig struct {
|
||||
@@ -39,20 +41,31 @@ type InboundDetourConfig struct {
|
||||
PortRangeValue *PortRange
|
||||
}
|
||||
|
||||
func (this *InboundDetourConfig) PortRange() config.PortRange {
|
||||
func (this *InboundDetourConfig) PortRange() v2net.PortRange {
|
||||
return this.PortRangeValue
|
||||
}
|
||||
|
||||
type OutboundDetourConfig struct {
|
||||
ConnectionConfig
|
||||
TagValue config.DetourTag
|
||||
}
|
||||
|
||||
func (this *OutboundDetourConfig) Tag() config.DetourTag {
|
||||
return this.TagValue
|
||||
}
|
||||
|
||||
func (config *LogConfig) AccessLog() string {
|
||||
return config.AccessLogValue
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
PortValue uint16
|
||||
LogConfigValue *LogConfig
|
||||
InboundConfigValue *ConnectionConfig
|
||||
OutboundConfigValue *ConnectionConfig
|
||||
InboundDetoursValue []*InboundDetourConfig
|
||||
PortValue uint16
|
||||
LogConfigValue *LogConfig
|
||||
RouterConfigValue routerconfig.RouterConfig
|
||||
InboundConfigValue *ConnectionConfig
|
||||
OutboundConfigValue *ConnectionConfig
|
||||
InboundDetoursValue []*InboundDetourConfig
|
||||
OutboundDetoursValue []*OutboundDetourConfig
|
||||
}
|
||||
|
||||
func (config *Config) Port() uint16 {
|
||||
@@ -63,6 +76,10 @@ func (config *Config) LogConfig() config.LogConfig {
|
||||
return config.LogConfigValue
|
||||
}
|
||||
|
||||
func (this *Config) RouterConfig() routerconfig.RouterConfig {
|
||||
return this.RouterConfigValue
|
||||
}
|
||||
|
||||
func (config *Config) InboundConfig() config.ConnectionConfig {
|
||||
return config.InboundConfigValue
|
||||
}
|
||||
@@ -78,3 +95,11 @@ func (this *Config) InboundDetours() []config.InboundDetourConfig {
|
||||
}
|
||||
return detours
|
||||
}
|
||||
|
||||
func (this *Config) OutboundDetours() []config.OutboundDetourConfig {
|
||||
detours := make([]config.OutboundDetourConfig, len(this.OutboundDetoursValue))
|
||||
for idx, detour := range this.OutboundDetoursValue {
|
||||
detours[idx] = detour
|
||||
}
|
||||
return detours
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package point
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/app/point/config"
|
||||
"github.com/v2ray/v2ray-core/app/router"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
"github.com/v2ray/v2ray-core/common/retry"
|
||||
@@ -11,10 +12,12 @@ import (
|
||||
|
||||
// Point is an single server in V2Ray system.
|
||||
type Point struct {
|
||||
port uint16
|
||||
ich connhandler.InboundConnectionHandler
|
||||
och connhandler.OutboundConnectionHandler
|
||||
idh []*InboundDetourHandler
|
||||
port uint16
|
||||
ich connhandler.InboundConnectionHandler
|
||||
och connhandler.OutboundConnectionHandler
|
||||
idh []*InboundDetourHandler
|
||||
odh map[config.DetourTag]connhandler.OutboundConnectionHandler
|
||||
router router.Router
|
||||
}
|
||||
|
||||
// NewPoint returns a new Point server based on given configuration.
|
||||
@@ -65,6 +68,34 @@ func NewPoint(pConfig config.PointConfig) (*Point, error) {
|
||||
}
|
||||
}
|
||||
|
||||
outboundDetours := pConfig.OutboundDetours()
|
||||
if len(outboundDetours) > 0 {
|
||||
vpoint.odh = make(map[config.DetourTag]connhandler.OutboundConnectionHandler)
|
||||
for _, detourConfig := range outboundDetours {
|
||||
detourFactory := connhandler.GetOutboundConnectionHandlerFactory(detourConfig.Protocol())
|
||||
if detourFactory == nil {
|
||||
log.Error("Unknown detour outbound connection handler factory %s", detourConfig.Protocol())
|
||||
return nil, config.BadConfiguration
|
||||
}
|
||||
detourHandler, err := detourFactory.Create(detourConfig.Settings())
|
||||
if err != nil {
|
||||
log.Error("Failed to create detour outbound connection handler: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
vpoint.odh[detourConfig.Tag()] = detourHandler
|
||||
}
|
||||
}
|
||||
|
||||
routerConfig := pConfig.RouterConfig()
|
||||
if routerConfig != nil {
|
||||
r, err := router.CreateRouter(routerConfig.Strategy(), routerConfig.Settings())
|
||||
if err != nil {
|
||||
log.Error("Failed to create router: %v", err)
|
||||
return nil, config.BadConfiguration
|
||||
}
|
||||
vpoint.router = r
|
||||
}
|
||||
|
||||
return vpoint, nil
|
||||
}
|
||||
|
||||
@@ -100,6 +131,19 @@ func (vp *Point) Start() error {
|
||||
|
||||
func (p *Point) DispatchToOutbound(packet v2net.Packet) ray.InboundRay {
|
||||
direct := ray.NewRay()
|
||||
dest := packet.Destination()
|
||||
|
||||
if p.router != nil {
|
||||
tag, err := p.router.TakeDetour(dest)
|
||||
if err == nil {
|
||||
handler, found := p.odh[tag]
|
||||
if found {
|
||||
go handler.Dispatch(packet, direct)
|
||||
return direct
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
go p.och.Dispatch(packet, direct)
|
||||
return direct
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package json
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
)
|
||||
|
||||
type RouterConfig struct {
|
||||
@@ -14,5 +16,11 @@ func (this *RouterConfig) Strategy() string {
|
||||
}
|
||||
|
||||
func (this *RouterConfig) Settings() interface{} {
|
||||
return CreateRouterConfig(this.Strategy())
|
||||
settings := CreateRouterConfig(this.Strategy())
|
||||
err := json.Unmarshal(this.SettingsValue, settings)
|
||||
if err != nil {
|
||||
log.Error("Failed to load router settings: %v", err)
|
||||
return nil
|
||||
}
|
||||
return settings
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ var (
|
||||
)
|
||||
|
||||
type Router interface {
|
||||
TakeDetour(v2net.Packet) (config.DetourTag, error)
|
||||
TakeDetour(v2net.Destination) (config.DetourTag, error)
|
||||
}
|
||||
|
||||
type RouterFactory interface {
|
||||
|
||||
93
app/router/rules/config/json/fieldrule.go
Normal file
93
app/router/rules/config/json/fieldrule.go
Normal file
@@ -0,0 +1,93 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
v2netjson "github.com/v2ray/v2ray-core/common/net/json"
|
||||
)
|
||||
|
||||
type FieldRule struct {
|
||||
Rule
|
||||
Domain string
|
||||
IP *net.IPNet
|
||||
Port v2net.PortRange
|
||||
Network v2net.NetworkList
|
||||
}
|
||||
|
||||
func (this *FieldRule) Apply(dest v2net.Destination) bool {
|
||||
address := dest.Address()
|
||||
if len(this.Domain) > 0 {
|
||||
if !address.IsDomain() || !strings.Contains(address.Domain(), this.Domain) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if this.IP != nil {
|
||||
if !(address.IsIPv4() || address.IsIPv6()) || !this.IP.Contains(address.IP()) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if this.Port != nil {
|
||||
port := address.Port()
|
||||
if port < this.Port.From() || port > this.Port.To() {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if this.Network != nil {
|
||||
if !this.Network.HasNetwork(v2net.Network(dest.Network())) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *FieldRule) UnmarshalJSON(data []byte) error {
|
||||
type RawFieldRule struct {
|
||||
Rule
|
||||
Domain string `json:"domain"`
|
||||
IP string `json:"ip"`
|
||||
Port *v2netjson.PortRange `json:"port"`
|
||||
Network *v2netjson.NetworkList `json:"network"`
|
||||
}
|
||||
rawFieldRule := RawFieldRule{}
|
||||
err := json.Unmarshal(data, &rawFieldRule)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
this.Type = rawFieldRule.Type
|
||||
this.OutboundTag = rawFieldRule.OutboundTag
|
||||
|
||||
hasField := false
|
||||
if len(rawFieldRule.Domain) > 0 {
|
||||
this.Domain = rawFieldRule.Domain
|
||||
hasField = true
|
||||
}
|
||||
|
||||
if len(rawFieldRule.IP) > 0 {
|
||||
_, ipNet, err := net.ParseCIDR(rawFieldRule.IP)
|
||||
if err != nil {
|
||||
return errors.New("Invalid IP range in router rule: " + err.Error())
|
||||
}
|
||||
this.IP = ipNet
|
||||
hasField = true
|
||||
}
|
||||
if rawFieldRule.Port != nil {
|
||||
this.Port = rawFieldRule.Port
|
||||
hasField = true
|
||||
}
|
||||
if rawFieldRule.Network != nil {
|
||||
this.Network = rawFieldRule.Network
|
||||
hasField = true
|
||||
}
|
||||
if !hasField {
|
||||
return errors.New("This rule has no effective fields.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
71
app/router/rules/config/json/fieldrule_test.go
Normal file
71
app/router/rules/config/json/fieldrule_test.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
|
||||
"github.com/v2ray/v2ray-core/testing/unit"
|
||||
)
|
||||
|
||||
func TestDomainMatching(t *testing.T) {
|
||||
assert := unit.Assert(t)
|
||||
|
||||
rule := &FieldRule{
|
||||
Domain: "v2ray.com",
|
||||
}
|
||||
dest := v2net.NewTCPDestination(v2net.DomainAddress("www.v2ray.com", 80))
|
||||
assert.Bool(rule.Apply(dest)).IsTrue()
|
||||
}
|
||||
|
||||
func TestPortMatching(t *testing.T) {
|
||||
assert := unit.Assert(t)
|
||||
|
||||
rule := &FieldRule{
|
||||
Port: &v2nettesting.PortRange{
|
||||
FromValue: 0,
|
||||
ToValue: 100,
|
||||
},
|
||||
}
|
||||
dest := v2net.NewTCPDestination(v2net.DomainAddress("www.v2ray.com", 80))
|
||||
assert.Bool(rule.Apply(dest)).IsTrue()
|
||||
}
|
||||
|
||||
func TestIPMatching(t *testing.T) {
|
||||
assert := unit.Assert(t)
|
||||
|
||||
rawJson := `{
|
||||
"type": "field",
|
||||
"ip": "10.0.0.0/8",
|
||||
"tag": "test"
|
||||
}`
|
||||
rule := parseRule([]byte(rawJson))
|
||||
dest := v2net.NewTCPDestination(v2net.IPAddress([]byte{10, 0, 0, 1}, 80))
|
||||
assert.Bool(rule.Apply(dest)).IsTrue()
|
||||
}
|
||||
|
||||
func TestPortNotMatching(t *testing.T) {
|
||||
assert := unit.Assert(t)
|
||||
|
||||
rawJson := `{
|
||||
"type": "field",
|
||||
"port": "80-100",
|
||||
"tag": "test"
|
||||
}`
|
||||
rule := parseRule([]byte(rawJson))
|
||||
dest := v2net.NewTCPDestination(v2net.IPAddress([]byte{10, 0, 0, 1}, 79))
|
||||
assert.Bool(rule.Apply(dest)).IsFalse()
|
||||
}
|
||||
|
||||
func TestDomainNotMatching(t *testing.T) {
|
||||
assert := unit.Assert(t)
|
||||
|
||||
rawJson := `{
|
||||
"type": "field",
|
||||
"domain": "google.com",
|
||||
"tag": "test"
|
||||
}`
|
||||
rule := parseRule([]byte(rawJson))
|
||||
dest := v2net.NewTCPDestination(v2net.IPAddress([]byte{10, 0, 0, 1}, 79))
|
||||
assert.Bool(rule.Apply(dest)).IsFalse()
|
||||
}
|
||||
47
app/router/rules/config/json/router.go
Normal file
47
app/router/rules/config/json/router.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
v2routerconfigjson "github.com/v2ray/v2ray-core/app/router/config/json"
|
||||
"github.com/v2ray/v2ray-core/app/router/rules/config"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
)
|
||||
|
||||
type RouterRuleConfig struct {
|
||||
RuleList []json.RawMessage `json:"rules"`
|
||||
}
|
||||
|
||||
func parseRule(msg json.RawMessage) config.Rule {
|
||||
rule := new(Rule)
|
||||
err := json.Unmarshal(msg, rule)
|
||||
if err != nil {
|
||||
log.Error("Invalid router rule: %v", err)
|
||||
return nil
|
||||
}
|
||||
if rule.Type == "field" {
|
||||
fieldrule := new(FieldRule)
|
||||
err = json.Unmarshal(msg, fieldrule)
|
||||
if err != nil {
|
||||
log.Error("Invalid field rule: %v", err)
|
||||
return nil
|
||||
}
|
||||
return fieldrule
|
||||
}
|
||||
log.Error("Unknown router rule type: %s", rule.Type)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *RouterRuleConfig) Rules() []config.Rule {
|
||||
rules := make([]config.Rule, len(this.RuleList))
|
||||
for idx, rawRule := range this.RuleList {
|
||||
rules[idx] = parseRule(rawRule)
|
||||
}
|
||||
return rules
|
||||
}
|
||||
|
||||
func init() {
|
||||
v2routerconfigjson.RegisterRouterConfig("rules", func() interface{} {
|
||||
return new(RouterRuleConfig)
|
||||
})
|
||||
}
|
||||
19
app/router/rules/config/json/rules.go
Normal file
19
app/router/rules/config/json/rules.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/app/point/config"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
type Rule struct {
|
||||
Type string `json:"type"`
|
||||
OutboundTag string `json:"outboundTag"`
|
||||
}
|
||||
|
||||
func (this *Rule) Tag() config.DetourTag {
|
||||
return config.DetourTag(this.OutboundTag)
|
||||
}
|
||||
|
||||
func (this *Rule) Apply(dest v2net.Destination) bool {
|
||||
return false
|
||||
}
|
||||
5
app/router/rules/config/router.go
Normal file
5
app/router/rules/config/router.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package config
|
||||
|
||||
type RouterRuleConfig interface {
|
||||
Rules() []Rule
|
||||
}
|
||||
11
app/router/rules/config/rules.go
Normal file
11
app/router/rules/config/rules.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/app/point/config"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
type Rule interface {
|
||||
Tag() config.DetourTag
|
||||
Apply(dest v2net.Destination) bool
|
||||
}
|
||||
@@ -1 +1,51 @@
|
||||
package rules
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
pointconfig "github.com/v2ray/v2ray-core/app/point/config"
|
||||
"github.com/v2ray/v2ray-core/app/router"
|
||||
"github.com/v2ray/v2ray-core/app/router/rules/config"
|
||||
"github.com/v2ray/v2ray-core/app/router/rules/config/json"
|
||||
v2net "github.com/v2ray/v2ray-core/common/net"
|
||||
)
|
||||
|
||||
var (
|
||||
InvalidRule = errors.New("Invalid Rule")
|
||||
NoRuleApplicable = errors.New("No rule applicable")
|
||||
|
||||
EmptyTag = pointconfig.DetourTag("")
|
||||
)
|
||||
|
||||
type Router struct {
|
||||
rules []config.Rule
|
||||
}
|
||||
|
||||
func (this *Router) TakeDetour(dest v2net.Destination) (pointconfig.DetourTag, error) {
|
||||
for _, rule := range this.rules {
|
||||
if rule.Apply(dest) {
|
||||
return rule.Tag(), nil
|
||||
}
|
||||
}
|
||||
return EmptyTag, NoRuleApplicable
|
||||
}
|
||||
|
||||
type RouterFactory struct {
|
||||
}
|
||||
|
||||
func (this *RouterFactory) Create(rawConfig interface{}) (router.Router, error) {
|
||||
config := rawConfig.(*json.RouterRuleConfig)
|
||||
rules := config.Rules()
|
||||
for _, rule := range rules {
|
||||
if rule == nil {
|
||||
return nil, InvalidRule
|
||||
}
|
||||
}
|
||||
return &Router{
|
||||
rules: rules,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
router.RegisterRouter("rules", &RouterFactory{})
|
||||
}
|
||||
|
||||
@@ -22,9 +22,7 @@ func (queue timedQueueImpl) Less(i, j int) bool {
|
||||
}
|
||||
|
||||
func (queue timedQueueImpl) Swap(i, j int) {
|
||||
tmp := queue[i]
|
||||
queue[i] = queue[j]
|
||||
queue[j] = tmp
|
||||
queue[i], queue[j] = queue[j], queue[i]
|
||||
}
|
||||
|
||||
func (queue *timedQueueImpl) Push(value interface{}) {
|
||||
|
||||
6
common/net/portrange.go
Normal file
6
common/net/portrange.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package net
|
||||
|
||||
type PortRange interface {
|
||||
From() uint16
|
||||
To() uint16
|
||||
}
|
||||
14
common/net/testing/portrange.go
Normal file
14
common/net/testing/portrange.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package testing
|
||||
|
||||
type PortRange struct {
|
||||
FromValue uint16
|
||||
ToValue uint16
|
||||
}
|
||||
|
||||
func (this *PortRange) From() uint16 {
|
||||
return this.FromValue
|
||||
}
|
||||
|
||||
func (this *PortRange) To() uint16 {
|
||||
return this.ToValue
|
||||
}
|
||||
2
core.go
2
core.go
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
version = "0.11"
|
||||
version = "0.14"
|
||||
build = "Custom"
|
||||
codename = "Post Apocalypse"
|
||||
intro = "A stable and unbreakable connection for everyone."
|
||||
|
||||
@@ -25,5 +25,94 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"outboundDetour": [
|
||||
{
|
||||
"protocol": "freedom",
|
||||
"settings": {},
|
||||
"tag": "direct"
|
||||
}
|
||||
],
|
||||
"routing": {
|
||||
"strategy": "rules",
|
||||
"settings": {
|
||||
"rules": [
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "0.0.0.0/8",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "10.0.0.0/8",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "100.64.0.0/10",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "127.0.0.0/8",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "169.254.0.0/16",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "172.16.0.0/12",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "192.0.0.0/24",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "192.0.2.0/24",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "192.168.0.0/16",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "198.18.0.0/15",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "198.51.100.0/24",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "203.0.113.0/24",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "::1/128",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "fc00::/7",
|
||||
"outboundTag": "direct"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "fe80::/10",
|
||||
"outboundTag": "direct"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,5 +21,94 @@
|
||||
"outbound": {
|
||||
"protocol": "freedom",
|
||||
"settings": {}
|
||||
},
|
||||
"outboundDetour": [
|
||||
{
|
||||
"protocol": "blackhole",
|
||||
"settings": {},
|
||||
"tag": "blocked"
|
||||
}
|
||||
],
|
||||
"routing": {
|
||||
"strategy": "rules",
|
||||
"settings": {
|
||||
"rules": [
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "0.0.0.0/8",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "10.0.0.0/8",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "100.64.0.0/10",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "127.0.0.0/8",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "169.254.0.0/16",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "172.16.0.0/12",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "192.0.0.0/24",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "192.0.2.0/24",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "192.168.0.0/16",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "198.18.0.0/15",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "198.51.100.0/24",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "203.0.113.0/24",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "::1/128",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "fc00::/7",
|
||||
"outboundTag": "blocked"
|
||||
},
|
||||
{
|
||||
"type": "field",
|
||||
"ip": "fe80::/10",
|
||||
"outboundTag": "blocked"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,14 @@ import (
|
||||
"github.com/v2ray/v2ray-core"
|
||||
"github.com/v2ray/v2ray-core/app/point"
|
||||
jsonconf "github.com/v2ray/v2ray-core/app/point/config/json"
|
||||
_ "github.com/v2ray/v2ray-core/app/router/config/json"
|
||||
_ "github.com/v2ray/v2ray-core/app/router/rules"
|
||||
_ "github.com/v2ray/v2ray-core/app/router/rules/config/json"
|
||||
"github.com/v2ray/v2ray-core/common/log"
|
||||
|
||||
// The following are neccesary as they register handlers in their init functions.
|
||||
_ "github.com/v2ray/v2ray-core/proxy/blackhole"
|
||||
_ "github.com/v2ray/v2ray-core/proxy/blackhole/config/json"
|
||||
_ "github.com/v2ray/v2ray-core/proxy/dokodemo"
|
||||
_ "github.com/v2ray/v2ray-core/proxy/dokodemo/config/json"
|
||||
_ "github.com/v2ray/v2ray-core/proxy/freedom"
|
||||
|
||||
Reference in New Issue
Block a user