diff --git a/bin/main b/bin/main index 5a29ac0..781b7bd 100755 Binary files a/bin/main and b/bin/main differ diff --git a/src/main.cpp b/src/main.cpp index aff51da..bcb8dda 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -132,16 +132,25 @@ int main() { } //network test + std::cout << std::endl << std::endl << "Testing networking " << std::endl; + + std::vector keys5 = Encryption::generateKeypair(); + Mesh mesh3; + Mesh::Node node5 = mesh3.addNode("127.0.0.1:8080", keys5[1]); + //path + std::vector path3 = { node5, node5}; + //message + Message message5("NULL", "Hello, world!"); + message5 = message5.encode(path3); + //send a message from node1 to node1 using the networking class Networking networking(node1.bindAddress(), node1.bindPort()); networking.startListeningThread(); std::cout << "Started Listening for messages..." << std::endl; - //encode the message but use the manual path instead of the mesh generated path as decoding with private keys only works if there is multiple nodes and we are simulating a mesh here - Message message3 = message1.encode(path2); //send the message - networking.sendMessage(node1.bindAddress(), node1.bindPort(), message3.toString()); - + std::cout << "sending message..." << std::endl; + networking.sendMessage(node1.bindAddress(), node1.bindPort(), message5.toString()); return 0; diff --git a/src/networking.cpp b/src/networking.cpp index 937fb3a..9875ee4 100644 --- a/src/networking.cpp +++ b/src/networking.cpp @@ -68,10 +68,14 @@ void Networking::listenForMessages() { //parse the message to get the next address Message message(receivedMessage); + //decrypt the message with the private key of this node to get the next address and content + message.decode(Encryption::getPrivateKey()); std::string nextAddress = message.getNextAddress(); int nextPort = message.getNextPort(message.getNextAddressFull()); - if (nextAddress == ipAddress || message.isDestination()) { + + if (message.isDestination()) { std::cout << "Message has reached destination" << std::endl; + std::cout << "Message content: " << message.getContent() << std::endl; } else { std::cout << "Message is not for this node, sending to " << message.getNextAddressFull() << std::endl; sendMessage(nextAddress, nextPort, message.getContent());