예제 #1
0
void helper_start(mowgli_eventloop_helper_proc_t *helper, void *userdata)
{
	mowgli_eventloop_t *eventloop = helper->eventloop;

	mowgli_writef(helper->fd, "hi from pid %d\n", getpid());

	mowgli_timer_add(eventloop, "timer_tick", (mowgli_event_dispatch_func_t *) timer_tick, helper, 1);
	mowgli_timer_add_once(eventloop, "timer_oneshot", (mowgli_event_dispatch_func_t *) timer_oneshot, helper, 5);

	mowgli_eventloop_run(eventloop);

	mowgli_writef(helper->fd, "eventloop halted\n");

	mowgli_eventloop_destroy(eventloop);
}
예제 #2
0
int main(int argc, char *argv[])
{
	eventloop = mowgli_eventloop_create();

	mowgli_timer_add(eventloop, "timer_tick", timer_tick, NULL, 1);
	mowgli_timer_add_once(eventloop, "timer_oneshot", timer_oneshot, NULL, 5);

	mowgli_eventloop_run(eventloop);

	printf("eventloop halted\n");

	mowgli_eventloop_destroy(eventloop);

	return EXIT_SUCCESS;
}
예제 #3
0
static banrecord_t *
trigger_ban(trigger_t *t, packet_info_t *packet, iprecord_t *irec)
{
	banrecord_t *rec;
	prefix_t *pfx;
	patricia_node_t *node;
	struct in_addr sin;

	switch (t->type) {
	case TRIGGER_SRC:
		sin.s_addr = packet->pkt_src.s_addr;
		break;
	case TRIGGER_DST:
	default:
		sin.s_addr = packet->pkt_dst.s_addr;
		break;
	};

	if (ban_find(sin.s_addr) != NULL)
		return NULL;

	rec = calloc(sizeof(banrecord_t), 1);

	rec->trigger = t;
	memcpy(&rec->irec, irec, sizeof(iprecord_t));
	memcpy(&rec->pkt, packet, sizeof(packet_info_t));
	rec->added = mowgli_eventloop_get_time(eventloop);
	rec->expiry_ts = rec->added + (t->expiry ? t->expiry : expiry);

	pfx = New_Prefix(AF_INET, &sin, 32);

	node = patricia_lookup(banrecord_trie, pfx);
	node->data = rec;

	Deref_Prefix(pfx);

	run_triggers(ACTION_BAN, t, packet, rec);

	rec->timer = mowgli_timer_add_once(eventloop, "expire_dynamic_trigger", expire_dynamic_trigger, rec, (t->expiry ? t->expiry : expiry));

	return rec;
}