RTRlib
 All Data Structures Functions 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 
102 struct rtr_socket {
103  struct tr_socket *tr_socket;
104  unsigned int refresh_interval;
105  time_t last_update;
106  unsigned int expire_interval;
107  unsigned int retry_interval;
108  enum rtr_socket_state state;
109  uint32_t session_id;
110  bool request_session_id;
111  uint32_t serial_number;
112  struct pfx_table *pfx_table;
113  pthread_t thread_id;
114  rtr_connection_state_fp connection_state_fp;
115  void *connection_state_fp_param;
116  unsigned int version;
117  bool has_received_pdus;
118  struct spki_table *spki_table;
119 };
120 
141 int rtr_init(struct rtr_socket *rtr_socket, struct tr_socket *tr_socket, struct pfx_table *pfx_table,
142  struct spki_table *spki_table, const unsigned int refresh_interval,
143  const unsigned int expire_interval, const unsigned int retry_interval,
144  rtr_connection_state_fp fp, void *fp_data);
145 
153 int rtr_start(struct rtr_socket *rtr_socket);
154 
159 void rtr_stop(struct rtr_socket *rtr_socket);
160 
167 const char *rtr_state_to_str(enum rtr_socket_state state);
168 
169 #endif
170 /* @} */
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: lpfst-pfx.h:39
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:102
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