RTRlib
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
rtr.h
1 /*
2  * This file is part of RTRlib.
3  *
4  * This file is subject to the terms and conditions of the MIT license.
5  * See the file LICENSE in the top level directory for more details.
6  *
7  * Website: http://rtrlib.realmv6.org/
8  */
9 
10 
18 #ifndef RTR_H
19 #define RTR_H
20 #include <time.h>
21 #include <stdbool.h>
22 #include <stdint.h>
23 #include <pthread.h>
24 #include "rtrlib/pfx/pfx.h"
25 #include "rtrlib/transport/transport.h"
26 
27 #define RTR_DBG(fmt, ...) lrtr_dbg("RTR Socket: " fmt, ## __VA_ARGS__)
28 #define RTR_DBG1(a) lrtr_dbg("RTR Socket: " a)
29 
30 static const uint8_t RTR_PROTOCOL_VERSION_0 = 0;
31 static const uint8_t RTR_PROTOCOL_VERSION_1 = 1;
32 
33 static const uint8_t RTR_PROTOCOL_MIN_SUPPORTED_VERSION = 0;
34 static const uint8_t RTR_PROTOCOL_MAX_SUPPORTED_VERSION = 1;
35 
36 enum rtr_rtvals {
37  RTR_SUCCESS = 0,
38  RTR_ERROR = -1,
39  RTR_INVALID_PARAM = -2
40 };
41 
48 
51 
54 
57 
60 
63 
66 
69 
72 
75 };
76 
77 struct rtr_socket;
78 
82 typedef void (*rtr_connection_state_fp)(const struct rtr_socket *rtr_socket, const enum rtr_socket_state state, void *connection_state_fp_param);
83 
106 struct rtr_socket {
107  struct tr_socket *tr_socket;
108  unsigned int refresh_interval;
109  time_t last_update;
110  unsigned int expire_interval;
111  unsigned int retry_interval;
112  enum rtr_socket_state state;
113  uint32_t session_id;
114  bool request_session_id;
115  uint32_t serial_number;
116  struct pfx_table *pfx_table;
117  pthread_t thread_id;
118  rtr_connection_state_fp connection_state_fp;
119  void *connection_state_fp_param;
120  unsigned int version;
121  bool has_received_pdus;
122  struct spki_table *spki_table;
123 };
124 
145 int rtr_init(struct rtr_socket *rtr_socket, struct tr_socket *tr_socket, struct pfx_table *pfx_table,
146  struct spki_table *spki_table, const unsigned int refresh_interval,
147  const unsigned int expire_interval, const unsigned int retry_interval,
148  rtr_connection_state_fp fp, void *fp_data);
149 
157 int rtr_start(struct rtr_socket *rtr_socket);
158 
163 void rtr_stop(struct rtr_socket *rtr_socket);
164 
171 const char *rtr_state_to_str(enum rtr_socket_state state);
172 
173 #endif
174 /* @} */
A transport socket datastructure.
Definition: transport.h:95
Definition: rtr.h:50
Definition: rtr.h:71
Definition: rtr.h:68
Definition: rtr.h:74
void(* rtr_connection_state_fp)(const struct rtr_socket *rtr_socket, const enum rtr_socket_state state, void *connection_state_fp_param)
A function pointer that is called if the state of the rtr socket has changed.
Definition: rtr.h:82
pfx_table.
Definition: trie-pfx.h:35
int rtr_start(struct rtr_socket *rtr_socket)
Starts the RTR protocol state machine in a pthread. Connection to the rtr_server will be established ...
Definition: rtr.c:99
Definition: rtr.h:56
Definition: rtr.h:62
Definition: rtr.h:47
rtr_socket_state
States of the RTR socket.
Definition: rtr.h:45
A RTR socket.
Definition: rtr.h:106
Definition: rtr.h:53
void rtr_stop(struct rtr_socket *rtr_socket)
Stops the RTR connection and terminate the transport connection.
Definition: rtr.c:232
Definition: rtr.h:59
int rtr_init(struct rtr_socket *rtr_socket, struct tr_socket *tr, struct pfx_table *pfx_table, struct spki_table *spki_table, const unsigned int refresh_interval, const unsigned int expire_interval, const unsigned int retry_interval, rtr_connection_state_fp fp, void *fp_param)
Initializes a rtr_socket.
Definition: rtr.c:55
Definition: rtr.h:65
const char * rtr_state_to_str(enum rtr_socket_state state)
Converts a rtr_socket_state to a String.
Definition: rtr.c:246