Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: refactoring and more checks in prince source (#32)
* add cmake build definition, remove makefile * create include directories for headers * add install target to cmake * switch to custom types for topology, node and prince_handler * use a common free_<type> approach in all our data structures * move topology struct and functions to topology module * format nicely parser.c * format nicely control flow, add nicer errors and log messages * refactor prince_handler constructor * print errors for new socker * format nicely socket, parser, config modules * fix return code for main, print error when opening shared library * refactor config module - use types - more error messages - avoid exiting on unknown configuration keys * define names for invalid structs and use them * format nicely functions in plugin interface header * explicitly state that netjson has been chosen as default * order headers in oonf library * refactor topology module - more error checking on malloc - format nicely * indent correctly * rename module parser to topology_parser * move plugin type declaration to common header * add missing get_initial_timers implementation to oonf library * create load_plugin module * create prince_handler module - move structs and constructor/destructor to module - set up cmake for new module * create config structs for graph and proto, make new modules this is very tricky as it requires freeing two more pointers in prince_handler_t and adding functions to create and free this new structs * add graph_config and proto_config when creating a prince_handler * early return when supplied conf poiter is invalid * implement loading of plugin functions * check malloc in new plugin implementation for olsr * do sanity check in prince main function * fix get_topology to behave as unix suppose * free temporary prince_handler in config modules * fix graph_parser header, format nicely source * more checks in prince main on bad pointers * follow unix conventions - return 0 on success - be portable * refactor for error checking - check for mallocs - check for return values * parse netjson and add error messages for unknown keys * update error check in prince * move test directory outside of prince * more error checking in olsr and socket * remove graph_parser reference as there is a custom parser for topology data we don't need to supply it to a plugin * fix indentation issue * remove http_receive function as it's not used * fix new_plugin_p signature * update readme * move creation of graph_parser in prince module this will ensure that the graph parser is always created and freed from prince constructor and destructor * add malloc check to brandes module * move plugin creationg to prince_handler * remove duplicate file write * update prince_handler id from procedure * implement valid_topo * update error message for jsoninfo parser * update find_node to return 0 on success * add exponential backoff on socket connecting * handle errors when connecting this will provide a way to filter on the errors types when trying to reconnect remove loading prototype of configurations * make get_initial_timer behave * set default timers when none are recovered * set protocol as olsrv1 in jsoninfo parser * remove duplicate target * remove duplicate declaration in brandes
- Loading branch information
Showing
80 changed files
with
1,830 additions
and
1,277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
cmake_minimum_required(VERSION 3.9 FATAL_ERROR) | ||
|
||
set(CMAKE_C_COMPILER gcc) | ||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g") | ||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -Wall -Werror=implicit-function-declaration -O2") | ||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS} -Wall -Werror=implicit-function-declaration -O2 -g") | ||
|
||
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib/prince") | ||
|
||
project(poprouting LANGUAGES C) | ||
|
||
find_package(Threads) | ||
|
||
add_executable(prince | ||
graph-parser_c/src/biconnected.c | ||
graph-parser_c/src/brandes.c | ||
graph-parser_c/src/graph/graph.c | ||
graph-parser_c/src/graph/list.c | ||
graph-parser_c/src/graph_parser.c | ||
graph-parser_c/src/network_change.c | ||
prince/src/config.c | ||
prince/src/config_proto.c | ||
prince/src/config_graph.c | ||
prince/src/load_plugin.c | ||
prince/src/prince.c | ||
prince/src/prince_handler.c | ||
prince/src/socket.c | ||
prince/src/topology.c | ||
prince/src/topology_parser.c | ||
) | ||
|
||
target_link_libraries(prince | ||
${CMAKE_DL_LIBS} | ||
${CMAKE_THREAD_LIBS_INIT} | ||
m | ||
json-c | ||
) | ||
|
||
include_directories( | ||
prince/include | ||
graph-parser_c/include | ||
) | ||
|
||
add_library(prince_oonf MODULE | ||
prince/lib/oonf/oonf.c | ||
prince/src/topology_parser.c | ||
prince/src/socket.c | ||
prince/src/topology.c | ||
prince/src/topology_parser.c | ||
) | ||
|
||
add_library(prince_olsr MODULE | ||
prince/lib/olsrd/olsr.c | ||
prince/src/socket.c | ||
prince/src/topology.c | ||
prince/src/topology_parser.c | ||
) | ||
|
||
add_library(prince_test MODULE | ||
prince/lib/testlib/test.c | ||
prince/src/topology_parser.c | ||
prince/src/socket.c | ||
prince/src/topology.c | ||
prince/src/topology_parser.c | ||
) | ||
|
||
install(TARGETS | ||
prince | ||
prince_oonf | ||
prince_olsr | ||
RUNTIME DESTINATION bin | ||
LIBRARY DESTINATION lib/prince | ||
) | ||
|
||
install(TARGETS | ||
prince | ||
prince_test | ||
RUNTIME DESTINATION bin | ||
LIBRARY DESTINATION lib/prince | ||
COMPONENT test | ||
EXCLUDE_FROM_ALL | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* File: graph.h | ||
* Author: mb03 | ||
* | ||
* Created on December 7, 2016, 3:48 PM | ||
*/ | ||
|
||
#ifndef GRAPH_H | ||
#define GRAPH_H | ||
|
||
#include "list.h" | ||
#include <stdbool.h> | ||
#include <string.h> | ||
|
||
#define INVALID_NODE_GRAPH NULL | ||
#define INVALID_EDGE_GRAPH NULL | ||
#define INVALID_GRAPH NULL | ||
#define NODE_GRAPH_SIZE sizeof(struct node_graph) | ||
#define EDGE_GRAPH_SIZE sizeof(struct edge_graph) | ||
#define GRAPH_SIZE sizeof(struct graph) | ||
|
||
/** | ||
* Structs and functions used to represent a graph. Further detail in grap.c | ||
*/ | ||
struct node_graph { | ||
struct list neighbours; | ||
char * name; | ||
int node_graph_id; | ||
}; | ||
|
||
typedef struct node_graph * node_graph_t; | ||
|
||
|
||
struct edge_graph { | ||
struct node_graph *to; | ||
double value; | ||
}; | ||
|
||
typedef struct edge_graph * edge_graph_t; | ||
|
||
|
||
struct graph { | ||
struct list nodes; | ||
bool directed; | ||
}; | ||
|
||
typedef struct graph * graph_t; | ||
|
||
|
||
void init_graph(graph_t g); | ||
|
||
void add_edge_graph(graph_t g, | ||
const char * name_from, | ||
const char * name_to, | ||
double value, | ||
bool directed); | ||
|
||
void add_edge_graph_return_node_indexes(graph_t g, | ||
const char * name_from, | ||
const char * name_to, | ||
double value, | ||
bool directed, | ||
int * nodefrom, | ||
int * nodeto); | ||
|
||
void free_graph(graph_t g); | ||
|
||
#endif /* GRAPH_H */ |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.