aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authordec05eba <0xdec05eba@gmail.com>2018-05-16 07:25:22 +0200
committerdec05eba <0xdec05eba@gmail.com>2018-05-16 07:25:25 +0200
commitba8631c5f75df45fb07726e0aab3bb0834d6a5b6 (patch)
treefa9270cfb2c774ef9448f2d398b1fa24ac5ecf87 /tests
parent16a9b3e33cd4e377417dcc785be7e19bf71e18b9 (diff)
Add functions to send/receive custom messages
Diffstat (limited to 'tests')
-rw-r--r--tests/main.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/main.cpp b/tests/main.cpp
index dd56164..e819684 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -266,6 +266,39 @@ int main()
assertEquals(1, createNodeCounter);
assertEquals(2, addDataCounter);
assertEquals(1, addUserCounter);
+
+ dht::InfoHash customMessageKey = Database::getInfoHash("asdf", 4);
+ sibs::SafeSerializer messageToSendSerializer;
+ messageToSendSerializer.add((u32)10);
+
+ u32 receivedNumber = 0;
+ database.receiveCustomMessage(customMessageKey, [&receivedNumber](const void *data, usize size)
+ {
+ sibs::SafeDeserializer deserializer((const u8*)data, size);
+ receivedNumber = deserializer.extract<u32>();
+ sibs::SafeSerializer serializer;
+ serializer.add((u32)20);
+ return serializer;
+ });
+
+ u32 sendCustomMessageResponseNumber = 0;
+ database.sendCustomMessage(customMessageKey, move(messageToSendSerializer.getBuffer()), [&sendCustomMessageResponseNumber](bool gotResponse, const void *data, usize size)
+ {
+ if(!gotResponse)
+ {
+ Log::error("Didn't get reponse!");
+ return true;
+ }
+
+ sibs::SafeDeserializer deserializer((const u8*)data, size);
+ sendCustomMessageResponseNumber = deserializer.extract<u32>();
+ return false;
+ });
+
+
+ this_thread::sleep_for(chrono::seconds(3));
+ assertEquals((u32)10, receivedNumber);
+ assertEquals((u32)20, sendCustomMessageResponseNumber);
}
return 0;