MCPcopy Create free account
hub / github.com/HumbleNet/HumbleNet / processMessage

Function processMessage

tests/test_peer.cpp:125–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123
124
125void 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

Callers 2

main_loopFunction · 0.85
RunMethod · 0.85

Calls 4

connectedToPeerFunction · 0.85
processKnownPeersFunction · 0.85
sendHelloFunction · 0.85
strMethod · 0.80

Tested by

no test coverage detected