diff options
author | dec05eba <dec05eba@protonmail.com> | 2018-05-16 07:25:22 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-08-18 23:25:46 +0200 |
commit | 92d6393a34dac4b3d623a5169e2b50a9518b4976 (patch) | |
tree | a318cc84e3837f61c03cd4a0533c3380bb5fdbde /tests | |
parent | c0574f16ca7960a3301230ba36ba96148818e229 (diff) |
Add functions to send/receive custom messages
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.cpp | 33 |
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; |