controller.cc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. extern "C" {
  2. #include <event2/listener.h>
  3. #include <event2/bufferevent.h>
  4. #include <event2/buffer.h>
  5. }
  6. #include <NTL/vec_ZZ.h>
  7. #include <NTL/ZZ.h>
  8. #include <NTL/ZZ_p.h>
  9. #include <sys/socket.h>
  10. #include <netinet/in.h>
  11. #include <arpa/inet.h>
  12. #include <fstream>
  13. #include <vector>
  14. #include <set>
  15. #include <map>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "evutils.h"
  19. #include "subproblem.h"
  20. NTL_CLIENT
  21. struct SubproblemProgress;
  22. typedef std::set<struct bufferevent *> BESet;
  23. typedef std::map<struct bufferevent *, SubproblemProgress *> BEMap;
  24. void besetdump(const BESet &bes, ostream &os)
  25. {
  26. BESet::const_iterator besit;
  27. os << hex << " ";
  28. for (besit = bes.begin(); besit != bes.end(); ++besit) {
  29. os << *besit << " ";
  30. }
  31. os << dec << "\n";
  32. }
  33. void bemapdump(const BEMap &bem, ostream &os)
  34. {
  35. BEMap::const_iterator bemit;
  36. os << hex << " ";
  37. for (bemit = bem.begin(); bemit != bem.end(); ++bemit) {
  38. os << bemit->first << "->" << bemit->second << " ";
  39. }
  40. os << dec << "\n";
  41. }
  42. struct Statuses {
  43. BESet idle;
  44. BEMap working;
  45. // Dump the state for debug purposes
  46. void dump(ostream &os) const {
  47. os << " idle (" << idle.size() << "):\n";
  48. besetdump(idle, os);
  49. os << " working (" << working.size() << "):\n";
  50. bemapdump(working, os);
  51. }
  52. };
  53. struct FactorDecomp {
  54. ZZ factor;
  55. vec_ZZ fvec;
  56. };
  57. void vsppdump(const vector<SubproblemProgress> &spv, ostream &os);
  58. static struct ControllerState {
  59. ZZ rho;
  60. FactorDecomp p, q;
  61. int working;
  62. vector<SubproblemProgress> subproblems_p, subproblems_q;
  63. Statuses dpnodes, workers;
  64. ControllerState() : working(0) {}
  65. // Dump the state for debug purposes
  66. void dump(ostream &os) const {
  67. if (!working) {
  68. os << "Not working\n";
  69. return;
  70. }
  71. os << "P:\n";
  72. vsppdump(subproblems_p, os);
  73. os << "Q:\n";
  74. vsppdump(subproblems_q, os);
  75. os << "dpnodes:\n";
  76. dpnodes.dump(os);
  77. os << "workers:\n";
  78. workers.dump(os);
  79. }
  80. } ctrlstate;
  81. struct IPPort {
  82. unsigned char ipport[6];
  83. IPPort(unsigned char *ipp) {
  84. memmove(ipport, ipp, 6);
  85. }
  86. void dump(ostream &os) const {
  87. os << int(ipport[0]) << "." << int(ipport[1]) << "." <<
  88. int(ipport[2]) << "." << int(ipport[3]) << ":" <<
  89. ((ipport[4] << 8) + ipport[5]) << " ";
  90. }
  91. };
  92. typedef vector<IPPort> IPPortSet;
  93. void ipportsetdump(const IPPortSet &ipps, ostream &os)
  94. {
  95. IPPortSet::const_iterator ippsit;
  96. os << " ";
  97. for (ippsit = ipps.begin(); ippsit != ipps.end(); ++ippsit) {
  98. ippsit->dump(os);
  99. }
  100. os << "\n";
  101. }
  102. struct SubproblemProgress : Subproblem {
  103. // The sets of dpnodes and workers currently working on this subproblem
  104. BESet dpnodes, workers;
  105. // The dpnode IPPorts registered for this subproblem
  106. IPPortSet ipports;
  107. // The desired number of DPnodes for this subproblem
  108. unsigned short desired_dpnodes;
  109. // The maximum number of workers useful for this subproblem
  110. unsigned int max_workers;
  111. // Have we found a solution?
  112. bool solved;
  113. // The solution, if found.
  114. ZZ solution;
  115. SubproblemProgress(unsigned short id, const ZZ &b, const ZZ &t,
  116. const ZZ &m, const ZZ &o, unsigned int dpf) :
  117. Subproblem(id, b, t, m, o, dpf), solved(false) {
  118. // How many DPnodes should we use for a problem of this size?
  119. desired_dpnodes = 2;
  120. // How many workers would we like to use?
  121. ZZ sorder = SqrRoot(order >> 46);
  122. if (NumBits(sorder) > 30) {
  123. // Just use all the workers we can find
  124. max_workers = 4294967295U; // 2^32 - 1
  125. } else {
  126. max_workers = trunc_long(sorder,31) + 1;
  127. }
  128. }
  129. // Stop all dpnodes and workers
  130. void stop(void) {
  131. BESet::iterator iter;
  132. unsigned char stopcmd[1] = { 'S' };
  133. for (BESet::iterator iter = dpnodes.begin(); iter != dpnodes.end();
  134. ++iter) {
  135. bufferevent_write(*iter, stopcmd, 1);
  136. ctrlstate.dpnodes.working.erase(*iter);
  137. ctrlstate.dpnodes.idle.insert(*iter);
  138. }
  139. for (BESet::iterator iter = workers.begin(); iter != workers.end();
  140. ++iter) {
  141. bufferevent_write(*iter, stopcmd, 1);
  142. ctrlstate.workers.working.erase(*iter);
  143. ctrlstate.workers.idle.insert(*iter);
  144. }
  145. dpnodes.clear();
  146. workers.clear();
  147. ipports.clear();
  148. }
  149. // Dump for debugging purposes
  150. void dump(ostream &os) const {
  151. os << " Subproblem " << problemid << "\n";
  152. os << " dpnodes (" << dpnodes.size() << "):\n";
  153. besetdump(dpnodes, os);
  154. os << " workers (" << workers.size() << "):\n";
  155. besetdump(workers, os);
  156. os << " ipports (" << ipports.size() << "):\n";
  157. ipportsetdump(ipports, os);
  158. if (solved) {
  159. os << " solution: " << solution << "\n\n";
  160. }
  161. }
  162. void worker_write(struct bufferevent *bev) {
  163. bev_write(bev);
  164. unsigned short num_ipports = ipports.size();
  165. bufferevent_write(bev, &num_ipports, 2);
  166. for (unsigned short i = 0; i < num_ipports; ++i) {
  167. bufferevent_write(bev, ipports[i].ipport, 6);
  168. }
  169. }
  170. };
  171. // Dump the state for debug purposes
  172. void vsppdump(const vector<SubproblemProgress> &spv, ostream &os)
  173. {
  174. vector<SubproblemProgress>::const_iterator spiter;
  175. int count = 0;
  176. for (spiter = spv.begin(); spiter != spv.end(); ++spiter) {
  177. ++count;
  178. os << " " << count << ":\n";
  179. spiter->dump(os);
  180. }
  181. os << "\n";
  182. }
  183. // Find a subproblem in the given vector that could use another DPnode,
  184. // and give it one of the idle ones. Only allocate it to a subproblem
  185. // with no current DPnodes if consider_empty is true.
  186. static void find_subproblem_for_dpnode(vector<SubproblemProgress> &spv,
  187. bool consider_empty)
  188. {
  189. vector<SubproblemProgress>::iterator spiter;
  190. for (spiter = spv.begin(); spiter != spv.end(); ++spiter) {
  191. if (spiter->solved) continue;
  192. if (spiter->dpnodes.size() == 0 && consider_empty == false) continue;
  193. // How many DPnodes would we like to have for this subproblem?
  194. while (spiter->dpnodes.size() < spiter->desired_dpnodes &&
  195. ctrlstate.dpnodes.idle.size() > 0) {
  196. // Get the first idle DPnode
  197. BESet::iterator beviter = ctrlstate.dpnodes.idle.begin();
  198. struct bufferevent *firstbev = *beviter;
  199. // Allocate it to the subproblem
  200. spiter->dpnodes.insert(firstbev);
  201. ctrlstate.dpnodes.working[firstbev] = &(*spiter);
  202. ctrlstate.dpnodes.idle.erase(firstbev);
  203. // Tell it to start listening for DPs
  204. spiter->bev_write(firstbev);
  205. }
  206. }
  207. }
  208. // Find a subproblem in the given vector that has all of its DPnodes and
  209. // could use another worker, and give it one of the idle ones.
  210. static void find_subproblem_for_worker(vector<SubproblemProgress> &spv)
  211. {
  212. vector<SubproblemProgress>::iterator spiter;
  213. for (spiter = spv.begin(); spiter != spv.end(); ++spiter) {
  214. if (spiter->solved) continue;
  215. while (spiter->ipports.size() == spiter->desired_dpnodes &&
  216. spiter->workers.size() < spiter->max_workers &&
  217. ctrlstate.workers.idle.size() > 0) {
  218. // Get the first idle worker
  219. BESet::iterator beviter = ctrlstate.workers.idle.begin();
  220. struct bufferevent *firstbev = *beviter;
  221. // Allocate it to the subproblem
  222. spiter->workers.insert(firstbev);
  223. ctrlstate.workers.working[firstbev] = &(*spiter);
  224. ctrlstate.workers.idle.erase(firstbev);
  225. // Tell it to start working on the subproblem
  226. spiter->worker_write(firstbev);
  227. }
  228. }
  229. }
  230. // See if there are any idle DPnodes or workers we can put to use
  231. void schedule(void)
  232. {
  233. cerr << "Before schedule:\n"; ctrlstate.dump(cerr);
  234. // Check the DPnodes
  235. // Iterate through the subproblems, looking for one that can use
  236. // another DPnode. First look for subproblems that already have
  237. // some, but not all, of their DPnodes
  238. if (ctrlstate.dpnodes.idle.size() > 0) {
  239. find_subproblem_for_dpnode(ctrlstate.subproblems_p, false);
  240. }
  241. if (ctrlstate.dpnodes.idle.size() > 0) {
  242. find_subproblem_for_dpnode(ctrlstate.subproblems_q, false);
  243. }
  244. // If there are still more dpnodes to place, start assigning them to
  245. // subproblems with no current dpnodes
  246. if (ctrlstate.dpnodes.idle.size() > 0) {
  247. find_subproblem_for_dpnode(ctrlstate.subproblems_p, true);
  248. }
  249. if (ctrlstate.dpnodes.idle.size() > 0) {
  250. find_subproblem_for_dpnode(ctrlstate.subproblems_q, true);
  251. }
  252. // Check the workers
  253. // Iterate through the subproblems, looking for one that can use
  254. // another worker.
  255. if (ctrlstate.workers.idle.size() > 0) {
  256. find_subproblem_for_worker(ctrlstate.subproblems_p);
  257. }
  258. if (ctrlstate.workers.idle.size() > 0) {
  259. find_subproblem_for_worker(ctrlstate.subproblems_q);
  260. }
  261. cerr << "After schedule:\n"; ctrlstate.dump(cerr);
  262. }
  263. typedef enum {
  264. CCSTATE_START,
  265. CCSTATE_DPWAITRESP,
  266. CCSTATE_DPLISTENING,
  267. CCSTATE_DPEXPON,
  268. CCSTATE_END
  269. } CCState;
  270. struct ControllerConnInfo {
  271. CCState state;
  272. ControllerConnInfo() : state(CCSTATE_DPWAITRESP) {}
  273. };
  274. static void controller_dpnode_reader(struct bufferevent *bev, void *ctx)
  275. {
  276. struct evbuffer *input = bufferevent_get_input(bev);
  277. ControllerConnInfo *info = (ControllerConnInfo *)ctx;
  278. unsigned char cmd[1];
  279. ZZ expon;
  280. while(1) {
  281. size_t len = evbuffer_get_length(input);
  282. switch (info->state) {
  283. case CCSTATE_START:
  284. case CCSTATE_DPWAITRESP:
  285. if (len < 1) return;
  286. bufferevent_read(bev, cmd, 1);
  287. switch (cmd[0]) {
  288. case 'L':
  289. info->state = CCSTATE_DPLISTENING;
  290. break;
  291. case 'E':
  292. info->state = CCSTATE_DPEXPON;
  293. break;
  294. default:
  295. /* Unknown DPnode command received */
  296. fprintf(stderr, "Unknown command in "
  297. "controller_dpnode_reader: "
  298. "%c\n", cmd[0]);
  299. info->state = CCSTATE_END;
  300. break;
  301. }
  302. break;
  303. case CCSTATE_DPLISTENING:
  304. // Read 6 bytes
  305. if (len < 6) return;
  306. unsigned char ipport[6];
  307. unsigned int DPip;
  308. unsigned short DPport;
  309. bufferevent_read(bev, ipport, 6);
  310. memmove(&DPip, ipport, 4);
  311. memmove(&DPport, ipport+4, 2);
  312. {
  313. struct in_addr DPaddr = { DPip };
  314. printf("DP node at %s:%d\n", inet_ntoa(DPaddr), ntohs(DPport));
  315. if (ctrlstate.dpnodes.working.count(bev) > 0) {
  316. ctrlstate.dpnodes.working[bev]->ipports.push_back(
  317. IPPort(ipport));
  318. schedule();
  319. }
  320. }
  321. info->state = CCSTATE_DPWAITRESP;
  322. break;
  323. case CCSTATE_DPEXPON:
  324. // Read the subproblemid and the answer to the subproblem
  325. if (len < 2 + 3*sizeof(unsigned int)) return;
  326. unsigned char exponbytes[2 + 3*sizeof(unsigned int)];
  327. unsigned short problemid;
  328. bufferevent_read(bev, exponbytes, 2 + 3*sizeof(unsigned int));
  329. memmove(&problemid, exponbytes, 2);
  330. ZZFromBytes(expon, exponbytes+2, 3*sizeof(unsigned int));
  331. // Find the subproblem and check the answer
  332. if (ctrlstate.dpnodes.working.count(bev) > 0) {
  333. SubproblemProgress *spp = ctrlstate.dpnodes.working[bev];
  334. if (spp->problemid == problemid &&
  335. spp->target ==
  336. PowerMod(spp->base, expon, spp->modulus)) {
  337. // Subproblem solved!
  338. spp->solution = expon;
  339. spp->solved = true;
  340. spp->stop();
  341. schedule();
  342. }
  343. }
  344. info->state = CCSTATE_DPWAITRESP;
  345. break;
  346. case CCSTATE_END:
  347. // Shut down the connection
  348. delete info;
  349. bufferevent_free(bev);
  350. return;
  351. }
  352. }
  353. }
  354. static void controller_dpnode_event_cb(struct bufferevent *bev, short events,
  355. void *ctx)
  356. {
  357. if (events & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) {
  358. ControllerConnInfo *info = (ControllerConnInfo*)ctx;
  359. fprintf(stderr, "Closing dpnode connection\n");
  360. if (ctrlstate.dpnodes.working.count(bev)) {
  361. // If we lose a dpnode from an active computation, the
  362. // computation is useless.
  363. SubproblemProgress *spp = ctrlstate.dpnodes.working[bev];
  364. ctrlstate.dpnodes.working.erase(bev);
  365. spp->dpnodes.erase(bev);
  366. spp->stop();
  367. } else {
  368. ctrlstate.dpnodes.idle.erase(bev);
  369. }
  370. delete info;
  371. bufferevent_free(bev);
  372. schedule();
  373. }
  374. }
  375. static void controller_worker_event_cb(struct bufferevent *bev, short events,
  376. void *ctx)
  377. {
  378. if (events & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) {
  379. ControllerConnInfo *info = (ControllerConnInfo*)ctx;
  380. fprintf(stderr, "Closing worker connection\n");
  381. if (ctrlstate.workers.working.count(bev)) {
  382. SubproblemProgress *spp = ctrlstate.workers.working[bev];
  383. ctrlstate.workers.working.erase(bev);
  384. spp->workers.erase(bev);
  385. } else {
  386. ctrlstate.workers.idle.erase(bev);
  387. }
  388. delete info;
  389. bufferevent_free(bev);
  390. schedule();
  391. }
  392. }
  393. static void controller_event_cb(struct bufferevent *bev, short events,
  394. void *ctx)
  395. {
  396. if (events & (BEV_EVENT_EOF|BEV_EVENT_ERROR)) {
  397. fprintf(stderr, "Closing connection\n");
  398. ControllerConnInfo *info = (ControllerConnInfo*)ctx;
  399. delete info;
  400. bufferevent_free(bev);
  401. }
  402. }
  403. // We're just going to read a single byte that will tell us whether the
  404. // peer is a DPnode or a Worker
  405. static void controller_master_reader(struct bufferevent *bev, void *ctx)
  406. {
  407. struct evbuffer *input = bufferevent_get_input(bev);
  408. size_t len = evbuffer_get_length(input);
  409. if (len < 1) return;
  410. char indata[1];
  411. bufferevent_read(bev, indata, 1);
  412. switch(indata[0]) {
  413. case 'D':
  414. printf("DPnode\n");
  415. /* Add this DPnode to the list of available ones */
  416. ctrlstate.dpnodes.idle.insert(bev);
  417. bufferevent_setcb(bev, controller_dpnode_reader, NULL,
  418. controller_dpnode_event_cb, ctx);
  419. controller_dpnode_reader(bev, ctx);
  420. schedule();
  421. return;
  422. case 'W':
  423. printf("Worker\n");
  424. ctrlstate.workers.idle.insert(bev);
  425. // We don't actually read anything from workers
  426. bufferevent_enable(bev, EV_WRITE);
  427. bufferevent_setcb(bev, NULL, NULL,
  428. controller_worker_event_cb, ctx);
  429. schedule();
  430. return;
  431. default:
  432. fprintf(stderr, "Unknown command in controller_master_reader: "
  433. "%c\n", indata[0]);
  434. ControllerConnInfo *info = (ControllerConnInfo*)ctx;
  435. delete info;
  436. bufferevent_free(bev);
  437. return;
  438. }
  439. }
  440. static void controller_accept_cb(struct evconnlistener *listener,
  441. evutil_socket_t fd, struct sockaddr *address, int socklen,
  442. void *ctx)
  443. {
  444. // Create the state of the new connection
  445. ControllerConnInfo *info = new ControllerConnInfo();
  446. // Create a bufferevent for the new connection
  447. struct event_base *base = evconnlistener_get_base(listener);
  448. struct bufferevent *bev = bufferevent_socket_new(
  449. base, fd, BEV_OPT_CLOSE_ON_FREE);
  450. bufferevent_setcb(bev, controller_master_reader, NULL,
  451. controller_event_cb, info);
  452. bufferevent_enable(bev, EV_READ|EV_WRITE);
  453. }
  454. // Create a new controller socket. bindport is the port to bind to (in
  455. // host byte order), or 0 if any port will do. ip and boundport are set
  456. // to the IP and port of the socket, in network byte order.
  457. void *controller_create(struct event_base *evbase, unsigned short bindport,
  458. unsigned int *ip, unsigned short *boundport)
  459. {
  460. return listener_create(evbase, bindport, controller_accept_cb, NULL,
  461. ip, boundport, false);
  462. }
  463. static unsigned short curproblemid = 0;
  464. // Take base and target mod f.factor, then decompose that into small
  465. // subproblems given our knowledge of the factors of phi(f.factor)
  466. static vector<SubproblemProgress> decomp(const ZZ_p &base, const ZZ_p &target,
  467. const FactorDecomp &f)
  468. {
  469. vector<SubproblemProgress> ret;
  470. // Compute phi(factor)
  471. const int fveclen = f.fvec.length();
  472. ZZ phi = to_ZZ(2);
  473. for (int i = 0; i < fveclen; ++i) {
  474. phi *= f.fvec[i];
  475. }
  476. ZZ_p::init(f.factor);
  477. for (int i = 0; i < fveclen; ++i) {
  478. const ZZ& order = f.fvec[i];
  479. ZZ quotient = phi / order;
  480. ZZ_p subgroup_base = to_ZZ_p(rep(base));
  481. subgroup_base = power(subgroup_base, quotient);
  482. ZZ_p subgroup_target = to_ZZ_p(rep(target));
  483. subgroup_target = power(subgroup_target, quotient);
  484. if (subgroup_base == 1) {
  485. // The original base wasn't a generator of the whole group
  486. if (subgroup_target == 1) {
  487. // But the target is in the subgroup. Lucky us.
  488. continue;
  489. } else {
  490. ret.clear();
  491. return ret;
  492. }
  493. }
  494. // By default, 1 in 1000 points are distinguihed points. The
  495. // number in the next line is 2^32/1000
  496. unsigned int dpfreq = 4294967;
  497. if (order < 1000) {
  498. // Just make every point a DP
  499. dpfreq = 4294967295U;
  500. } else if (NumBits(order) < 27) {
  501. // The frequency of DPs should be 10/sqrt(order) to avoid
  502. // a DP-free cycle, so dpfreq = (10*2^32)/sqrt(order)
  503. ZZ f = (to_ZZ(10) << 32) / SqrRoot(order);
  504. dpfreq = trunc_long(f, 31);
  505. }
  506. ++curproblemid;
  507. ret.push_back(SubproblemProgress(curproblemid, rep(subgroup_base),
  508. rep(subgroup_target),
  509. f.factor, order, dpfreq));
  510. }
  511. return ret;
  512. }
  513. static int generate_problem(struct event_base *evbase)
  514. {
  515. // If there's already a problem on the go, don't generate another one
  516. if (ctrlstate.working == 1) {
  517. return -1;
  518. }
  519. ctrlstate.working = 1;
  520. // Generate a DLP mod rho (in the large odd-order subgroup)
  521. ZZ_p::init(ctrlstate.rho);
  522. ZZ_p base = power(random_ZZ_p(), 2);
  523. ZZ_p target = power(random_ZZ_p(), 2);
  524. // Decompose it mod p and mod q
  525. ctrlstate.subproblems_p = decomp(base, target, ctrlstate.p);
  526. ctrlstate.subproblems_q = decomp(base, target, ctrlstate.q);
  527. schedule();
  528. return 0;
  529. }
  530. int main(int argc, char **argv)
  531. {
  532. // Initialize the prng with some randomness from the kernel
  533. unsigned char randbuf[1024];
  534. ifstream urand("/dev/urandom");
  535. urand.read((char *)randbuf, sizeof(randbuf));
  536. urand.close();
  537. ZZ randzz = ZZFromBytes(randbuf, sizeof(randbuf));
  538. SetSeed(randzz);
  539. // Read the modulus and the factorization of its totient from cin
  540. cin >> ctrlstate.rho >> ctrlstate.p.factor >> ctrlstate.p.fvec >>
  541. ctrlstate.q.factor >> ctrlstate.q.fvec;
  542. unsigned short bindport = 0;
  543. if (argc > 1) {
  544. bindport = strtoul(argv[1], NULL, 10);
  545. }
  546. struct event_base *evbase = event_base_new();
  547. unsigned int myip;
  548. unsigned short myport;
  549. controller_create(evbase, bindport, &myip, &myport);
  550. struct in_addr myaddr = { myip };
  551. printf("Bound to %s:%d\n", inet_ntoa(myaddr), ntohs(myport));
  552. // Kick off the first problem to solve
  553. generate_problem(evbase);
  554. event_base_dispatch(evbase);
  555. return 0;
  556. }