@@ -36,26 +36,27 @@ using namespace dev::eth;
3636using namespace dev ::p2p;
3737using namespace dev ::shh;
3838
39- #if 0
39+ #if 1
4040int main ()
4141{
4242 DownloadMan man;
4343 DownloadSub s0 (man);
4444 DownloadSub s1 (man);
4545 DownloadSub s2 (man);
4646 man.resetToChain (h256s ({u256 (0 ), u256 (1 ), u256 (2 ), u256 (3 ), u256 (4 ), u256 (5 ), u256 (6 ), u256 (7 ), u256 (8 )}));
47- cnote << s0.nextFetch(2);
48- cnote << s1.nextFetch(2);
49- cnote << s2.nextFetch(2);
50- s0.noteBlock(u256(0 ));
47+ assert (( s0.nextFetch (2 ) == h256Set{(u256) 7 , (u256) 8 }) );
48+ assert (( s1.nextFetch (2 ) == h256Set{(u256) 5 , (u256) 6 }) );
49+ assert (( s2.nextFetch (2 ) == h256Set{(u256) 3 , (u256) 4 }) );
50+ s0.noteBlock (u256 (8 ));
5151 s0.doneFetch ();
52- cnote << s0.nextFetch(2);
53- s1.noteBlock(u256(2 ));
54- s1.noteBlock(u256(3 ));
52+ assert (( s0.nextFetch (2 ) == h256Set{(u256) 2 , (u256) 7 }) );
53+ s1.noteBlock (u256 (6 ));
54+ s1.noteBlock (u256 (5 ));
5555 s1.doneFetch ();
56- cnote << s1.nextFetch(2);
57- s0.doneFetch();
58- cnote << s0.nextFetch(2);
56+ assert ((s1.nextFetch (2 ) == h256Set{(u256)0 , (u256)1 }));
57+ s0.doneFetch (); // TODO: check exact semantics of doneFetch & nextFetch. Not sure if they're right -> doneFetch calls resetFetch which kills all the info of past fetches.
58+ cdebug << s0.nextFetch (2 );
59+ assert ((s0.nextFetch (2 ) == h256Set{(u256)3 , (u256)4 }));
5960
6061/* RangeMask<unsigned> m(0, 100);
6162 cnote << m;
@@ -73,49 +74,70 @@ int main()
7374}
7475#endif
7576
76- int main ( int argc, char ** argv )
77+ /* int other(bool& o_started )
7778{
78- g_logVerbosity = 20 ;
79-
80- short listenPort = 30303 ;
81- string remoteHost;
82- short remotePort = 30303 ;
79+ setThreadName("other");
8380
84- for (int i = 1 ; i < argc; ++i)
85- {
86- string arg = argv[i];
87- if (arg == " -l" && i + 1 < argc)
88- listenPort = (short )atoi (argv[++i]);
89- else if (arg == " -r" && i + 1 < argc)
90- remoteHost = argv[++i];
91- else if (arg == " -p" && i + 1 < argc)
92- remotePort = (short )atoi (argv[++i]);
93- else
94- remoteHost = argv[i];
95- }
81+ short listenPort = 30300;
9682
9783 Host ph("Test", NetworkPreferences(listenPort, "", false, true));
9884 auto wh = ph.registerCapability(new WhisperHost());
9985
10086 ph.start();
10187
102- if (!remoteHost.empty ())
103- ph.connect (remoteHost, remotePort);
88+ o_started = true;
10489
10590 /// Only interested in odd packets
10691 auto w = wh->installWatch(BuildTopicMask()("odd"));
10792
108- KeyPair us = KeyPair::create ();
109- for (int i = 0 ; ; ++i)
93+ unsigned last = 0;
94+ unsigned total = 0;
95+
96+ for (int i = 0; i < 100 && last < 81; ++i)
11097 {
111- wh->post (us.sec (), RLPStream ().append (i * i).out (), BuildTopic (i)(i % 2 ? " odd" : " even" ));
11298 for (auto i: wh->checkWatch(w))
11399 {
114100 Message msg = wh->envelope(i).open();
115-
101+ last = RLP(msg.payload()).toInt<unsigned>();
116102 cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt<unsigned>();
103+ total += last;
117104 }
118- this_thread::sleep_for (chrono::seconds ( 1 ));
105+ this_thread::sleep_for(chrono::milliseconds(50 ));
119106 }
120- return 0 ;
107+ return total ;
121108}
109+
110+ int main(int, char**)
111+ {
112+ g_logVerbosity = 0;
113+
114+ bool started = false;
115+ unsigned result;
116+ std::thread listener([&](){ return (result = other(started)); });
117+ while (!started)
118+ this_thread::sleep_for(chrono::milliseconds(50));
119+
120+ short listenPort = 30303;
121+ string remoteHost = "127.0.0.1";
122+ short remotePort = 30300;
123+
124+ Host ph("Test", NetworkPreferences(listenPort, "", false, true));
125+ auto wh = ph.registerCapability(new WhisperHost());
126+
127+ ph.start();
128+
129+ if (!remoteHost.empty())
130+ ph.connect(remoteHost, remotePort);
131+
132+ KeyPair us = KeyPair::create();
133+ for (int i = 0; i < 10; ++i)
134+ {
135+ wh->post(us.sec(), RLPStream().append(i * i).out(), BuildTopic(i)(i % 2 ? "odd" : "even"));
136+ this_thread::sleep_for(chrono::milliseconds(250));
137+ }
138+
139+ listener.join();
140+ assert(result == 1 + 9 + 25 + 49 + 81);
141+
142+ return 0;
143+ }*/
0 commit comments