|  | @@ -1,86 +1,21 @@
 | 
											
												
													
														|  |  package freedom
 |  |  package freedom
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  import (
 |  |  import (
 | 
											
												
													
														|  | -	"bytes"
 |  | 
 | 
											
												
													
														|  |  	"fmt"
 |  |  	"fmt"
 | 
											
												
													
														|  |  	"net"
 |  |  	"net"
 | 
											
												
													
														|  |  	"testing"
 |  |  	"testing"
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	"golang.org/x/net/proxy"
 |  |  	"golang.org/x/net/proxy"
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -	"github.com/v2ray/v2ray-core/app"
 |  | 
 | 
											
												
													
														|  | -	"github.com/v2ray/v2ray-core/app/dispatcher"
 |  | 
 | 
											
												
													
														|  | -	"github.com/v2ray/v2ray-core/common/alloc"
 |  | 
 | 
											
												
													
														|  |  	v2io "github.com/v2ray/v2ray-core/common/io"
 |  |  	v2io "github.com/v2ray/v2ray-core/common/io"
 | 
											
												
													
														|  | -	v2net "github.com/v2ray/v2ray-core/common/net"
 |  | 
 | 
											
												
													
														|  |  	v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
 |  |  	v2nettesting "github.com/v2ray/v2ray-core/common/net/testing"
 | 
											
												
													
														|  | -	v2proxy "github.com/v2ray/v2ray-core/proxy"
 |  | 
 | 
											
												
													
														|  |  	_ "github.com/v2ray/v2ray-core/proxy/socks"
 |  |  	_ "github.com/v2ray/v2ray-core/proxy/socks"
 | 
											
												
													
														|  | -	proxytesting "github.com/v2ray/v2ray-core/proxy/testing"
 |  | 
 | 
											
												
													
														|  | -	proxymocks "github.com/v2ray/v2ray-core/proxy/testing/mocks"
 |  | 
 | 
											
												
													
														|  |  	"github.com/v2ray/v2ray-core/shell/point"
 |  |  	"github.com/v2ray/v2ray-core/shell/point"
 | 
											
												
													
														|  |  	v2testing "github.com/v2ray/v2ray-core/testing"
 |  |  	v2testing "github.com/v2ray/v2ray-core/testing"
 | 
											
												
													
														|  |  	"github.com/v2ray/v2ray-core/testing/assert"
 |  |  	"github.com/v2ray/v2ray-core/testing/assert"
 | 
											
												
													
														|  |  	"github.com/v2ray/v2ray-core/testing/servers/tcp"
 |  |  	"github.com/v2ray/v2ray-core/testing/servers/tcp"
 | 
											
												
													
														|  | -	"github.com/v2ray/v2ray-core/testing/servers/udp"
 |  | 
 | 
											
												
													
														|  |  )
 |  |  )
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -func TestUDPSend(t *testing.T) {
 |  | 
 | 
											
												
													
														|  | -	v2testing.Current(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,
 |  | 
 | 
											
												
													
														|  | -	}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -	protocol, err := proxytesting.RegisterInboundConnectionHandlerCreator("mock_ich",
 |  | 
 | 
											
												
													
														|  | -		func(space app.Space, config interface{}) (v2proxy.InboundHandler, error) {
 |  | 
 | 
											
												
													
														|  | -			ich.PacketDispatcher = space.GetApp(dispatcher.APP_ID).(dispatcher.PacketDispatcher)
 |  | 
 | 
											
												
													
														|  | -			return ich, nil
 |  | 
 | 
											
												
													
														|  | -		})
 |  | 
 | 
											
												
													
														|  | -	assert.Error(err).IsNil()
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -	pointPort := v2nettesting.PickPort()
 |  | 
 | 
											
												
													
														|  | -	config := &point.Config{
 |  | 
 | 
											
												
													
														|  | -		Port: pointPort,
 |  | 
 | 
											
												
													
														|  | -		InboundConfig: &point.ConnectionConfig{
 |  | 
 | 
											
												
													
														|  | -			Protocol: protocol,
 |  | 
 | 
											
												
													
														|  | -			Settings: nil,
 |  | 
 | 
											
												
													
														|  | -		},
 |  | 
 | 
											
												
													
														|  | -		OutboundConfig: &point.ConnectionConfig{
 |  | 
 | 
											
												
													
														|  | -			Protocol: "freedom",
 |  | 
 | 
											
												
													
														|  | -			Settings: 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))
 |  | 
 | 
											
												
													
														|  | -	ich.Communicate(v2net.NewPacket(udpServerAddr, data2SendBuffer, false))
 |  | 
 | 
											
												
													
														|  | -	assert.Bytes(connOutput.Bytes()).Equals([]byte("Processed: Data to be sent to remote"))
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |  func TestSocksTcpConnect(t *testing.T) {
 |  |  func TestSocksTcpConnect(t *testing.T) {
 | 
											
												
													
														|  |  	v2testing.Current(t)
 |  |  	v2testing.Current(t)
 | 
											
												
													
														|  |  	port := v2nettesting.PickPort()
 |  |  	port := v2nettesting.PickPort()
 |