Connect to hard-coded peer and exchange route info. Buggy and incomplete.
[trust_router.git] / trp / trp_rtable.c
index b20e788..6fbbd6f 100644 (file)
@@ -37,6 +37,7 @@ TRP_RENTRY *trp_rentry_new(TALLOC_CTX *mem_ctx)
     entry->peer=NULL;
     entry->next_hop=NULL;
     entry->selected=0;
+    entry->interval=0;
     entry->expiry=talloc(entry, struct timespec);
     if (entry->expiry==NULL) {
       talloc_free(entry);
@@ -63,6 +64,11 @@ TR_NAME *trp_rentry_get_apc(TRP_RENTRY *entry)
   return entry->apc;
 }
 
+TR_NAME *trp_rentry_dup_apc(TRP_RENTRY *entry)
+{
+  return tr_dup_name(trp_rentry_get_apc(entry));
+}
+
 void trp_rentry_set_realm(TRP_RENTRY *entry, TR_NAME *realm)
 {
   entry->realm=realm;
@@ -73,6 +79,11 @@ TR_NAME *trp_rentry_get_realm(TRP_RENTRY *entry)
   return entry->realm;
 }
 
+TR_NAME *trp_rentry_dup_realm(TRP_RENTRY *entry)
+{
+  return tr_dup_name(trp_rentry_get_realm(entry));
+}
+
 void trp_rentry_set_trust_router(TRP_RENTRY *entry, TR_NAME *tr)
 {
   entry->trust_router=tr;
@@ -83,6 +94,11 @@ TR_NAME *trp_rentry_get_trust_router(TRP_RENTRY *entry)
   return entry->trust_router;
 }
 
+TR_NAME *trp_rentry_dup_trust_router(TRP_RENTRY *entry)
+{
+  return tr_dup_name(trp_rentry_get_trust_router(entry));
+}
+
 void trp_rentry_set_peer(TRP_RENTRY *entry, TR_NAME *peer)
 {
   entry->peer=peer;
@@ -93,6 +109,11 @@ TR_NAME *trp_rentry_get_peer(TRP_RENTRY *entry)
   return entry->peer;
 }
 
+TR_NAME *trp_rentry_dup_peer(TRP_RENTRY *entry)
+{
+  return tr_dup_name(trp_rentry_get_peer(entry));
+}
+
 void trp_rentry_set_metric(TRP_RENTRY *entry, unsigned int metric)
 {
   entry->metric=metric;
@@ -113,6 +134,11 @@ TR_NAME *trp_rentry_get_next_hop(TRP_RENTRY *entry)
   return entry->next_hop;
 }
 
+TR_NAME *trp_rentry_dup_next_hop(TRP_RENTRY *entry)
+{
+  return tr_dup_name(trp_rentry_get_next_hop(entry));
+}
+
 void trp_rentry_set_selected(TRP_RENTRY *entry, int sel)
 {
   entry->selected=sel;
@@ -123,6 +149,16 @@ int trp_rentry_get_selected(TRP_RENTRY *entry)
   return entry->selected;
 }
 
+void trp_rentry_set_interval(TRP_RENTRY *entry, int interval)
+{
+  entry->interval=interval;
+}
+
+int trp_rentry_get_interval(TRP_RENTRY *entry)
+{
+  return entry->interval;
+}
+
 /* copies incoming value, does not assume responsibility for freeing */
 void trp_rentry_set_expiry(TRP_RENTRY *entry, struct timespec *exp)
 {
@@ -500,13 +536,9 @@ TR_NAME **trp_rtable_get_apc_realm_peers(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME
 /* Gets a single entry. Do not free it. */
 TRP_RENTRY *trp_rtable_get_entry(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm, TR_NAME *peer)
 {
-  GHashTable *apc_tbl=NULL;
   GHashTable *realm_tbl=NULL;
   
-  apc_tbl=g_hash_table_lookup(rtbl, apc);
-  if (apc_tbl==NULL)
-    return NULL;
-  realm_tbl=g_hash_table_lookup(apc_tbl, realm);
+  realm_tbl=trp_rtable_get_realm_table(rtbl, apc, realm);
   if (realm_tbl==NULL)
     return NULL;
   return g_hash_table_lookup(realm_tbl, peer); /* does not copy or increment ref count */
@@ -531,6 +563,21 @@ static char *timespec_to_str(struct timespec *ts)
   return s;
 }
 
+TRP_RENTRY *trp_rtable_get_selected_entry(TRP_RTABLE *rtbl, TR_NAME *apc, TR_NAME *realm)
+{
+  size_t n=0;
+  TRP_RENTRY **entry=trp_rtable_get_realm_entries(rtbl, apc, realm, &n);
+  TRP_RENTRY *selected=NULL;
+
+  if (n==0)
+    return NULL;
+
+  while(n-- && !trp_rentry_get_selected(entry[n])) { }
+  selected=entry[n];
+  talloc_free(entry);
+  return selected;
+}
+
 /* Pretty print a route table entry to a newly allocated string. If sep is NULL,
  * returns comma+space separated string. */
 char *trp_rentry_to_str(TALLOC_CTX *mem_ctx, TRP_RENTRY *entry, const char *sep)