コード例 #1
0
ファイル: vmess.go プロジェクト: amazted/v2ray-core
// 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)
	}
}
コード例 #2
0
ファイル: vmess.go プロジェクト: sign4bill/v2ray-core
// 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)
	}
}
コード例 #3
0
ファイル: config.go プロジェクト: NinjaOSX/v2ray-core
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,
	}
}
コード例 #4
0
ファイル: freedom_test.go プロジェクト: road0001/v2ray-core
func TestUDPSend(t *testing.T) {
	assert := unit.Assert(t)

	data2Send := "Data to be sent to remote"

	udpServer := &udp.Server{
		Port: 0,
		MsgProcessor: func(data []byte) []byte {
			buffer := make([]byte, 0, 2048)
			buffer = append(buffer, []byte("Processed: ")...)
			buffer = append(buffer, data...)
			return buffer
		},
	}

	udpServerAddr, err := udpServer.Start()
	assert.Error(err).IsNil()

	connOutput := bytes.NewBuffer(make([]byte, 0, 1024))
	ich := &proxymocks.InboundConnectionHandler{
		ConnInput:  bytes.NewReader([]byte("Not Used")),
		ConnOutput: connOutput,
	}

	connhandler.RegisterInboundConnectionHandlerFactory("mock_ich", ich)

	pointPort := v2nettesting.PickPort()
	config := mocks.Config{
		PortValue: pointPort,
		InboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "mock_ich",
			SettingsValue: nil,
		},
		OutboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "freedom",
			SettingsValue: nil,
		},
	}

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

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

	data2SendBuffer := alloc.NewBuffer().Clear()
	data2SendBuffer.Append([]byte(data2Send))
	dest := v2net.NewUDPDestination(udpServerAddr)
	ich.Communicate(v2net.NewPacket(dest, data2SendBuffer, false))
	assert.Bytes(connOutput.Bytes()).Equals([]byte("Processed: Data to be sent to remote"))
}
コード例 #5
0
ファイル: freedom_test.go プロジェクト: nenew/v2ray-core
func TestUDPSend(t *testing.T) {
	assert := unit.Assert(t)

	data2Send := "Data to be sent to remote"

	udpServer := &udp.Server{
		Port: 0,
		MsgProcessor: func(data []byte) []byte {
			buffer := make([]byte, 0, 2048)
			buffer = append(buffer, []byte("Processed: ")...)
			buffer = append(buffer, data...)
			return buffer
		},
	}

	udpServerAddr, err := udpServer.Start()
	assert.Error(err).IsNil()

	ich := &mocks.InboundConnectionHandler{
		Data2Send:    []byte("Not Used"),
		DataReturned: bytes.NewBuffer(make([]byte, 0, 1024)),
	}

	core.RegisterInboundConnectionHandlerFactory("mock_ich", ich)

	pointPort := uint16(38724)
	config := mocks.Config{
		PortValue: pointPort,
		InboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "mock_ich",
			ContentValue:  nil,
		},
		OutboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "freedom",
			ContentValue:  nil,
		},
	}

	point, err := core.NewPoint(&config)
	assert.Error(err).IsNil()

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

	dest := v2net.NewUDPDestination(udpServerAddr)
	ich.Communicate(v2net.NewPacket(dest, []byte(data2Send), false))
	assert.Bytes(ich.DataReturned.Bytes()).Equals([]byte("Processed: Data to be sent to remote"))
}
コード例 #6
0
ファイル: dokodemo.go プロジェクト: hackiechain/v2ray-core
func (this *DokodemoDoor) handleUDPPackets(udpConn *net.UDPConn) {
	defer udpConn.Close()
	for this.accepting {
		buffer := alloc.NewBuffer()
		nBytes, addr, err := udpConn.ReadFromUDP(buffer.Value)
		buffer.Slice(0, nBytes)
		if err != nil {
			buffer.Release()
			log.Error("Dokodemo failed to read from UDP: %v", err)
			return
		}

		packet := v2net.NewPacket(v2net.NewUDPDestination(this.address), buffer, false)
		ray := this.dispatcher.DispatchToOutbound(packet)
		close(ray.InboundInput())

		for payload := range ray.InboundOutput() {
			udpConn.WriteToUDP(payload.Value, addr)
		}
	}
}
コード例 #7
0
ファイル: outbound.go プロジェクト: amazted/v2ray-core
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)
		}
		if rawTarget.TCPEnabled {
			targets = append(targets, &vmessconfig.OutboundTarget{
				Destination: v2net.NewTCPDestination(rawTarget.Address),
				Accounts:    users,
			})
		}
		if rawTarget.UDPEnabled {
			targets = append(targets, &vmessconfig.OutboundTarget{
				Destination: v2net.NewUDPDestination(rawTarget.Address),
				Accounts:    users,
			})
		}
	}
	return targets
}
コード例 #8
0
ファイル: udp.go プロジェクト: nenew/v2ray-core
func (request *Socks5UDPRequest) Destination() v2net.Destination {
	return v2net.NewUDPDestination(request.Address)
}
コード例 #9
0
ファイル: vmess_test.go プロジェクト: NinjaOSX/v2ray-core
func TestVMessInAndOutUDP(t *testing.T) {
	assert := unit.Assert(t)

	data2Send := "The data to be send to outbound server."

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

	core.RegisterInboundConnectionHandlerFactory("mock_ich", ich)

	configA := mocks.Config{
		PortValue: portA,
		InboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "mock_ich",
			SettingsValue: nil,
		},
		OutboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "vmess",
			SettingsValue: &VMessOutboundConfig{
				[]VNextConfig{
					VNextConfig{
						Address: "127.0.0.1",
						Port:    13841,
						Network: "udp",
						Users: []VMessUser{
							VMessUser{Id: "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"},
						},
					},
				},
			},
		},
	}

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

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

	portB := uint16(13841)

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

	core.RegisterOutboundConnectionHandlerFactory("mock_och", och)

	configB := mocks.Config{
		PortValue: portB,
		InboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "vmess",
			SettingsValue: &VMessInboundConfig{
				AllowedClients: []VMessUser{
					VMessUser{Id: "ad937d9d-6e23-4a5a-ba23-bce5092a7c51"},
				},
				UDPEnabled: true,
			},
		},
		OutboundConfigValue: &mocks.ConnectionConfig{
			ProtocolValue: "mock_och",
			SettingsValue: nil,
		},
	}

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

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

	data2SendBuffer := alloc.NewBuffer()
	data2SendBuffer.Clear()
	data2SendBuffer.Append([]byte(data2Send))
	dest := v2net.NewUDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}, 80))
	ich.Communicate(v2net.NewPacket(dest, data2SendBuffer, false))
	assert.Bytes([]byte(data2Send)).Equals(och.Data2Send.Bytes())
	assert.Bytes(ich.DataReturned.Bytes()).Equals(och.Data2Return)
}
コード例 #10
0
ファイル: vmess_test.go プロジェクト: kennshi/v2ray-core
func TestVMessInAndOutUDP(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 := v2nettesting.PickPort()
	portB := v2nettesting.PickPort()

	ichConnInput := []byte("The data to be send to outbound server.")
	ichConnOutput := bytes.NewBuffer(make([]byte, 0, 1024))
	ich := &proxymocks.InboundConnectionHandler{
		ConnInput:  bytes.NewReader(ichConnInput),
		ConnOutput: ichConnOutput,
	}

	connhandler.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}, portB),
						UDPEnabled: true,
						Users: []*json.ConfigUser{
							&json.ConfigUser{Id: testAccount},
						},
					},
				},
			},
		},
	}

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

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

	ochConnInput := []byte("The data to be returned to inbound server.")
	ochConnOutput := bytes.NewBuffer(make([]byte, 0, 1024))
	och := &proxymocks.OutboundConnectionHandler{
		ConnInput:  bytes.NewReader(ochConnInput),
		ConnOutput: ochConnOutput,
	}

	connhandler.RegisterOutboundConnectionHandlerFactory("mock_och", och)

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

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

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

	data2SendBuffer := alloc.NewBuffer()
	data2SendBuffer.Clear()
	data2SendBuffer.Append([]byte(data2Send))
	dest := v2net.NewUDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}, 80))
	ich.Communicate(v2net.NewPacket(dest, data2SendBuffer, false))

	assert.Bytes(ichConnInput).Equals(ochConnOutput.Bytes())
	assert.Bytes(ichConnOutput.Bytes()).Equals(ochConnInput)
}