Fully test trp_rtable code. All tests pass.
[trust_router.git] / include / trp_rtable.h
1 #ifndef _TRP_RTABLE_H_
2 #define _TRP_RTABLE_H_
3
4 #include <glib.h>
5 #include <talloc.h>
6 #include <time.h>
7
8 #include <trp_internal.h>
9
10 typedef struct trp_rentry {
11   TR_NAME *apc;
12   TR_NAME *realm;
13   TR_NAME *trust_router;
14   unsigned int metric;
15   TR_NAME *peer;
16   TR_NAME *next_hop;
17   int selected;
18   struct timespec *expiry;
19 } TRP_RENTRY;
20
21 typedef GHashTable TRP_RTABLE;
22
23 TRP_RTABLE *trp_rtable_new(void);
24 void trp_rtable_free(TRP_RTABLE *rtbl);
25 void trp_rtable_add(TRP_RTABLE *rtbl, TRP_RENTRY *entry); /* adds or updates */
26 void trp_rtable_remove(TRP_RTABLE *rtbl, TRP_RENTRY *entry);
27 size_t trp_rtable_size(TRP_RTABLE *rtbl);
28 size_t trp_rtable_apc_size(TRP_RTABLE *rtbl, TR_NAME *apc);
29 size_t trp_rtable_realm_size(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm);
30 TRP_RENTRY **trp_rtable_get_entries(TRP_RTABLE *rtbl, size_t *n_out);
31 TR_NAME **trp_rtable_get_apcs(TRP_RTABLE *rtbl, size_t *n_out);
32 TRP_RENTRY **trp_rtable_get_apc_entries(TRP_RTABLE *rtbl, TR_NAME *apc, size_t *n_out);
33 TR_NAME **trp_rtable_get_apc_realms(TRP_RTABLE *rtbl, TR_NAME *apc, size_t *n_out);
34 TRP_RENTRY **trp_rtable_get_realm_entries(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, size_t *n_out);
35 TR_NAME **trp_rtable_get_apc_realm_peers(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, size_t *n_out);
36 TRP_RENTRY *trp_rtable_get_entry(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, TR_NAME *peer);
37
38 TRP_RENTRY *trp_rentry_new(TALLOC_CTX *mem_ctx);
39 void trp_rentry_free(TRP_RENTRY *entry);
40 void trp_rentry_set_apc(TRP_RENTRY *entry, TR_NAME *apc);
41 TR_NAME *trp_rentry_get_apc(TRP_RENTRY *entry);
42 void trp_rentry_set_realm(TRP_RENTRY *entry, TR_NAME *realm);
43 TR_NAME *trp_rentry_get_realm(TRP_RENTRY *entry);
44 void trp_rentry_set_trust_router(TRP_RENTRY *entry, TR_NAME *tr);
45 TR_NAME *trp_rentry_get_trust_router(TRP_RENTRY *entry);
46 void trp_rentry_set_peer(TRP_RENTRY *entry, TR_NAME *peer);
47 TR_NAME *trp_rentry_get_peer(TRP_RENTRY *entry);
48 void trp_rentry_set_metric(TRP_RENTRY *entry, unsigned int metric);
49 unsigned int trp_rentry_get_metric(TRP_RENTRY *entry);
50 void trp_rentry_set_next_hop(TRP_RENTRY *entry, TR_NAME *next_hop);
51 TR_NAME *trp_rentry_get_next_hop(TRP_RENTRY *entry);
52 void trp_rentry_set_selected(TRP_RENTRY *entry, int sel);
53 int trp_rentry_get_selected(TRP_RENTRY *entry);
54 void trp_rentry_set_expiry(TRP_RENTRY *entry, struct timespec *exp);
55 struct timespec *trp_rentry_get_expiry(TRP_RENTRY *entry);
56
57 #endif /* _TRP_RTABLE_H_ */