| 123 | |
| 124 | |
| 125 | void processMessage(PeerId peer, const char* buff, size_t length) |
| 126 | { |
| 127 | flatbuffers::Verifier v(reinterpret_cast<const uint8_t*>(buff), length); |
| 128 | |
| 129 | if (!TestClient::VerifyMessageBuffer(v)) { |
| 130 | std::cout << "Invalid buffer received" << std::endl; |
| 131 | return; |
| 132 | } |
| 133 | auto message = TestClient::GetMessage(buff); |
| 134 | |
| 135 | auto message_type = message->message_type(); |
| 136 | |
| 137 | if (message_type == TestClient::MessageSwitch_HelloPeer) { |
| 138 | auto hello = reinterpret_cast<const TestClient::HelloPeer*>(message->message()); |
| 139 | std::cout << "Received hello from peer " << peer << " response " << hello->is_response() << std::endl; |
| 140 | connectedToPeer(peer); |
| 141 | |
| 142 | processKnownPeers(hello->peers()); |
| 143 | |
| 144 | |
| 145 | if (!hello->is_response()) { |
| 146 | sendHello(peer, true); |
| 147 | } |
| 148 | } else if (message_type == TestClient::MessageSwitch_Chat) { |
| 149 | auto chat = reinterpret_cast<const TestClient::Chat*>(message->message()); |
| 150 | std::cout << "Peer " << peer << ": " << chat->message()->str() << std::endl; |
| 151 | } else { |
| 152 | std::cout << "Unexpected message type received " << message_type << std::endl; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // input helpers for desktop builds |
| 157 |
no test coverage detected