当前位置: 首页>>代码示例>>Golang>>正文


Golang net.TCPDestination函数代码示例

本文整理汇总了Golang中v2ray/com/core/common/net.TCPDestination函数的典型用法代码示例。如果您正苦于以下问题:Golang TCPDestination函数的具体用法?Golang TCPDestination怎么用?Golang TCPDestination使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了TCPDestination函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestChinaSitesJson

func TestChinaSitesJson(t *testing.T) {
	assert := assert.On(t)

	rule := ParseRule([]byte(`{
    "type": "chinasites",
    "outboundTag": "y"
  }`))
	assert.String(rule.Tag).Equals("y")
	cond, err := rule.BuildCondition()
	assert.Error(err).IsNil()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("v.qq.com"), 80),
	})).IsTrue()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("www.163.com"), 80),
	})).IsTrue()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("ngacn.cc"), 80),
	})).IsTrue()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("12306.cn"), 80),
	})).IsTrue()

	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("v2ray.com"), 80),
	})).IsFalse()
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:27,代码来源:router_test.go

示例2: TestChinaIPJson

func TestChinaIPJson(t *testing.T) {
	assert := assert.On(t)

	rule := ParseRule([]byte(`{
    "type": "chinaip",
    "outboundTag": "x"
  }`))
	assert.String(rule.Tag).Equals("x")
	cond, err := rule.BuildCondition()
	assert.Error(err).IsNil()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("121.14.1.189"), 80),
	})).IsTrue() // sina.com.cn
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("101.226.103.106"), 80),
	})).IsTrue() // qq.com
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("115.239.210.36"), 80),
	})).IsTrue() // image.baidu.com
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("120.135.126.1"), 80),
	})).IsTrue()

	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("8.8.8.8"), 80),
	})).IsFalse()
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:27,代码来源:router_test.go

示例3: 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()
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:27,代码来源:router_test.go

示例4: 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()
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:29,代码来源:ws_test.go

示例5: 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()
	cond, err := rule.BuildCondition()
	assert.Error(err).IsNil()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("www.ooxx.com"), 80),
	})).IsTrue()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("www.aabb.com"), 80),
	})).IsFalse()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), 80),
	})).IsFalse()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("www.12306.cn"), 80),
	})).IsTrue()
	assert.Bool(cond.Apply(&proxy.SessionInfo{
		Destination: v2net.TCPDestination(v2net.ParseAddress("www.acn.com"), 80),
	})).IsFalse()
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:32,代码来源:router_test.go

示例6: TestConnectionCache

func TestConnectionCache(t *testing.T) {
	assert := assert.On(t)

	pool := NewConnectionPool()
	conn := pool.Get(NewConnectionID(v2net.LocalHostIP, v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(80))))
	assert.Pointer(conn).IsNil()

	pool.Put(NewConnectionID(v2net.LocalHostIP, v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(80))), &TestConnection{id: "test"})
	conn = pool.Get(NewConnectionID(v2net.LocalHostIP, v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(80))))
	assert.String(conn.(*TestConnection).id).Equals("test")
}
开发者ID:ylywyn,项目名称:v2ray-core,代码行数:11,代码来源:pool_test.go

示例7: TestConnectionRecycle

func TestConnectionRecycle(t *testing.T) {
	assert := assert.On(t)

	pool := NewConnectionPool()
	c := &TestConnection{id: "test"}
	pool.Put(NewConnectionID(v2net.LocalHostIP, v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(80))), c)
	time.Sleep(6 * time.Second)
	assert.Bool(c.closed).IsTrue()
	conn := pool.Get(NewConnectionID(v2net.LocalHostIP, v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(80))))
	assert.Pointer(conn).IsNil()
}
开发者ID:ylywyn,项目名称:v2ray-core,代码行数:11,代码来源:pool_test.go

示例8: Destination

func (request *Socks5Request) Destination() v2net.Destination {
	switch request.AddrType {
	case AddrTypeIPv4:
		return v2net.TCPDestination(v2net.IPAddress(request.IPv4[:]), request.Port)
	case AddrTypeIPv6:
		return v2net.TCPDestination(v2net.IPAddress(request.IPv6[:]), request.Port)
	case AddrTypeDomain:
		return v2net.TCPDestination(v2net.ParseAddress(request.Domain), request.Port)
	default:
		panic("Unknown address type")
	}
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:12,代码来源:socks.go

示例9: TestTCPDestinationEquals

func TestTCPDestinationEquals(t *testing.T) {
	assert := assert.On(t)

	dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
	assert.Bool(dest.Equals(nil)).IsFalse()

	dest2 := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
	assert.Bool(dest.Equals(dest2)).IsTrue()

	dest3 := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
	assert.Bool(dest.Equals(dest3)).IsFalse()

	dest4 := v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80)
	assert.Bool(dest.Equals(dest4)).IsFalse()
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:15,代码来源:destination_test.go

示例10: 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--
	}
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:29,代码来源:ws_test.go

示例11: 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)
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:31,代码来源:freedom_test.go

示例12: handleSocks4

func (v *Server) handleSocks4(clientAddr v2net.Destination, reader *bufio.BufferedReader, writer *bufio.BufferedWriter, auth protocol.Socks4AuthenticationRequest) error {
	result := protocol.Socks4RequestGranted
	if auth.Command == protocol.CmdBind {
		result = protocol.Socks4RequestRejected
	}
	socks4Response := protocol.NewSocks4AuthenticationResponse(result, auth.Port, auth.IP[:])

	socks4Response.Write(writer)

	if result == protocol.Socks4RequestRejected {
		log.Warning("Socks: Unsupported socks 4 command ", auth.Command)
		log.Access(clientAddr, "", log.AccessRejected, ErrUnsupportedSocksCommand)
		return ErrUnsupportedSocksCommand
	}

	reader.SetCached(false)
	writer.SetCached(false)

	dest := v2net.TCPDestination(v2net.IPAddress(auth.IP[:]), auth.Port)
	session := &proxy.SessionInfo{
		Source:      clientAddr,
		Destination: dest,
		Inbound:     v.meta,
	}
	log.Access(clientAddr, dest, log.AccessAccepted, "")
	v.transport(reader, writer, session)
	return nil
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:28,代码来源:server.go

示例13: UnmarshalJSON

func (this *ClientConfig) UnmarshalJSON(data []byte) error {
	type ServerConfig struct {
		Address *v2net.AddressJson `json:"address"`
		Port    v2net.Port         `json:"port"`
		Users   []json.RawMessage  `json:"users"`
	}
	type JsonConfig struct {
		Servers []*ServerConfig `json:"servers"`
	}
	jsonConfig := new(JsonConfig)
	if err := json.Unmarshal(data, jsonConfig); err != nil {
		return errors.New("Socks|Client: Failed to parse config: " + err.Error())
	}
	this.Servers = make([]*protocol.ServerSpec, len(jsonConfig.Servers))
	for idx, serverConfig := range jsonConfig.Servers {
		server := protocol.NewServerSpec(v2net.TCPDestination(serverConfig.Address.Address, serverConfig.Port), protocol.AlwaysValid())
		for _, rawUser := range serverConfig.Users {
			user := new(protocol.User)
			if err := json.Unmarshal(rawUser, user); err != nil {
				return errors.New("Socks|Client: Failed to parse user: " + err.Error())
			}
			account := new(Account)
			if err := json.Unmarshal(rawUser, account); err != nil {
				return errors.New("Socks|Client: Failed to parse socks account: " + err.Error())
			}
			user.Account = account
			server.AddUser(user)
		}
		this.Servers[idx] = server
	}
	return nil
}
开发者ID:DZLZHCODE,项目名称:v2ray-core,代码行数:32,代码来源:client_config_json.go

示例14: 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)
}
开发者ID:v2ray,项目名称:v2ray-core,代码行数:31,代码来源:freedom_test.go

示例15: 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")
}
开发者ID:ylywyn,项目名称:v2ray-core,代码行数:29,代码来源:router_test.go


注:本文中的v2ray/com/core/common/net.TCPDestination函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。