You've already forked v2ray-core
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e82128dc9 | ||
|
|
a7474e1f8a | ||
|
|
21e9a04dca | ||
|
|
021cd3b5b7 | ||
|
|
e13def10c4 | ||
|
|
4257d1a0ed | ||
|
|
db6d6a89df |
@@ -39,31 +39,6 @@ func (v *ConditionChan) Len() int {
|
||||
return len(*v)
|
||||
}
|
||||
|
||||
type AnyCondition []Condition
|
||||
|
||||
func NewAnyCondition() *AnyCondition {
|
||||
var anyCond AnyCondition = make([]Condition, 0, 8)
|
||||
return &anyCond
|
||||
}
|
||||
|
||||
func (v *AnyCondition) Add(cond Condition) *AnyCondition {
|
||||
*v = append(*v, cond)
|
||||
return v
|
||||
}
|
||||
|
||||
func (v *AnyCondition) Apply(ctx context.Context) bool {
|
||||
for _, cond := range *v {
|
||||
if cond.Apply(ctx) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (v *AnyCondition) Len() int {
|
||||
return len(*v)
|
||||
}
|
||||
|
||||
var matcherTypeMap = map[Domain_Type]strmatcher.Type{
|
||||
Domain_Plain: strmatcher.Substr,
|
||||
Domain_Regex: strmatcher.Regex,
|
||||
|
||||
@@ -13,6 +13,33 @@ import (
|
||||
"v2ray.com/ext/sysio"
|
||||
)
|
||||
|
||||
func TestGeoIPMatcherContainer(t *testing.T) {
|
||||
container := &router.GeoIPMatcherContainer{}
|
||||
|
||||
m1, err := container.Add(&router.GeoIP{
|
||||
CountryCode: "CN",
|
||||
})
|
||||
common.Must(err)
|
||||
|
||||
m2, err := container.Add(&router.GeoIP{
|
||||
CountryCode: "US",
|
||||
})
|
||||
common.Must(err)
|
||||
|
||||
m3, err := container.Add(&router.GeoIP{
|
||||
CountryCode: "CN",
|
||||
})
|
||||
common.Must(err)
|
||||
|
||||
if m1 != m3 {
|
||||
t.Error("expect same matcher for same geoip, but not")
|
||||
}
|
||||
|
||||
if m1 == m2 {
|
||||
t.Error("expect different matcher for different geoip, but actually same")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGeoIPMatcher(t *testing.T) {
|
||||
cidrList := router.CIDRList{
|
||||
{Ip: []byte{0, 0, 0, 0}, Prefix: 8},
|
||||
|
||||
@@ -25,7 +25,7 @@ type ClientManager struct {
|
||||
}
|
||||
|
||||
func (m *ClientManager) Dispatch(ctx context.Context, link *transport.Link) error {
|
||||
for {
|
||||
for i := 0; i < 16; i++ {
|
||||
worker, err := m.Picker.PickAvailable()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -34,6 +34,8 @@ func (m *ClientManager) Dispatch(ctx context.Context, link *transport.Link) erro
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return newError("unable to find an available mux client")
|
||||
}
|
||||
|
||||
type WorkerPicker interface {
|
||||
|
||||
@@ -70,6 +70,10 @@ type Address interface {
|
||||
String() string // String representation of this Address
|
||||
}
|
||||
|
||||
func isAlphaNum(c byte) bool {
|
||||
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
|
||||
}
|
||||
|
||||
// ParseAddress parses a string into an Address. The return value will be an IPAddress when
|
||||
// the string is in the form of IPv4 or IPv6 address, or a DomainAddress otherwise.
|
||||
func ParseAddress(addr string) Address {
|
||||
@@ -77,8 +81,12 @@ func ParseAddress(addr string) Address {
|
||||
lenAddr := len(addr)
|
||||
if lenAddr > 0 && addr[0] == '[' && addr[lenAddr-1] == ']' {
|
||||
addr = addr[1 : lenAddr-1]
|
||||
lenAddr -= 2
|
||||
}
|
||||
|
||||
if lenAddr > 0 && (!isAlphaNum(addr[0]) || !isAlphaNum(addr[len(addr)-1])) {
|
||||
addr = strings.TrimSpace(addr)
|
||||
}
|
||||
addr = strings.TrimSpace(addr)
|
||||
|
||||
ip := net.ParseIP(addr)
|
||||
if ip != nil {
|
||||
|
||||
@@ -101,3 +101,21 @@ func TestIPOrDomain(t *testing.T) {
|
||||
assert(NewIPOrDomain(ParseAddress("8.8.8.8")).AsAddress(), Equals, ParseAddress("8.8.8.8"))
|
||||
assert(NewIPOrDomain(ParseAddress("2001:4860:0:2001::68")).AsAddress(), Equals, ParseAddress("2001:4860:0:2001::68"))
|
||||
}
|
||||
|
||||
func BenchmarkParseAddressIPv4(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = ParseAddress("8.8.8.8")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseAddressIPv6(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = ParseAddress("2001:4860:0:2001::68")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkParseAddressDomain(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = ParseAddress("v2ray.com")
|
||||
}
|
||||
}
|
||||
|
||||
2
core.go
2
core.go
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
version = "4.1"
|
||||
version = "4.2"
|
||||
build = "Custom"
|
||||
codename = "Po"
|
||||
intro = "A unified platform for anti-censorship."
|
||||
|
||||
@@ -1,25 +1,118 @@
|
||||
// Config file of V2Ray. This file follows standard JSON format, with comments support.
|
||||
// Uncomment entries below to satisfy your needs. Also read our manual for more detail at
|
||||
// https://www.v2ray.com/
|
||||
{
|
||||
"log": {
|
||||
// By default, V2Ray writes access log to stdout.
|
||||
// "access": "/path/to/access/log/file",
|
||||
|
||||
// By default, V2Ray write error log to stdout.
|
||||
// "error": "/path/to/error/log/file",
|
||||
|
||||
// Log level, one of "debug", "info", "warning", "error", "none"
|
||||
"loglevel": "warning"
|
||||
},
|
||||
"inbound": {
|
||||
// List of inbound proxy configurations.
|
||||
"inbounds": [{
|
||||
// Port to listen on. You may need root access if the value is less than 1024.
|
||||
"port": 1080,
|
||||
|
||||
// IP address to listen on. Change to "0.0.0.0" to listen on all network interfaces.
|
||||
"listen": "127.0.0.1",
|
||||
|
||||
// Tag of the inbound proxy. May be used for routing.
|
||||
"tag": "socks-inbound",
|
||||
|
||||
// Protocol name of inbound proxy.
|
||||
"protocol": "socks",
|
||||
|
||||
// Settings of the protocol. Varies based on protocol.
|
||||
"settings": {
|
||||
"auth": "noauth",
|
||||
"udp": false,
|
||||
"ip": "127.0.0.1"
|
||||
}
|
||||
},
|
||||
"outbound": {
|
||||
}],
|
||||
// List of outbound proxy configurations.
|
||||
"outbounds": [{
|
||||
// Protocol name of the outbound proxy.
|
||||
"protocol": "freedom",
|
||||
|
||||
// Settings of the protocol. Varies based on protocol.
|
||||
"settings": {},
|
||||
|
||||
// Tag of the outbound. May be used for routing.
|
||||
"tag": "direct"
|
||||
},{
|
||||
"protocol": "blackhole",
|
||||
"settings": {},
|
||||
"tag": "blocked"
|
||||
}],
|
||||
|
||||
// Transport is for global transport settings. If you have multiple transports with same settings
|
||||
// (say mKCP), you may put it here, instead of in each individual inbound/outbounds.
|
||||
//"transport": {},
|
||||
|
||||
// Routing controls how traffic from inbounds are sent to outbounds.
|
||||
"routing": {
|
||||
"domainStrategy": "IPOnDemand",
|
||||
"rules":[{
|
||||
"type": "field",
|
||||
"ip": ["geoip:private"],
|
||||
"outboundTag": "blocked"
|
||||
}]
|
||||
},
|
||||
|
||||
// Dns settings for domain resolution.
|
||||
"dns": {
|
||||
// Static hosts, similar to hosts file.
|
||||
"hosts": {
|
||||
// Blacklist all Baidu domains, including all sub domains.
|
||||
"domain:baidu.com": "127.0.0.1"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
"address": "1.1.1.1",
|
||||
"port": 53,
|
||||
"domains": [
|
||||
"domain:v2ray.com"
|
||||
]
|
||||
},
|
||||
"8.8.8.8",
|
||||
"localhost"
|
||||
]
|
||||
},
|
||||
|
||||
// Policy controls some internal behavior of how V2Ray handles connections.
|
||||
// It may be on connection level by user levels in 'levels', or global settings in 'system.'
|
||||
"policy": {
|
||||
// Connection policys by user levels
|
||||
"levels": {
|
||||
"0": {"uplinkOnly": 0}
|
||||
"0": {
|
||||
"uplinkOnly": 0,
|
||||
"downlinkOnly": 0
|
||||
}
|
||||
},
|
||||
"system": {
|
||||
"statsInboundUplink": false,
|
||||
"statsInboundDownlink": false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Stats enables internal stats counter.
|
||||
// This setting can be used together with Policy and Api.
|
||||
//"stats":{},
|
||||
|
||||
// Api enables gRPC APIs for external programs to communicate with V2Ray instance.
|
||||
//"api": {
|
||||
//"tag": "api",
|
||||
//"services": [
|
||||
// "HandlerService",
|
||||
// "LoggerService",
|
||||
// "StatsService"
|
||||
//]
|
||||
//},
|
||||
|
||||
// You may add other entries to the configuration, but they will not be recognized by V2Ray.
|
||||
"other": {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user