Exemple #1
0
// Validates that info to peer connect is equal.
func TestUDPCommConfig(t *testing.T) {
	cryptoKey := []byte{1, 55, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}
	enc := physical.CreateUDPCommConfig("127.0.0.1:16000", cryptoKey)

	expected := "7b22446174616772616d4c656e677468223a3531322c2245787465726e616c486f7374223a7b224950223a223132372e302e302e31222c22506f7274223a31363030302c225a6f6e65223a22227d2c2243727970746f4b6579223a22415463414141454141414142414141414151414141414541414141424141414141514141414145414141413d227d"
	assert.Equal(t, expected, enc, "Error in encoding")

}
Exemple #2
0
func makePeer(pubKey cipher.PubKey, addr string, port int) *Peer {
	portStr := strconv.Itoa(port)
	address := addr + ":" + portStr

	peer := Peer{}
	peer.Peer = pubKey
	peer.Info = physical.CreateUDPCommConfig(address, nil)
	return &peer
}
Exemple #3
0
// Integration Test that:
// 1. create two nodes (Nodo 1 y Nodo 2), these task are execute in Goroutines separated.
// 2. Assign transport the nodes (Nodo 1 y Nodo 2).
// 3. Connect the nodes (Nodo 1 y Nodo 2) together.
// 4. Create a route, send data over the route, confirm receipt of data
func TestNodeCase1(t *testing.T) {
	var wg sync.WaitGroup
	wg.Add(2)

	statusChannel := make(chan bool, 2)

	// Initialize Node 2
	config2 := createTestConfig(configText2)
	cryptoKey2 := []byte{1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 11, 22, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0}
	config2.PeersToConnect[0].Info = physical.CreateUDPCommConfig("127.0.0.1:15000", cryptoKey2)
	go InitializeNode(2, config2, &wg, statusChannel)

	// Initialize Node 1
	config1 := createTestConfig(configText1)
	cryptoKey1 := []byte{1, 0, 0, 0, 1, 0, 44, 22, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 11, 0, 0}
	config1.PeersToConnect[0].Info = physical.CreateUDPCommConfig("127.0.0.1:17000", cryptoKey1)
	go InitializeNode(1, config1, &wg, statusChannel)

	timeout := 30 * time.Second
	for i := 1; i <= 2; i++ {
		select {
		case status, ok := <-statusChannel:
			{
				if ok {
					assert.True(t, status, "Error expected Status True")
				}
			}
		case <-time.After(timeout):
			{
				assert.Fail(t, "Error TimeOut", "")
				break
			}
		}
	}
	wg.Wait()
	fmt.Println("Done")
}
Exemple #4
0
// Create two Nodes using the functions created in the meshnet library.
func TestSendMessage(t *testing.T) {
	// Setup for Node 1
	config1 := createTestConfig2(15000)
	// Setup for Node 2
	config2 := createTestConfig2(17000)

	peersToConnect1 := []PeersToConnect{}
	peerToConnect1 := PeersToConnect{}
	peerToConnect1.Peer = config2.NodeConfig.PubKey
	peerToConnect1.Info = physical.CreateUDPCommConfig("127.0.0.1:17000", nil)
	peersToConnect1 = append(peersToConnect1, peerToConnect1)
	config1.PeersToConnect = peersToConnect1

	routesToEstablish1 := []RouteConfig{}
	routeToEstablish1 := RouteConfig{}
	routeToEstablish1.ID = uuid.NewV4()
	routeToEstablish1.Peers = append(routeToEstablish1.Peers, config2.NodeConfig.PubKey)
	routesToEstablish1 = append(routesToEstablish1, routeToEstablish1)
	config1.RoutesToEstablish = routesToEstablish1

	messagesToSend1 := []MessageToSend{}
	messageToSend1 := MessageToSend{}
	messageToSend1.ThruRoute = routeToEstablish1.ID
	messageToSend1.Contents = []byte("Message 1")
	messagesToSend1 = append(messagesToSend1, messageToSend1)
	config1.MessagesToSend = messagesToSend1

	messagesToReceive1 := []MessageToReceive{}
	messageToReceive1 := MessageToReceive{}
	messageToReceive1.Contents = []byte("Message 2")
	messagesToReceive1 = append(messagesToReceive1, messageToReceive1)
	config1.MessagesToReceive = messagesToReceive1

	peersToConnect2 := []PeersToConnect{}
	peerToConnect2 := PeersToConnect{}
	peerToConnect2.Peer = config1.NodeConfig.PubKey
	peerToConnect2.Info = physical.CreateUDPCommConfig("127.0.0.1:15000", nil)
	peersToConnect2 = append(peersToConnect2, peerToConnect2)
	config2.PeersToConnect = peersToConnect2

	messagesToReceive2 := []MessageToReceive{}
	messageToReceive2 := MessageToReceive{}
	messageToReceive2.Contents = []byte("Message 1")
	messageToReceive2.Reply = []byte("Message 2")
	messagesToReceive2 = append(messagesToReceive2, messageToReceive2)
	config2.MessagesToReceive = messagesToReceive2

	var wg sync.WaitGroup
	wg.Add(2)

	statusChannel := make(chan bool, 2)

	// Initialize Node 2
	go InitializeNode(2, config2, &wg, statusChannel)

	// Initialize Node 1
	go InitializeNode(1, config1, &wg, statusChannel)

	timeout := 30 * time.Second
	for i := 1; i <= 2; i++ {
		select {
		case status, ok := <-statusChannel:
			{
				if ok {
					assert.True(t, status, "Error expected Status True")
				}
			}
		case <-time.After(timeout):
			{
				assert.Fail(t, "Error TimeOut", "")
				break
			}
		}
	}
	wg.Wait()
	fmt.Println("Done")
}