You've already forked v2ray-core
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7474e1f8a | ||
|
|
21e9a04dca | ||
|
|
021cd3b5b7 |
@@ -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."
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
"port": 53,
|
||||
"domains": [
|
||||
"domain:v2ray.com"
|
||||
],
|
||||
]
|
||||
},
|
||||
"8.8.8.8",
|
||||
"localhost"
|
||||
|
||||
Reference in New Issue
Block a user