|
|
@ -216,30 +216,25 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) |
|
|
|
|
|
|
|
cnote << "Testing Whisper async forwarding..."; |
|
|
|
VerbosityHolder setTemporaryLevel(2); |
|
|
|
|
|
|
|
unsigned const TestValue = 8456; |
|
|
|
unsigned result = 0; |
|
|
|
bool done = false; |
|
|
|
|
|
|
|
// Host must be configured not to share peers.
|
|
|
|
Host host1("Forwarder", NetworkPreferences("127.0.0.1", 30305, false)); |
|
|
|
host1.setIdealPeerCount(1); |
|
|
|
auto whost1 = host1.registerCapability(new WhisperHost()); |
|
|
|
auto whost1 = host1.registerCapability(new WhisperHost(false)); |
|
|
|
host1.start(); |
|
|
|
while (!host1.haveNetwork()) |
|
|
|
this_thread::sleep_for(chrono::milliseconds(2)); |
|
|
|
|
|
|
|
auto w = whost1->installWatch(BuildTopicMask("test")); // only interested in odd packets
|
|
|
|
bool startedForwarder = false; |
|
|
|
std::thread forwarder([&]() |
|
|
|
{ |
|
|
|
setThreadName("forwarder"); |
|
|
|
|
|
|
|
this_thread::sleep_for(chrono::milliseconds(500)); |
|
|
|
|
|
|
|
this_thread::sleep_for(chrono::milliseconds(50)); |
|
|
|
startedForwarder = true; |
|
|
|
|
|
|
|
/// Only interested in odd packets
|
|
|
|
auto w = whost1->installWatch(BuildTopicMask("test")); |
|
|
|
|
|
|
|
while (!done) |
|
|
|
{ |
|
|
|
for (auto i: whost1->checkWatch(w)) |
|
|
@ -257,31 +252,30 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) |
|
|
|
{ |
|
|
|
Host host2("Sender", NetworkPreferences("127.0.0.1", 30300, false)); |
|
|
|
host2.setIdealPeerCount(1); |
|
|
|
shared_ptr<WhisperHost> whost2 = host2.registerCapability(new WhisperHost()); |
|
|
|
shared_ptr<WhisperHost> whost2 = host2.registerCapability(new WhisperHost(false)); |
|
|
|
host2.start(); |
|
|
|
while (!host2.haveNetwork()) |
|
|
|
this_thread::sleep_for(chrono::milliseconds(2)); |
|
|
|
host2.addNode(host1.id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), 30305, 30305)); |
|
|
|
|
|
|
|
while (!host2.peerCount()) |
|
|
|
host2.requirePeer(host1.id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), 30305, 30305)); |
|
|
|
while (!host2.peerCount() || !host1.peerCount()) |
|
|
|
this_thread::sleep_for(chrono::milliseconds(5)); |
|
|
|
|
|
|
|
KeyPair us = KeyPair::create(); |
|
|
|
whost2->post(us.sec(), RLPStream().append(1).out(), BuildTopic("test")); |
|
|
|
whost2->post(us.sec(), RLPStream().append(TestValue).out(), BuildTopic("test"), 777000); |
|
|
|
this_thread::sleep_for(chrono::milliseconds(250)); |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
Host ph("Listener", NetworkPreferences("127.0.0.1", 30300, false)); |
|
|
|
ph.setIdealPeerCount(1); |
|
|
|
shared_ptr<WhisperHost> wh = ph.registerCapability(new WhisperHost()); |
|
|
|
shared_ptr<WhisperHost> wh = ph.registerCapability(new WhisperHost(false)); |
|
|
|
ph.start(); |
|
|
|
while (!ph.haveNetwork()) |
|
|
|
this_thread::sleep_for(chrono::milliseconds(2)); |
|
|
|
ph.addNode(host1.id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), 30305, 30305)); |
|
|
|
|
|
|
|
/// Only interested in odd packets
|
|
|
|
auto w = wh->installWatch(BuildTopicMask("test")); |
|
|
|
auto w = wh->installWatch(BuildTopicMask("test")); // only interested in odd packets
|
|
|
|
ph.requirePeer(host1.id(), NodeIPEndpoint(bi::address::from_string("127.0.0.1"), 30305, 30305)); |
|
|
|
|
|
|
|
for (int i = 0; i < 200 && !result; ++i) |
|
|
|
{ |
|
|
@ -298,7 +292,7 @@ BOOST_AUTO_TEST_CASE(asyncforwarding) |
|
|
|
|
|
|
|
done = true; |
|
|
|
forwarder.join(); |
|
|
|
BOOST_REQUIRE_EQUAL(result, 1); |
|
|
|
BOOST_REQUIRE_EQUAL(result, TestValue); |
|
|
|
} |
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(topicAdvertising) |
|
|
|