aboutsummaryrefslogtreecommitdiff
path: root/src/feature
diff options
context:
space:
mode:
authorTaylor Yu <catalyst@torproject.org>2019-03-08 09:41:43 -0600
committerDavid Goulet <dgoulet@torproject.org>2019-06-11 11:59:30 -0400
commita8c0f4ddfe3f0a63bd499959c8d921346aa9766e (patch)
tree50793b2860d2ce1532cf23197957c2c22e10aa96 /src/feature
parenta8a0144d1183a3598bffe6c552507c9dcbdcd474 (diff)
downloadtor-a8c0f4ddfe3f0a63bd499959c8d921346aa9766e.tar.gz
tor-a8c0f4ddfe3f0a63bd499959c8d921346aa9766e.zip
Rework orconn tracking to use pubsub
Part of ticket 29976.
Diffstat (limited to 'src/feature')
-rw-r--r--src/feature/control/btrack.c8
-rw-r--r--src/feature/control/btrack_orconn.c49
-rw-r--r--src/feature/control/btrack_orconn.h3
3 files changed, 36 insertions, 24 deletions
diff --git a/src/feature/control/btrack.c b/src/feature/control/btrack.c
index d3d12cb2b7..3a6ae07881 100644
--- a/src/feature/control/btrack.c
+++ b/src/feature/control/btrack.c
@@ -24,6 +24,7 @@
#include "feature/control/btrack_circuit.h"
#include "feature/control/btrack_orconn.h"
#include "feature/control/btrack_sys.h"
+#include "lib/pubsub/pubsub.h"
#include "lib/subsys/subsys.h"
static int
@@ -44,10 +45,17 @@ btrack_fini(void)
btrack_circ_fini();
}
+static int
+btrack_add_pubsub(pubsub_connector_t *connector)
+{
+ return btrack_orconn_add_pubsub(connector);
+}
+
const subsys_fns_t sys_btrack = {
.name = "btrack",
.supported = true,
.level = -30,
.initialize = btrack_init,
.shutdown = btrack_fini,
+ .add_pubsub = btrack_add_pubsub,
};
diff --git a/src/feature/control/btrack_orconn.c b/src/feature/control/btrack_orconn.c
index 93ebe8d9cc..cbeb7b4ff1 100644
--- a/src/feature/control/btrack_orconn.c
+++ b/src/feature/control/btrack_orconn.c
@@ -45,6 +45,10 @@
#include "feature/control/btrack_orconn_cevent.h"
#include "feature/control/btrack_orconn_maps.h"
#include "lib/log/log.h"
+#include "lib/pubsub/pubsub.h"
+
+DECLARE_SUBSCRIBE(orconn_state, bto_state_rcvr);
+DECLARE_SUBSCRIBE(orconn_status, bto_status_rcvr);
/** Pair of a best ORCONN GID and with its state */
typedef struct bto_best_t {
@@ -110,16 +114,17 @@ bto_reset_bests(void)
* message comes from code in connection_or.c.
**/
static void
-bto_state_rcvr(const orconn_state_msg_t *msg)
+bto_state_rcvr(const msg_t *msg, const orconn_state_msg_t *arg)
{
bt_orconn_t *bto;
- bto = bto_find_or_new(msg->gid, msg->chan);
+ (void)msg;
+ bto = bto_find_or_new(arg->gid, arg->chan);
log_debug(LD_BTRACK, "ORCONN gid=%"PRIu64" chan=%"PRIu64
" proxy_type=%d state=%d",
- msg->gid, msg->chan, msg->proxy_type, msg->state);
- bto->proxy_type = msg->proxy_type;
- bto->state = msg->state;
+ arg->gid, arg->chan, arg->proxy_type, arg->state);
+ bto->proxy_type = arg->proxy_type;
+ bto->state = arg->state;
if (bto->is_orig)
bto_update_bests(bto);
}
@@ -130,33 +135,20 @@ bto_state_rcvr(const orconn_state_msg_t *msg)
* control.c.
**/
static void
-bto_status_rcvr(const orconn_status_msg_t *msg)
+bto_status_rcvr(const msg_t *msg, const orconn_status_msg_t *arg)
{
- switch (msg->status) {
+ (void)msg;
+ switch (arg->status) {
case OR_CONN_EVENT_FAILED:
case OR_CONN_EVENT_CLOSED:
log_info(LD_BTRACK, "ORCONN DELETE gid=%"PRIu64" status=%d reason=%d",
- msg->gid, msg->status, msg->reason);
- return bto_delete(msg->gid);
+ arg->gid, arg->status, arg->reason);
+ return bto_delete(arg->gid);
default:
break;
}
}
-/** Dispatch to individual ORCONN message handlers */
-static void
-bto_event_rcvr(const orconn_event_msg_t *msg)
-{
- switch (msg->type) {
- case ORCONN_MSGTYPE_STATE:
- return bto_state_rcvr(&msg->u.state);
- case ORCONN_MSGTYPE_STATUS:
- return bto_status_rcvr(&msg->u.status);
- default:
- tor_assert(false);
- }
-}
-
/**
* Create or update a cached ORCONN state for a newly launched
* connection, including whether it's launched by an origin circuit
@@ -190,12 +182,21 @@ int
btrack_orconn_init(void)
{
bto_init_maps();
- orconn_event_subscribe(bto_event_rcvr);
ocirc_event_subscribe(bto_chan_rcvr);
return 0;
}
+int
+btrack_orconn_add_pubsub(pubsub_connector_t *connector)
+{
+ if (DISPATCH_ADD_SUB(connector, orconn, orconn_state))
+ return -1;
+ if (DISPATCH_ADD_SUB(connector, orconn, orconn_status))
+ return -1;
+ return 0;
+}
+
/** Clear the hash maps and reset the "best" states */
void
btrack_orconn_fini(void)
diff --git a/src/feature/control/btrack_orconn.h b/src/feature/control/btrack_orconn.h
index 6ab4892a78..fed9a58eb0 100644
--- a/src/feature/control/btrack_orconn.h
+++ b/src/feature/control/btrack_orconn.h
@@ -9,6 +9,8 @@
#ifndef TOR_BTRACK_ORCONN_H
#define TOR_BTRACK_ORCONN_H
+#include "lib/pubsub/pubsub.h"
+
#ifdef BTRACK_ORCONN_PRIVATE
#include "ht.h"
@@ -33,6 +35,7 @@ typedef struct bt_orconn_t {
#endif /* defined(BTRACK_ORCONN_PRIVATE) */
int btrack_orconn_init(void);
+int btrack_orconn_add_pubsub(pubsub_connector_t *);
void btrack_orconn_fini(void);
#endif /* defined(TOR_BTRACK_ORCONN_H) */