diff options
author | Martin Willi <martin@revosec.ch> | 2010-03-03 15:51:32 +0100 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2010-03-03 15:52:20 +0100 |
commit | 24f058ac7420ede0de13a3d5a8a184d37e5f4a89 (patch) | |
tree | 778e742e6773262e567026290a92319e66642483 /src | |
parent | eb1aa4c5373378c5f6cf18bb07f76ee7a1dae386 (diff) | |
download | strongswan-24f058ac7420ede0de13a3d5a8a184d37e5f4a89.tar.bz2 strongswan-24f058ac7420ede0de13a3d5a8a184d37e5f4a89.tar.xz |
Migrated receiver_t to METHOD/INIT macros
Diffstat (limited to 'src')
-rw-r--r-- | src/charon/network/receiver.c | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/charon/network/receiver.c b/src/charon/network/receiver.c index 6cd99439b..39d1f447a 100644 --- a/src/charon/network/receiver.c +++ b/src/charon/network/receiver.c @@ -248,7 +248,7 @@ static bool peer_to_aggressive(private_receiver_t *this, message_t *message) } /** - * Implementation of receiver_t.receive_packets. + * Job callback to receive packets */ static job_requeue_t receive_packets(private_receiver_t *this) { @@ -329,10 +329,8 @@ static job_requeue_t receive_packets(private_receiver_t *this) return JOB_REQUEUE_DIRECT; } -/** - * Implementation of receiver_t.destroy. - */ -static void destroy(private_receiver_t *this) +METHOD(receiver_t, destroy, void, + private_receiver_t *this) { this->job->cancel(this->job); this->rng->destroy(this->rng); @@ -345,11 +343,22 @@ static void destroy(private_receiver_t *this) */ receiver_t *receiver_create() { - private_receiver_t *this = malloc_thing(private_receiver_t); + private_receiver_t *this; u_int32_t now = time_monotonic(NULL); - this->public.destroy = (void(*)(receiver_t*)) destroy; + INIT(this, + .public.destroy = _destroy, + .secret_switch = now, + .secret_offset = random() % now, + ); + if (lib->settings->get_bool(lib->settings, "charon.dos_protection", TRUE)) + { + this->cookie_threshold = lib->settings->get_int(lib->settings, + "charon.cookie_threshold", COOKIE_THRESHOLD_DEFAULT); + this->block_threshold = lib->settings->get_int(lib->settings, + "charon.block_threshold", BLOCK_THRESHOLD_DEFAULT); + } this->hasher = lib->crypto->create_hasher(lib->crypto, HASH_PREFERRED); if (this->hasher == NULL) { @@ -365,20 +374,8 @@ receiver_t *receiver_create() free(this); return NULL; } - this->secret_switch = now; - this->secret_offset = random() % now; - this->secret_used = 0; this->rng->get_bytes(this->rng, SECRET_LENGTH, this->secret); memcpy(this->secret_old, this->secret, SECRET_LENGTH); - this->cookie_threshold = lib->settings->get_int(lib->settings, - "charon.cookie_threshold", COOKIE_THRESHOLD_DEFAULT); - this->block_threshold = lib->settings->get_int(lib->settings, - "charon.block_threshold", BLOCK_THRESHOLD_DEFAULT); - if (!lib->settings->get_bool(lib->settings, "charon.dos_protection", TRUE)) - { - this->cookie_threshold = 0; - this->block_threshold = 0; - } this->job = callback_job_create((callback_job_cb_t)receive_packets, this, NULL, NULL); |