本文整理汇总了Golang中v2ray/com/core/common/net.DomainAddress函数的典型用法代码示例。如果您正苦于以下问题:Golang DomainAddress函数的具体用法?Golang DomainAddress怎么用?Golang DomainAddress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DomainAddress函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_listenWSAndDial
func Test_listenWSAndDial(t *testing.T) {
assert := assert.On(t)
(&Config{Pto: "ws", Path: "ws"}).Apply()
listen, err := ListenWS(v2net.DomainAddress("localhost"), 13142)
assert.Error(err).IsNil()
go func() {
conn, err := listen.Accept()
assert.Error(err).IsNil()
conn.Close()
conn, err = listen.Accept()
assert.Error(err).IsNil()
conn.Close()
conn, err = listen.Accept()
assert.Error(err).IsNil()
conn.Close()
listen.Close()
}()
conn, err := Dial(v2net.AnyIP, v2net.TCPDestination(v2net.DomainAddress("localhost"), 13142))
assert.Error(err).IsNil()
conn.Close()
<-time.After(time.Second * 5)
conn, err = Dial(v2net.AnyIP, v2net.TCPDestination(v2net.DomainAddress("localhost"), 13142))
assert.Error(err).IsNil()
conn.Close()
<-time.After(time.Second * 15)
conn, err = Dial(v2net.AnyIP, v2net.TCPDestination(v2net.DomainAddress("localhost"), 13142))
assert.Error(err).IsNil()
conn.Close()
}
示例2: TestDomainAddressEquals
func TestDomainAddressEquals(t *testing.T) {
assert := assert.On(t)
addr := v2net.DomainAddress("v2ray.com")
assert.Bool(addr.Equals(nil)).IsFalse()
addr2 := v2net.DomainAddress("v2ray.com")
assert.Bool(addr.Equals(addr2)).IsTrue()
addr3 := v2net.DomainAddress("www.v2ray.com")
assert.Bool(addr.Equals(addr3)).IsFalse()
addr4 := v2net.IPAddress([]byte{1, 3, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
assert.Bool(addr.Equals(addr4)).IsFalse()
}
示例3: TestIPResolution
func TestIPResolution(t *testing.T) {
assert := assert.On(t)
space := app.NewSpace()
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, outbound.New())
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
r := router.NewRouter(&router.Config{}, space)
space.BindApp(router.APP_ID, r)
dnsServer := dnsserver.NewCacheServer(space, &dns.Config{
Hosts: map[string]*v2net.IPOrDomain{
"v2ray.com": v2net.NewIPOrDomain(v2net.LocalHostIP),
},
})
space.BindApp(dns.APP_ID, dnsServer)
freedom := NewFreedomConnection(
&Config{DomainStrategy: Config_USE_IP},
space,
&proxy.OutboundHandlerMeta{
Address: v2net.AnyIP,
StreamSettings: &internet.StreamConfig{
Network: v2net.Network_RawTCP,
},
})
space.Initialize()
ipDest := freedom.ResolveIP(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), v2net.Port(80)))
assert.Destination(ipDest).IsTCP()
assert.Address(ipDest.Address).Equals(v2net.LocalHostIP)
}
示例4: TestIPResolution
func TestIPResolution(t *testing.T) {
assert := assert.On(t)
space := app.NewSpace()
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, proxyman.NewDefaultOutboundHandlerManager())
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
r, _ := router.CreateRouter("rules", &rules.RouterRuleConfig{}, space)
space.BindApp(router.APP_ID, r)
dnsServer := dns.NewCacheServer(space, &dns.Config{
Hosts: map[string]net.IP{
"v2ray.com": net.IP([]byte{127, 0, 0, 1}),
},
})
space.BindApp(dns.APP_ID, dnsServer)
freedom := NewFreedomConnection(
&Config{DomainStrategy: DomainStrategyUseIP},
space,
&proxy.OutboundHandlerMeta{
Address: v2net.AnyIP,
StreamSettings: &internet.StreamSettings{
Type: internet.StreamConnectionTypeRawTCP,
},
})
space.Initialize()
ipDest := freedom.ResolveIP(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), v2net.Port(80)))
assert.Destination(ipDest).IsTCP()
assert.Address(ipDest.Address()).Equals(v2net.LocalHostIP)
}
示例5: TestSourceIPRule
func TestSourceIPRule(t *testing.T) {
assert := assert.On(t)
rule := ParseRule([]byte(`{
"type": "field",
"source": [
"10.0.0.0/8",
"192.0.0.0/24"
],
"outboundTag": "direct"
}`))
assert.Pointer(rule).IsNotNil()
cond, err := rule.BuildCondition()
assert.Error(err).IsNil()
assert.Bool(cond.Apply(&proxy.SessionInfo{
Source: v2net.TCPDestination(v2net.DomainAddress("www.ooxx.com"), 80),
})).IsFalse()
assert.Bool(cond.Apply(&proxy.SessionInfo{
Source: v2net.TCPDestination(v2net.IPAddress([]byte{10, 0, 0, 1}), 80),
})).IsTrue()
assert.Bool(cond.Apply(&proxy.SessionInfo{
Source: v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80),
})).IsFalse()
assert.Bool(cond.Apply(&proxy.SessionInfo{
Source: v2net.TCPDestination(v2net.IPAddress([]byte{192, 0, 0, 1}), 80),
})).IsTrue()
}
示例6: TestSimpleRouter
func TestSimpleRouter(t *testing.T) {
assert := assert.On(t)
config := &Config{
Rule: []*RoutingRule{
{
Tag: "test",
NetworkList: &net.NetworkList{
Network: []net.Network{net.Network_TCP},
},
},
},
}
space := app.NewSpace()
ctx := app.ContextWithSpace(context.Background(), space)
assert.Error(app.AddApplicationToSpace(ctx, new(dns.Config))).IsNil()
assert.Error(app.AddApplicationToSpace(ctx, new(dispatcher.Config))).IsNil()
assert.Error(app.AddApplicationToSpace(ctx, new(proxyman.OutboundConfig))).IsNil()
assert.Error(app.AddApplicationToSpace(ctx, config)).IsNil()
assert.Error(space.Initialize()).IsNil()
r := FromSpace(space)
ctx = proxy.ContextWithDestination(ctx, net.TCPDestination(net.DomainAddress("v2ray.com"), 80))
tag, err := r.TakeDetour(ctx)
assert.Error(err).IsNil()
assert.String(tag).Equals("test")
}
示例7: TestSimpleRouter
func TestSimpleRouter(t *testing.T) {
assert := assert.On(t)
config := &Config{
Rule: []*RoutingRule{
{
Tag: "test",
NetworkList: &v2net.NetworkList{
Network: []v2net.Network{v2net.Network_TCP},
},
},
},
}
space := app.NewSpace()
space.BindApp(dns.APP_ID, dns.NewCacheServer(space, &dns.Config{}))
space.BindApp(dispatcher.APP_ID, dispatchers.NewDefaultDispatcher(space))
space.BindApp(proxyman.APP_ID_OUTBOUND_MANAGER, proxyman.NewDefaultOutboundHandlerManager())
r := NewRouter(config, space)
space.BindApp(APP_ID, r)
assert.Error(space.Initialize()).IsNil()
tag, err := r.TakeDetour(&proxy.SessionInfo{Destination: v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80)})
assert.Error(err).IsNil()
assert.String(tag).Equals("test")
}
示例8: Test_Connect_wss_guess_reuse
func Test_Connect_wss_guess_reuse(t *testing.T) {
assert := assert.On(t)
(&Config{Pto: "", Path: "", ConnectionReuse: true}).Apply()
i := 3
for i != 0 {
conn, err := Dial(v2net.AnyIP, v2net.TCPDestination(v2net.DomainAddress("echo.websocket.org"), 443))
assert.Error(err).IsNil()
conn.Write([]byte("echo"))
s := make(chan int)
go func() {
buf := make([]byte, 4)
conn.Read(buf)
str := string(buf)
if str != "echo" {
assert.Fail("Data mismatch")
}
s <- 0
}()
<-s
if i == 0 {
conn.SetDeadline(time.Now())
conn.SetReadDeadline(time.Now())
conn.SetWriteDeadline(time.Now())
conn.SetReusable(false)
}
conn.Close()
i--
}
}
示例9: Test_listenWSAndDial_TLS
func Test_listenWSAndDial_TLS(t *testing.T) {
assert := assert.On(t)
go func() {
<-time.After(time.Second * 5)
assert.Fail("Too slow")
}()
listen, err := ListenWS(v2net.DomainAddress("localhost"), 13143, internet.ListenOptions{
Stream: &internet.StreamConfig{
SecurityType: serial.GetMessageType(new(v2tls.Config)),
SecuritySettings: []*serial.TypedMessage{serial.ToTypedMessage(&v2tls.Config{
Certificate: []*v2tls.Certificate{tlsgen.GenerateCertificateForTest()},
})},
Protocol: internet.TransportProtocol_WebSocket,
TransportSettings: []*internet.TransportConfig{
{
Protocol: internet.TransportProtocol_WebSocket,
Settings: serial.ToTypedMessage(&Config{
Path: "wss",
ConnectionReuse: &ConnectionReuse{
Enable: true,
},
}),
},
},
},
})
assert.Error(err).IsNil()
go func() {
conn, err := listen.Accept()
assert.Error(err).IsNil()
conn.Close()
listen.Close()
}()
ctx := internet.ContextWithTransportSettings(context.Background(), &Config{
Path: "wss",
ConnectionReuse: &ConnectionReuse{
Enable: true,
},
})
ctx = internet.ContextWithSecuritySettings(ctx, &v2tls.Config{
AllowInsecure: true,
})
conn, err := Dial(ctx, v2net.TCPDestination(v2net.DomainAddress("localhost"), 13143))
assert.Error(err).IsNil()
conn.Close()
}
示例10: Test_listenWSAndDial_TLS
func Test_listenWSAndDial_TLS(t *testing.T) {
assert := assert.On(t)
go func() {
<-time.After(time.Second * 5)
assert.Fail("Too slow")
}()
(&Config{Pto: "wss", Path: "wss", ConnectionReuse: true, DeveloperInsecureSkipVerify: true, PrivKey: "./../../../testing/tls/key.pem", Cert: "./../../../testing/tls/cert.pem"}).Apply()
listen, err := ListenWS(v2net.DomainAddress("localhost"), 13143)
assert.Error(err).IsNil()
go func() {
conn, err := listen.Accept()
assert.Error(err).IsNil()
conn.Close()
listen.Close()
}()
conn, err := Dial(v2net.AnyIP, v2net.TCPDestination(v2net.DomainAddress("localhost"), 13143))
assert.Error(err).IsNil()
conn.Close()
}
示例11: TestDomainRule
func TestDomainRule(t *testing.T) {
assert := assert.On(t)
rule := ParseRule([]byte(`{
"type": "field",
"domain": [
"ooxx.com",
"oxox.com",
"regexp:\\.cn$"
],
"network": "tcp",
"outboundTag": "direct"
}`))
assert.Pointer(rule).IsNotNil()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.ooxx.com"), 80))).IsTrue()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.aabb.com"), 80))).IsFalse()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80))).IsFalse()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.12306.cn"), 80))).IsTrue()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.acn.com"), 80))).IsFalse()
}
示例12: TestDomainAddress
func TestDomainAddress(t *testing.T) {
assert := assert.On(t)
domain := "v2ray.com"
addr := v2net.DomainAddress(domain)
assert.Address(addr).IsDomain()
assert.Address(addr).IsNotIPv6()
assert.Address(addr).IsNotIPv4()
assert.String(addr.Domain()).Equals(domain)
assert.Address(addr).EqualsString("v2ray.com")
}
示例13: TestDialDomain
func TestDialDomain(t *testing.T) {
assert := assert.On(t)
server := &tcp.Server{}
dest, err := server.Start()
assert.Error(err).IsNil()
defer server.Close()
conn, err := DialToDest(nil, v2net.TCPDestination(v2net.DomainAddress("local.v2ray.com"), dest.Port))
assert.Error(err).IsNil()
assert.String(conn.RemoteAddr().String()).Equals("127.0.0.1:" + dest.Port.String())
conn.Close()
}
示例14: TestUDPDestinationEquals
func TestUDPDestinationEquals(t *testing.T) {
assert := assert.On(t)
dest := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(nil)).IsFalse()
dest2 := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(dest2)).IsTrue()
dest3 := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(dest3)).IsFalse()
dest4 := v2net.UDPDestination(v2net.DomainAddress("v2ray.com"), 80)
assert.Bool(dest.Equals(dest4)).IsFalse()
}
示例15: TestIPRule
func TestIPRule(t *testing.T) {
assert := assert.On(t)
rule := ParseRule([]byte(`{
"type": "field",
"ip": [
"10.0.0.0/8",
"192.0.0.0/24"
],
"network": "tcp",
"outboundTag": "direct"
}`))
assert.Pointer(rule).IsNotNil()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.DomainAddress("www.ooxx.com"), 80))).IsFalse()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{10, 0, 0, 1}), 80))).IsTrue()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80))).IsFalse()
assert.Bool(rule.Apply(v2net.TCPDestination(v2net.IPAddress([]byte{192, 0, 0, 1}), 80))).IsTrue()
}