MCPcopy Create free account
hub / github.com/SNAS/openbmp / runServer

Function runServer

Server/src/openbmp.cpp:401–551  ·  view source on GitHub ↗

* Run Server loop * * \param [in] cfg Reference to the config options */

Source from the content-addressed store, hash-verified

399 * \param [in] cfg Reference to the config options
400 */
401void runServer(Config &cfg) {
402 msgBus_kafka *kafka;
403 int active_connections = 0; // Number of active connections/threads
404 int concurrent_routers = 0; // Number of concurrent routers
405 time_t last_heartbeat_time = 0;
406
407 LOG_INFO("Initializing server");
408
409 try {
410 // Define the collector hash
411 MD5 hash;
412 hash.update((unsigned char *)cfg.admin_id, strlen(cfg.admin_id));
413 hash.finalize();
414
415 // Save the hash
416 unsigned char *hash_raw = hash.raw_digest();
417 memcpy(cfg.c_hash_id, hash_raw, 16);
418 delete[] hash_raw;
419
420 // Kafka connection
421 kafka = new msgBus_kafka(logger, &cfg, cfg.c_hash_id);
422
423 // allocate and start a new bmp server
424 BMPListener *bmp_svr = new BMPListener(logger, &cfg);
425
426 collector_update_msg(kafka, cfg, MsgBusInterface::COLLECTOR_ACTION_STARTED);
427 last_heartbeat_time = time(NULL);
428
429 LOG_INFO("Ready. Waiting for connections");
430
431 // Loop to accept new connections
432 while (run) {
433 /*
434 * Check for any stale threads/connections
435 */
436 for (size_t i=0; i < thr_list.size(); i++) {
437
438 // If thread is not running, it means it terminated, so close it out
439 if (!thr_list.at(i)->running) {
440
441 // Join the thread to clean up
442 pthread_join(thr_list.at(i)->thr, NULL);
443 --active_connections;
444
445 if (!thr_list.at(i)->baselineTimeout)
446 --concurrent_routers;
447
448 // free the vector entry
449 delete thr_list.at(i);
450 thr_list.erase(thr_list.begin() + i);
451
452 collector_update_msg(kafka, cfg,
453 MsgBusInterface::COLLECTOR_ACTION_CHANGE);
454
455 }
456
457 else if (!thr_list.at(i)->baselineTimeout) {
458

Callers 1

mainFunction · 0.85

Calls 6

collector_update_msgFunction · 0.85
updateMethod · 0.80
finalizeMethod · 0.80
raw_digestMethod · 0.80
sizeMethod · 0.80

Tested by

no test coverage detected