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


Golang net.NewTCPDestination函数代码示例

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


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

示例1: handleSocks4

func (server *SocksServer) handleSocks4(reader io.Reader, writer io.Writer, auth protocol.Socks4AuthenticationRequest) error {
	result := protocol.Socks4RequestGranted
	if auth.Command == protocol.CmdBind {
		result = protocol.Socks4RequestRejected
	}
	socks4Response := protocol.NewSocks4AuthenticationResponse(result, auth.Port, auth.IP[:])

	responseBuffer := alloc.NewSmallBuffer().Clear()
	socks4Response.Write(responseBuffer)
	writer.Write(responseBuffer.Value)
	responseBuffer.Release()

	if result == protocol.Socks4RequestRejected {
		log.Warning("Unsupported socks 4 command %d", auth.Command)
		return UnsupportedSocksCommand
	}

	dest := v2net.NewTCPDestination(v2net.IPAddress(auth.IP[:], auth.Port))
	data, err := v2net.ReadFrom(reader, nil)
	if err != nil {
		return err
	}

	packet := v2net.NewPacket(dest, data, true)
	server.transport(reader, writer, packet)
	return nil
}
开发者ID:kennshi,项目名称:v2ray-core,代码行数:27,代码来源:socks.go

示例2: ToVNextServer

func (config VNextConfig) ToVNextServer(network string) VNextServer {
	users := make([]user.User, 0, len(config.Users))
	for _, user := range config.Users {
		vuser, err := user.ToUser()
		if err != nil {
			panic(log.Error("Failed to convert %v to User.", user))
		}
		users = append(users, vuser)
	}
	ip := net.ParseIP(config.Address)
	if ip == nil {
		panic(log.Error("Unable to parse VNext IP: %s", config.Address))
	}
	address := v2net.IPAddress(ip, config.Port)
	var dest v2net.Destination
	if network == "tcp" {
		dest = v2net.NewTCPDestination(address)
	} else {
		dest = v2net.NewUDPDestination(address)
	}
	return VNextServer{
		Destination: dest,
		Users:       users,
	}
}
开发者ID:NinjaOSX,项目名称:v2ray-core,代码行数:25,代码来源:config.go

示例3: Destination

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

示例4: Destination

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

示例5: TestDomainMatching

func TestDomainMatching(t *testing.T) {
	assert := unit.Assert(t)

	rule := &FieldRule{
		Domain: NewStringList("v2ray.com"),
	}
	dest := v2net.NewTCPDestination(v2net.DomainAddress("www.v2ray.com", 80))
	assert.Bool(rule.Apply(dest)).IsTrue()
}
开发者ID:sign4bill,项目名称:v2ray-core,代码行数:9,代码来源:fieldrule_test.go

示例6: TestPortMatching

func TestPortMatching(t *testing.T) {
	assert := unit.Assert(t)

	rule := &FieldRule{
		Port: &v2nettesting.PortRange{
			FromValue: 0,
			ToValue:   100,
		},
	}
	dest := v2net.NewTCPDestination(v2net.DomainAddress("www.v2ray.com", 80))
	assert.Bool(rule.Apply(dest)).IsTrue()
}
开发者ID:sign4bill,项目名称:v2ray-core,代码行数:12,代码来源:fieldrule_test.go

示例7: TestIPMatching

func TestIPMatching(t *testing.T) {
	assert := unit.Assert(t)

	rawJson := `{
    "type": "field",
    "ip": "10.0.0.0/8",
    "tag": "test"
  }`
	rule := parseRule([]byte(rawJson))
	dest := v2net.NewTCPDestination(v2net.IPAddress([]byte{10, 0, 0, 1}, 80))
	assert.Bool(rule.Apply(dest)).IsTrue()
}
开发者ID:sign4bill,项目名称:v2ray-core,代码行数:12,代码来源:fieldrule_test.go

示例8: TestDomainNotMatchingDomain

func TestDomainNotMatchingDomain(t *testing.T) {
	assert := unit.Assert(t)

	rawJson := `{
    "type": "field",
    "domain": ["google.com", "v2ray.com"],
    "tag": "test"
  }`
	rule := parseRule([]byte(rawJson))
	dest := v2net.NewTCPDestination(v2net.DomainAddress("baidu.com", 80))
	assert.Bool(rule.Apply(dest)).IsFalse()
}
开发者ID:sign4bill,项目名称:v2ray-core,代码行数:12,代码来源:fieldrule_test.go

示例9: TestPortNotMatching

func TestPortNotMatching(t *testing.T) {
	assert := unit.Assert(t)

	rawJson := `{
    "type": "field",
    "port": "80-100",
    "tag": "test"
  }`
	rule := parseRule([]byte(rawJson))
	dest := v2net.NewTCPDestination(v2net.IPAddress([]byte{10, 0, 0, 1}, 79))
	assert.Bool(rule.Apply(dest)).IsFalse()
}
开发者ID:sign4bill,项目名称:v2ray-core,代码行数:12,代码来源:fieldrule_test.go

示例10: Destination

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

示例11: Targets

func (o *Outbound) Targets() []*vmessconfig.OutboundTarget {
	targets := make([]*vmessconfig.OutboundTarget, 0, 2*len(o.TargetList))
	for _, rawTarget := range o.TargetList {
		users := make([]vmessconfig.User, 0, len(rawTarget.Users))
		for _, rawUser := range rawTarget.Users {
			users = append(users, rawUser)
		}
		targets = append(targets, &vmessconfig.OutboundTarget{
			Destination: v2net.NewTCPDestination(rawTarget.Address),
			Accounts:    users,
		})
	}
	return targets
}
开发者ID:road0001,项目名称:v2ray-core,代码行数:14,代码来源:outbound.go

示例12: HandleTCPConnection

func (this *DokodemoDoor) HandleTCPConnection(conn *net.TCPConn) {
	defer conn.Close()

	packet := v2net.NewPacket(v2net.NewTCPDestination(this.address), nil, true)
	ray := this.dispatcher.DispatchToOutbound(packet)

	var inputFinish, outputFinish sync.Mutex
	inputFinish.Lock()
	outputFinish.Lock()

	reader := v2net.NewTimeOutReader(this.config.Timeout, conn)
	go dumpInput(reader, ray.InboundInput(), &inputFinish)
	go dumpOutput(conn, ray.InboundOutput(), &outputFinish)

	outputFinish.Lock()
}
开发者ID:hackiechain,项目名称:v2ray-core,代码行数:16,代码来源:dokodemo.go

示例13: handleSocks4

func (server *SocksServer) handleSocks4(reader io.Reader, writer io.Writer, auth protocol.Socks4AuthenticationRequest) error {
	result := protocol.Socks4RequestGranted
	if auth.Command == protocol.CmdBind {
		result = protocol.Socks4RequestRejected
	}
	socks4Response := protocol.NewSocks4AuthenticationResponse(result, auth.Port, auth.IP[:])
	writer.Write(socks4Response.ToBytes(nil))

	if result == protocol.Socks4RequestRejected {
		return errors.NewInvalidOperationError("Socks4 command " + strconv.Itoa(int(auth.Command)))
	}

	dest := v2net.NewTCPDestination(v2net.IPAddress(auth.IP[:], auth.Port))
	data, err := v2net.ReadFrom(reader)
	if err != nil {
		return err
	}

	packet := v2net.NewPacket(dest, data, true)
	server.transport(reader, writer, packet)
	return nil
}
开发者ID:iusky,项目名称:v2ray-core,代码行数:22,代码来源:socks.go

示例14: TestVMessInAndOut

func TestVMessInAndOut(t *testing.T) {
	assert := unit.Assert(t)

	data2Send := "The data to be send to outbound server."
	testAccount, err := config.NewID("ad937d9d-6e23-4a5a-ba23-bce5092a7c51")
	assert.Error(err).IsNil()

	portA := uint16(17392)
	ich := &mocks.InboundConnectionHandler{
		Data2Send:    []byte(data2Send),
		DataReturned: bytes.NewBuffer(make([]byte, 0, 1024)),
	}

	proxy.RegisterInboundConnectionHandlerFactory("mock_ich", ich)

	configA := mocks.Config{
		PortValue: portA,
		InboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "mock_ich",
			SettingsValue: nil,
		},
		OutboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "vmess",
			SettingsValue: &json.Outbound{
				[]*json.ConfigTarget{
					&json.ConfigTarget{
						Address:    v2net.IPAddress([]byte{127, 0, 0, 1}, 13829),
						TCPEnabled: true,
						Users: []*json.ConfigUser{
							&json.ConfigUser{Id: testAccount},
						},
					},
				},
			},
		},
	}

	pointA, err := point.NewPoint(&configA)
	assert.Error(err).IsNil()

	err = pointA.Start()
	assert.Error(err).IsNil()

	portB := uint16(13829)

	och := &mocks.OutboundConnectionHandler{
		Data2Send:   bytes.NewBuffer(make([]byte, 0, 1024)),
		Data2Return: []byte("The data to be returned to inbound server."),
	}

	proxy.RegisterOutboundConnectionHandlerFactory("mock_och", och)

	configB := mocks.Config{
		PortValue: portB,
		InboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "vmess",
			SettingsValue: &json.Inbound{
				AllowedClients: []*json.ConfigUser{
					&json.ConfigUser{Id: testAccount},
				},
			},
		},
		OutboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "mock_och",
			SettingsValue: nil,
		},
	}

	pointB, err := point.NewPoint(&configB)
	assert.Error(err).IsNil()

	err = pointB.Start()
	assert.Error(err).IsNil()

	dest := v2net.NewTCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}, 80))
	ich.Communicate(v2net.NewPacket(dest, nil, true))
	assert.Bytes([]byte(data2Send)).Equals(och.Data2Send.Bytes())
	assert.Bytes(ich.DataReturned.Bytes()).Equals(och.Data2Return)
}
开发者ID:amazted,项目名称:v2ray-core,代码行数:79,代码来源:vmess_test.go

示例15: HandleConnection

func (server *SocksServer) HandleConnection(connection net.Conn) error {
	defer connection.Close()

	reader := connection.(io.Reader)

	auth, auth4, err := protocol.ReadAuthentication(reader)
	if err != nil && err != protocol.ErrorSocksVersion4 {
		log.Error("Error on reading authentication: %v", err)
		return err
	}

	var dest v2net.Destination

	// TODO refactor this part
	if err == protocol.ErrorSocksVersion4 {
		result := protocol.Socks4RequestGranted
		if auth4.Command == protocol.CmdBind {
			result = protocol.Socks4RequestRejected
		}
		socks4Response := protocol.NewSocks4AuthenticationResponse(result, auth4.Port, auth4.IP[:])
		protocol.WriteSocks4AuthenticationResponse(connection, socks4Response)

		if result == protocol.Socks4RequestRejected {
			return ErrorCommandNotSupported
		}

		dest = v2net.NewTCPDestination(v2net.IPAddress(auth4.IP[:], auth4.Port))
	} else {
		expectedAuthMethod := protocol.AuthNotRequired
		if server.config.AuthMethod == JsonAuthMethodUserPass {
			expectedAuthMethod = protocol.AuthUserPass
		}

		if !auth.HasAuthMethod(expectedAuthMethod) {
			authResponse := protocol.NewAuthenticationResponse(protocol.AuthNoMatchingMethod)
			err = protocol.WriteAuthentication(connection, authResponse)
			if err != nil {
				log.Error("Error on socksio write authentication: %v", err)
				return err
			}
			log.Warning("Client doesn't support allowed any auth methods.")
			return ErrorAuthenticationFailed
		}

		authResponse := protocol.NewAuthenticationResponse(expectedAuthMethod)
		err = protocol.WriteAuthentication(connection, authResponse)
		if err != nil {
			log.Error("Error on socksio write authentication: %v", err)
			return err
		}
		if server.config.AuthMethod == JsonAuthMethodUserPass {
			upRequest, err := protocol.ReadUserPassRequest(reader)
			if err != nil {
				log.Error("Failed to read username and password: %v", err)
				return err
			}
			status := byte(0)
			if !upRequest.IsValid(server.config.Username, server.config.Password) {
				status = byte(0xFF)
			}
			upResponse := protocol.NewSocks5UserPassResponse(status)
			err = protocol.WriteUserPassResponse(connection, upResponse)
			if err != nil {
				log.Error("Error on socksio write user pass response: %v", err)
				return err
			}
			if status != byte(0) {
				return ErrorInvalidUser
			}
		}

		request, err := protocol.ReadRequest(reader)
		if err != nil {
			log.Error("Error on reading socks request: %v", err)
			return err
		}

		response := protocol.NewSocks5Response()

		if request.Command == protocol.CmdBind || request.Command == protocol.CmdUdpAssociate {
			response := protocol.NewSocks5Response()
			response.Error = protocol.ErrorCommandNotSupported
			err = protocol.WriteResponse(connection, response)
			if err != nil {
				log.Error("Error on socksio write response: %v", err)
				return err
			}
			log.Warning("Unsupported socks command %d", request.Command)
			return ErrorCommandNotSupported
		}

		response.Error = protocol.ErrorSuccess
		response.Port = request.Port
		response.AddrType = request.AddrType
		switch response.AddrType {
		case protocol.AddrTypeIPv4:
			copy(response.IPv4[:], request.IPv4[:])
		case protocol.AddrTypeIPv6:
			copy(response.IPv6[:], request.IPv6[:])
		case protocol.AddrTypeDomain:
//.........这里部分代码省略.........
开发者ID:hxford,项目名称:v2ray-core,代码行数:101,代码来源:socks.go


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