Consistently allow policy alloc_cmux_data() and alloc_circ_data() functions to return NULL if the policy does not use this in circuitmux.c

This commit is contained in:
Andrea Shepard 2012-09-27 13:51:04 -07:00
parent 86d9d85dfc
commit debef8f0cd

View File

@ -293,7 +293,6 @@ circuitmux_detach_all_circuits(circuitmux_t *cmux)
* free it
*/
tor_assert(cmux->policy);
tor_assert(cmux->policy_data);
tor_assert(cmux->policy->free_circ_data);
/* Call free_circ_data() */
cmux->policy->free_circ_data(cmux,
@ -805,8 +804,10 @@ circuitmux_attach_circuit(circuitmux_t *cmux, circuit_t *circ,
hashent->muxinfo.cell_count = cell_count;
hashent->muxinfo.direction = direction;
/* Allocate policy specific circuit data if we need it */
if (cmux->policy && cmux->policy_data &&
cmux->policy->alloc_circ_data) {
if (cmux->policy && cmux->policy->alloc_circ_data) {
/* Assert that we have the means to free policy-specific data */
tor_assert(cmux->policy->free_circ_data);
/* Allocate it */
hashent->muxinfo.policy_data =
cmux->policy->alloc_circ_data(cmux,
cmux->policy_data,
@ -898,7 +899,6 @@ circuitmux_detach_circuit(circuitmux_t *cmux, circuit_t *circ)
if (hashent->muxinfo.policy_data) {
/* If we have policy data, assert that we have the means to free it */
tor_assert(cmux->policy);
tor_assert(cmux->policy_data);
tor_assert(cmux->policy->free_circ_data);
/* Call free_circ_data() */
cmux->policy->free_circ_data(cmux,
@ -997,16 +997,14 @@ circuitmux_make_circuit_active(circuitmux_t *cmux, circuit_t *circ,
/* Policy-specific notification */
if (cmux->policy &&
cmux->policy->notify_circ_active &&
cmux->policy_data) {
cmux->policy->notify_circ_active) {
/* Okay, we need to check the circuit for policy data now */
hashent = circuitmux_find_map_entry(cmux, circ);
/* We should have found something */
tor_assert(hashent);
/* Check for policy data for the circuit and notify */
if (hashent->muxinfo.policy_data)
cmux->policy->notify_circ_active(cmux, cmux->policy_data,
circ, hashent->muxinfo.policy_data);
/* Notify */
cmux->policy->notify_circ_active(cmux, cmux->policy_data,
circ, hashent->muxinfo.policy_data);
}
}
@ -1106,16 +1104,14 @@ circuitmux_make_circuit_inactive(circuitmux_t *cmux, circuit_t *circ,
/* Policy-specific notification */
if (cmux->policy &&
cmux->policy->notify_circ_inactive &&
cmux->policy_data) {
cmux->policy->notify_circ_inactive) {
/* Okay, we need to check the circuit for policy data now */
hashent = circuitmux_find_map_entry(cmux, circ);
/* We should have found something */
tor_assert(hashent);
/* Check for policy data for the circuit and notify */
if (hashent->muxinfo.policy_data)
cmux->policy->notify_circ_inactive(cmux, cmux->policy_data,
circ, hashent->muxinfo.policy_data);
/* Notify */
cmux->policy->notify_circ_inactive(cmux, cmux->policy_data,
circ, hashent->muxinfo.policy_data);
}
}
@ -1153,11 +1149,8 @@ circuitmux_set_num_cells(circuitmux_t *cmux, circuit_t *circ,
cmux->n_cells += n_cells;
/* Do we need to notify a cmux policy? */
if (cmux->policy && cmux->policy_data &&
cmux->policy->notify_set_n_cells) {
/* Yeah; assert that we have circuit policy data */
tor_assert(hashent->muxinfo.policy_data);
/* ... and call notify_set_n_cells */
if (cmux->policy && cmux->policy->notify_set_n_cells) {
/* Call notify_set_n_cells */
cmux->policy->notify_set_n_cells(cmux,
cmux->policy_data,
circ,