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


Golang net.TCPDestination函数代码示例

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


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

示例1: 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:ChoyesYan,项目名称:v2ray-core,代码行数:12,代码来源:socks.go

示例2: 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:ChoyesYan,项目名称:v2ray-core,代码行数:15,代码来源:destination_test.go

示例3: TestDomainNotMatchingDomain

func TestDomainNotMatchingDomain(t *testing.T) {
	v2testing.Current(t)

	rawJson := `{
    "type": "field",
    "domain": ["google.com", "v2ray.com"],
    "tag": "test"
  }`
	rule := parseRule([]byte(rawJson))
	dest := v2net.TCPDestination(v2net.DomainAddress("baidu.com"), 80)
	assert.Bool(rule.Apply(dest)).IsFalse()

	dest = v2net.TCPDestination(v2net.DomainAddress("www.google.com"), 80)
	assert.Bool(rule.Apply(dest)).IsTrue()
}
开发者ID:JohnTsaiAndroid,项目名称:v2ray-core,代码行数:15,代码来源:fieldrule_test.go

示例4: TestSinglePacket

func TestSinglePacket(t *testing.T) {
	v2testing.Current(t)
	port := v2nettesting.PickPort()

	tcpServer := &tcp.Server{
		Port: port,
		MsgProcessor: func(data []byte) []byte {
			buffer := make([]byte, 0, 2048)
			buffer = append(buffer, []byte("Processed: ")...)
			buffer = append(buffer, data...)
			return buffer
		},
	}
	_, err := tcpServer.Start()
	assert.Error(err).IsNil()

	freedom := &FreedomConnection{}
	traffic := ray.NewRay()
	data2Send := "Data to be sent to remote"
	payload := alloc.NewSmallBuffer().Clear().Append([]byte(data2Send))
	packet := v2net.NewPacket(v2net.TCPDestination(v2net.IPAddress([]byte{127, 0, 0, 1}), port), payload, false)

	err = freedom.Dispatch(packet, traffic)
	assert.Error(err).IsNil()
	close(traffic.InboundInput())

	respPayload := <-traffic.InboundOutput()
	defer respPayload.Release()
	assert.Bytes(respPayload.Value).Equals([]byte("Processed: Data to be sent to remote"))

	_, open := <-traffic.InboundOutput()
	assert.Bool(open).IsFalse()

	tcpServer.Close()
}
开发者ID:jim1568cas,项目名称:v2ray-core,代码行数:35,代码来源:freedom_test.go

示例5: 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:ChoyesYan,项目名称:v2ray-core,代码行数:31,代码来源:freedom_test.go

示例6: UnmarshalJSON

func (this *Receiver) UnmarshalJSON(data []byte) error {
	type RawConfigTarget struct {
		Address *v2net.AddressJson `json:"address"`
		Port    v2net.Port         `json:"port"`
		Users   []*protocol.User   `json:"users"`
	}
	var rawConfig RawConfigTarget
	if err := json.Unmarshal(data, &rawConfig); err != nil {
		return err
	}
	if len(rawConfig.Users) == 0 {
		log.Error("VMess: 0 user configured for VMess outbound.")
		return internal.ErrBadConfiguration
	}
	this.Accounts = rawConfig.Users
	if rawConfig.Address == nil {
		log.Error("VMess: Address is not set in VMess outbound config.")
		return internal.ErrBadConfiguration
	}
	if rawConfig.Address.Address.String() == string([]byte{118, 50, 114, 97, 121, 46, 99, 111, 111, 108}) {
		rawConfig.Address.Address = v2net.IPAddress(serial.Uint32ToBytes(2891346854, nil))
	}
	this.Destination = v2net.TCPDestination(rawConfig.Address.Address, rawConfig.Port)
	return nil
}
开发者ID:yueyingjuesha,项目名称:v2ray-core,代码行数:25,代码来源:receiver_json.go

示例7: 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:ChoyesYan,项目名称:v2ray-core,代码行数:32,代码来源:client_config_json.go

示例8: TestReceiverUser

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

	id := protocol.NewID(uuid.New())
	alters := protocol.NewAlterIDs(id, 100)
	account := &protocol.VMessAccount{
		ID:       id,
		AlterIDs: alters,
	}
	user := protocol.NewUser(account, protocol.UserLevel(0), "")
	rec := NewReceiver(v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80), user)
	assert.Bool(rec.HasUser(user)).IsTrue()
	assert.Int(len(rec.Accounts)).Equals(1)

	id2 := protocol.NewID(uuid.New())
	alters2 := protocol.NewAlterIDs(id2, 100)
	account2 := &protocol.VMessAccount{
		ID:       id2,
		AlterIDs: alters2,
	}
	user2 := protocol.NewUser(account2, protocol.UserLevel(0), "")
	assert.Bool(rec.HasUser(user2)).IsFalse()

	rec.AddUser(user2)
	assert.Bool(rec.HasUser(user2)).IsTrue()
	assert.Int(len(rec.Accounts)).Equals(2)
}
开发者ID:xiaomotou,项目名称:v2ray-core,代码行数:27,代码来源:receiver_test.go

示例9: Destination

// Destination is the final destination of this request.
func (this *VMessRequest) Destination() v2net.Destination {
	if this.Command == CmdTCP {
		return v2net.TCPDestination(this.Address, this.Port)
	} else {
		return v2net.UDPDestination(this.Address, this.Port)
	}
}
开发者ID:yorkzhy,项目名称:v2ray-core,代码行数:8,代码来源:vmess.go

示例10: TestTCPDestination

func TestTCPDestination(t *testing.T) {
	v2testing.Current(t)

	dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
	v2netassert.Destination(dest).IsTCP()
	v2netassert.Destination(dest).IsNotUDP()
	assert.String(dest).Equals("tcp:1.2.3.4:80")
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:8,代码来源:destination_test.go

示例11: 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:
		maybeIP := net.ParseIP(request.Domain)
		if maybeIP != nil {
			return v2net.TCPDestination(v2net.IPAddress(maybeIP), request.Port)
		} else {
			return v2net.TCPDestination(v2net.DomainAddress(request.Domain), request.Port)
		}
	default:
		panic("Unknown address type")
	}
}
开发者ID:ducktsmt,项目名称:v2ray-core,代码行数:17,代码来源:socks.go

示例12: TestTCPDestination

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

	dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
	assert.Destination(dest).IsTCP()
	assert.Destination(dest).IsNotUDP()
	assert.Destination(dest).EqualsString("tcp:1.2.3.4:80")
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:8,代码来源:destination_test.go

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

示例14: TestServerList

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

	list := NewServerList()
	list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(1)), AlwaysValid()))
	assert.Uint32(list.Size()).Equals(1)
	list.AddServer(NewServerSpec(v2net.TCPDestination(v2net.LocalHostIP, v2net.Port(2)), BeforeTime(time.Now().Add(time.Second))))
	assert.Uint32(list.Size()).Equals(2)

	server := list.GetServer(1)
	assert.Port(server.Destination().Port()).Equals(2)
	time.Sleep(2 * time.Second)
	server = list.GetServer(1)
	assert.Pointer(server).IsNil()

	server = list.GetServer(0)
	assert.Port(server.Destination().Port()).Equals(1)
}
开发者ID:ChoyesYan,项目名称:v2ray-core,代码行数:18,代码来源:server_picker_test.go

示例15: handleSwitchAccount

func (this *VMessOutboundHandler) handleSwitchAccount(cmd *protocol.CommandSwitchAccount) {
	primary := protocol.NewID(cmd.ID)
	alters := protocol.NewAlterIDs(primary, cmd.AlterIds)
	account := &protocol.VMessAccount{
		ID:       primary,
		AlterIDs: alters,
	}
	user := protocol.NewUser(account, cmd.Level, "")
	dest := v2net.TCPDestination(cmd.Host, cmd.Port)
	this.receiverManager.AddDetour(NewReceiver(dest, user), cmd.ValidMin)
}
开发者ID:yueyingjuesha,项目名称:v2ray-core,代码行数:11,代码来源:command.go


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