| 
					
				 | 
			
			
				@@ -11,6 +11,7 @@ import ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"github.com/v2ray/v2ray-core/proxy/dokodemo/config/json" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	_ "github.com/v2ray/v2ray-core/proxy/freedom" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"github.com/v2ray/v2ray-core/testing/servers/tcp" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"github.com/v2ray/v2ray-core/testing/servers/udp" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	"github.com/v2ray/v2ray-core/testing/unit" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -75,3 +76,64 @@ func TestDokodemoTCP(t *testing.T) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	assert.String("Processed: " + data2Send).Equals(string(response[:nBytes])) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+func TestDokodemoUDP(t *testing.T) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	assert := unit.Assert(t) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	port := v2nettesting.PickPort() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	data2Send := "Data to be sent to remote." 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	udpServer := &udp.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 := udpServer.Start() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	assert.Error(err).IsNil() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	pointPort := v2nettesting.PickPort() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	networkList := v2netjson.NetworkList([]string{"udp"}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	config := mocks.Config{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		PortValue: pointPort, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		InboundConfigValue: &mocks.ConnectionConfig{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			ProtocolValue: "dokodemo-door", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			SettingsValue: &json.DokodemoConfig{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Host:    "127.0.0.1", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Port:    int(port), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Network: &networkList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+				Timeout: 0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		OutboundConfigValue: &mocks.ConnectionConfig{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			ProtocolValue: "freedom", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+			SettingsValue: nil, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	point, err := point.NewPoint(&config) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	assert.Error(err).IsNil() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	err = point.Start() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	assert.Error(err).IsNil() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	udpClient, err := net.DialUDP("udp", nil, &net.UDPAddr{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		IP:   []byte{127, 0, 0, 1}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Port: int(pointPort), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		Zone: "", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	assert.Error(err).IsNil() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	udpClient.Write([]byte(data2Send)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	response := make([]byte, 1024) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	nBytes, err := udpClient.Read(response) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	assert.Error(err).IsNil() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	udpClient.Close() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	assert.String("Processed: " + data2Send).Equals(string(response[:nBytes])) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |