Install callback to request routes when connections established.
authorJennifer Richards <jennifer@painless-security.com>
Wed, 7 Sep 2016 19:13:56 +0000 (15:13 -0400)
committerJennifer Richards <jennifer@painless-security.com>
Wed, 7 Sep 2016 19:48:40 +0000 (15:48 -0400)
include/trp_internal.h
tr/tr_trp.c
trp/trps.c

index 35f3f97..30abf54 100644 (file)
@@ -165,6 +165,7 @@ TRP_RC trpc_send_msg(TRPC_INSTANCE *trpc, const char *msg_content);
 TRPS_INSTANCE *trps_new (TALLOC_CTX *mem_ctx);
 void trps_free (TRPS_INSTANCE *trps);
 void trps_set_ptable(TRPS_INSTANCE *trps, TRP_PTABLE *ptable);
+void trps_set_peer_status_callback(TRPS_INSTANCE *trps, void (*cb)(TRP_PEER *, void *), void *cookie);
 TRP_RC trps_init_rtable(TRPS_INSTANCE *trps);
 void trps_clear_rtable(TRPS_INSTANCE *trps);
 void trps_set_connect_interval(TRPS_INSTANCE *trps, unsigned int interval);
index 11a2d30..5f78976 100644 (file)
@@ -797,6 +797,7 @@ void tr_config_changed(TR_CFG *new_cfg, void *cookie)
   trps_set_update_interval(trps, new_cfg->internal->trp_update_interval);
   trps_set_sweep_interval(trps, new_cfg->internal->trp_sweep_interval);
   trps_set_ptable(trps, new_cfg->peers);
+  trps_set_peer_status_callback(trps, tr_peer_status_change, (void *)trps);
   trps_clear_rtable(trps); /* should we do this every time??? */
   tr_add_local_routes(trps, new_cfg); /* should we do this every time??? */
   trps_update_active_routes(trps); /* find new routes */
index 1c6cde5..f770e1c 100644 (file)
@@ -130,6 +130,19 @@ void trps_set_ptable(TRPS_INSTANCE *trps, TRP_PTABLE *ptable)
   trps->ptable=ptable;
 }
 
+void trps_set_peer_status_callback(TRPS_INSTANCE *trps, void (*cb)(TRP_PEER *, void *), void *cookie)
+{
+  TRP_PTABLE_ITER *iter=NULL;
+  TRP_PEER *peer=NULL;
+  if (trps->ptable==NULL)
+    return;
+
+  iter=trp_ptable_iter_new(NULL);
+  for (peer=trp_ptable_iter_first(iter, trps->ptable); peer!=NULL; peer=trp_ptable_iter_next(iter))
+    trp_peer_set_conn_status_cb(peer, cb, cookie);
+  trp_ptable_iter_free(iter);
+}
+
 TRPC_INSTANCE *trps_find_trpc(TRPS_INSTANCE *trps, TRP_PEER *peer)
 {
   TRPC_INSTANCE *cur=NULL;