Ejemplo n.º 1
0
void
ccndc_destroy_data(struct ccndc_data **data) {
    struct ccndc_data *self = *data;
    
    if (self != NULL) {
        ccn_charbuf_destroy(&self->no_name);
        ccn_charbuf_destroy(&self->local_scope_template);
        ccn_disconnect(self->ccn_handle);
        ccn_destroy(&self->ccn_handle);
        free(self);
        *data = NULL;
    }
}
Ejemplo n.º 2
0
int GroupManager::ccn_free() {

    if (ccn != NULL) {
        ccn_disconnect(ccn);
        ccn_destroy(&ccn);
    }
    if (cached_keystore != NULL) ccn_keystore_destroy(&cached_keystore);
    if (join_closure != NULL) {
        free(join_closure);
        join_closure = NULL;
    }
    if (req_closure != NULL) {
        free(req_closure);
        req_closure = NULL;
    }
	if (leave_closure != NULL) {
		free(leave_closure);
		leave_closure = NULL;
	}
    return 0;
}
Ejemplo n.º 3
0
PUBLIC void
r_io_shutdown_client_fd(struct ccnr_handle *h, int fd)
{
    struct fdholder *fdholder = NULL;
    enum cq_delay_class c;
    int m;
    int res;
    
    fdholder = r_io_fdholder_from_fd(h, fd);
    if (fdholder == NULL) {
        ccnr_msg(h, "no fd holder for fd %d", fd);
        return;
    }
    if (fdholder == h->face0)
        (res = 0, h->face0 = NULL);
    else if ((fdholder->flags & CCNR_FACE_CCND))
        res = ccn_disconnect(h->direct_client);
    else
        res = close(fd);
    if (CCNSHOULDLOG(h, sdfdf, CCNL_INFO))
        ccnr_msg(h, "shutdown client fd=%d", fd);
    ccn_charbuf_destroy(&fdholder->inbuf);
    ccn_charbuf_destroy(&fdholder->outbuf);
    for (c = 0; c < CCN_CQ_N; c++)
        r_sendq_content_queue_destroy(h, &(fdholder->q[c]));
    for (m = 0; m < CCNR_FACE_METER_N; m++)
        ccnr_meter_destroy(&fdholder->meter[m]);
    if (h->fdholder_by_fd[fd] != fdholder) abort();
    h->fdholder_by_fd[fd] = NULL;
    ccn_charbuf_destroy(&fdholder->name);
    free(fdholder);
    if (h->active_in_fd == fd)
        h->active_in_fd = -1;
    if (h->active_out_fd == fd)
        h->active_out_fd = -1;
    if (h->repofile1_fd == fd)
        h->repofile1_fd = -1;
    // r_fwd_reap_needed(h, 250000);
}
Ejemplo n.º 4
0
/**
 * Destroys a ccn_fetch object.
 * Only destroys the underlying ccn connection if it was automatically created.
 * Forces all underlying streams to close immediately.
 * @returns NULL in all cases.
 */
extern struct ccn_fetch *
ccn_fetch_destroy(struct ccn_fetch *f) {
	// destroys a ccn_fetch object
	// always returns NULL
	// only destroys the underlying ccn connection if it was
	// automatically created, otherwise does not alter it
	if (f != NULL) {
		struct ccn *h = f->h;
		if (h != NULL && f->localConnect) {
			ccn_disconnect(h);
			ccn_destroy(&f->h);
		}
		// take down all of the streams
		while (f->nStreams > 0) {
			struct ccn_fetch_stream *fs = f->streams[0];
			if (fs == NULL) break;
			ccn_fetch_close(fs);
		}
		free(f);
	}
	return NULL;
}
Ejemplo n.º 5
0
static void
pyccn_Capsule_Destructor(PyObject *capsule)
{
	const char *name;
	void *pointer;
	enum _pyccn_capsules type;

	assert(PyCapsule_CheckExact(capsule));

	name = PyCapsule_GetName(capsule);
	type = name2type(name);

	pointer = PyCapsule_GetPointer(capsule, name);
	assert(pointer);

	switch (type) {
	case CLOSURE:
	{
		PyObject *py_obj_closure;
		struct ccn_closure *p = pointer;

		py_obj_closure = PyCapsule_GetContext(capsule);
		assert(py_obj_closure);
		Py_DECREF(py_obj_closure); /* No longer referencing Closure object */

		/* If we store something else, than ourselves, it probably is a bug */
		assert(capsule == p->data);

		free(p);
	}
		break;
	case CONTENT_OBJECT:
	{
		struct content_object_data *context;
		struct ccn_charbuf *p = pointer;

		context = PyCapsule_GetContext(capsule);
		if (context) {
			if (context->pco)
				free(context->pco);
			ccn_indexbuf_destroy(&context->comps);
			free(context);
		}
		ccn_charbuf_destroy(&p);
	}
		break;
	case HANDLE:
	{
		struct ccn *p = pointer;
		ccn_disconnect(p);
		ccn_destroy(&p);
	}
		break;
	case INTEREST:
	{
		struct interest_data *context;
		struct ccn_charbuf *p = pointer;

		context = PyCapsule_GetContext(capsule);
		if (context) {
			if (context->pi)
				free(context->pi);
			free(context);
		}
		ccn_charbuf_destroy(&p);
	}
		break;
	case PKEY_PRIV:
	case PKEY_PUB:
	{
		struct ccn_pkey *p = pointer;
		ccn_pubkey_free(p);
	}
		break;
	case EXCLUSION_FILTER:
	case KEY_LOCATOR:
	case NAME:
	case SIGNATURE:
	case SIGNED_INFO:
	{
		struct ccn_charbuf *p = pointer;
		ccn_charbuf_destroy(&p);
	}
		break;
	case SIGNING_PARAMS:
	{
		struct ccn_signing_params *p = pointer;

		if (p->template_ccnb)
			ccn_charbuf_destroy(&p->template_ccnb);

		free(p);
	}
		break;
	default:
		debug("Got capsule: %s\n", PyCapsule_GetName(capsule));
		panic("Unable to destroy the object: got an unknown capsule");
	}
}
Ejemplo n.º 6
0
/**
 * Create a new ccnr instance
 * @param progname - name of program binary, used for locating helpers
 * @param logger - logger function
 * @param loggerdata - data to pass to logger function
 */
PUBLIC struct ccnr_handle *
r_init_create(const char *progname, ccnr_logger logger, void *loggerdata)
{
    char *sockname = NULL;
    const char *portstr = NULL;
    const char *listen_on = NULL;
    const char *d = NULL;
    struct ccnr_handle *h = NULL;
    struct hashtb_param param = {0};
    struct ccn_charbuf *config = NULL;
    int res;
    
    h = calloc(1, sizeof(*h));
    if (h == NULL)
        return(h);
    h->notify_after = 0; //CCNR_MAX_ACCESSION;
    h->logger = logger;
    h->loggerdata = loggerdata;
    h->logpid = (int)getpid();
    h->progname = progname;
    h->debug = -1;
    config = r_init_read_config(h);
    if (config == NULL)
        goto Bail;
    r_init_parse_config(h, config, 0); /* silent pass to pick up CCNR_DEBUG */
    h->debug = 1; /* so that we see any complaints */
    h->debug = r_init_debug_getenv(h, "CCNR_DEBUG");
    res = r_init_parse_config(h, config, 1);
    if (res < 0) {
        h->running = -1;
        goto Bail;
    }
    r_init_parse_config(h, config, 2);
    sockname = r_net_get_local_sockname();
    h->skiplinks = ccn_indexbuf_create();
    h->face_limit = 10; /* soft limit */
    h->fdholder_by_fd = calloc(h->face_limit, sizeof(h->fdholder_by_fd[0]));
    param.finalize_data = h;
    param.finalize = &r_fwd_finalize_nameprefix;
    h->nameprefix_tab = hashtb_create(sizeof(struct nameprefix_entry), &param);
    param.finalize = 0; // PRUNED &r_fwd_finalize_propagating;
    h->propagating_tab = hashtb_create(sizeof(struct propagating_entry), &param);
    param.finalize = &r_proto_finalize_enum_state;
    h->enum_state_tab = hashtb_create(sizeof(struct enum_state), &param);
    h->min_stale = ~0;
    h->max_stale = 0;
    h->unsol = ccn_indexbuf_create();
    h->ticktock.descr[0] = 'C';
    h->ticktock.micros_per_base = 1000000;
    h->ticktock.gettime = &r_util_gettime;
    h->ticktock.data = h;
    h->sched = ccn_schedule_create(h, &h->ticktock);
    h->starttime = h->sec;
    h->starttime_usec = h->usec;
    h->oldformatcontentgrumble = 1;
    h->oldformatinterestgrumble = 1;
    h->cob_limit = 4201;
    h->start_write_scope_limit = r_init_confval(h, "CCNR_START_WRITE_SCOPE_LIMIT", 0, 3, 3);
    h->debug = 1; /* so that we see any complaints */
    h->debug = r_init_debug_getenv(h, "CCNR_DEBUG");
    h->syncdebug = r_init_debug_getenv(h, "CCNS_DEBUG");
    portstr = getenv("CCNR_STATUS_PORT");
    if (portstr == NULL || portstr[0] == 0 || strlen(portstr) > 10)
        portstr = "";
    h->portstr = portstr;
    ccnr_msg(h, "CCNR_DEBUG=%d CCNR_DIRECTORY=%s CCNR_STATUS_PORT=%s", h->debug, h->directory, h->portstr);
    listen_on = getenv("CCNR_LISTEN_ON");
    if (listen_on != NULL && listen_on[0] != 0)
        ccnr_msg(h, "CCNR_LISTEN_ON=%s", listen_on);
    
    if (ccnr_init_repo_keystore(h, NULL) < 0) {
        h->running = -1;
        goto Bail;
    }
    r_util_reseed(h);
    r_store_init(h);
    if (h->running == -1) goto Bail;
    while (h->active_in_fd >= 0) {
        r_dispatch_process_input(h, h->active_in_fd);
        r_store_trim(h, h->cob_limit);
        ccn_schedule_run(h->sched);
    }
    ccnr_msg(h, "Repository file is indexed");
    if (h->face0 == NULL) {
        struct fdholder *fdholder;
        fdholder = calloc(1, sizeof(*fdholder));
        if (dup2(open("/dev/null", O_RDONLY), 0) == -1)
            ccnr_msg(h, "stdin: %s", strerror(errno));
        fdholder->filedesc = 0;
        fdholder->flags = (CCNR_FACE_GG | CCNR_FACE_NORECV);
        r_io_enroll_face(h, fdholder);
    }
    ccnr_direct_client_start(h);
    d = getenv("CCNR_SKIP_VERIFY");
#if (CCN_API_VERSION >= 4004)
    if (d != NULL && strcmp(d, "1") == 0) {
        ccnr_msg(h, "CCNR_SKIP_VERIFY=%s", d);
        ccn_defer_verification(h->direct_client, 1);
    }
#endif
    if (ccn_connect(h->direct_client, NULL) != -1) {
        int af = 0;
        int bufsize;
        int flags;
        int fd;
        struct fdholder *fdholder;

        fd = ccn_get_connection_fd(h->direct_client);
        // Play a dirty trick here - if this wins, we can fix it right in the c lib later on...
        af = try_tcp_instead(fd);  
        flags = CCNR_FACE_CCND;
        if (af == AF_INET)
            flags |= CCNR_FACE_INET;
        else if (af == AF_INET6)
            flags |= CCNR_FACE_INET6;
        else
            flags |= CCNR_FACE_LOCAL;
        fdholder = r_io_record_fd(h, fd, "CCND", 5, flags);
        if (fdholder == NULL) abort();
        ccnr_uri_listen(h, h->direct_client, "ccnx:/%C1.M.S.localhost/%C1.M.SRV/repository",
                        &ccnr_answer_req, OP_SERVICE);
        ccnr_uri_listen(h, h->direct_client, "ccnx:/%C1.M.S.neighborhood/%C1.M.SRV/repository",
                        &ccnr_answer_req, OP_SERVICE);
        bufsize = r_init_confval(h, "CCNR_MIN_SEND_BUFSIZE", 1, 2097152, 16384);
        establish_min_send_bufsize(h, fd, bufsize);
    }
    else
        ccn_disconnect(h->direct_client); // Apparently ccn_connect error case needs work.
    if (1 == r_init_confval(h, "CCNS_ENABLE", 0, 1, 1)) {
        h->sync_plumbing = calloc(1, sizeof(struct sync_plumbing));
        h->sync_plumbing->ccn = h->direct_client;
        h->sync_plumbing->sched = h->sched;
        h->sync_plumbing->client_methods = &sync_client_methods;
        h->sync_plumbing->client_data = h;
        h->sync_base = SyncNewBaseForActions(h->sync_plumbing);
    }
    if (-1 == load_policy(h))
        goto Bail;
    r_net_listen_on(h, listen_on);
    ccnr_internal_client_start(h);
    r_proto_init(h);
    r_proto_activate_policy(h, h->parsed_policy);
    if (merge_files(h) == -1)
        r_init_fail(h, __LINE__, "Unable to merge additional repository data files.", errno);
    if (h->running == -1) goto Bail;
    if (h->sync_plumbing) {
        // Start sync running
        // returns < 0 if a failure occurred
        // returns 0 if the name updates should fully restart
        // returns > 0 if the name updates should restart at last fence
        res = h->sync_plumbing->sync_methods->sync_start(h->sync_plumbing, NULL);
        if (res < 0) {
            r_init_fail(h, __LINE__, "starting sync", res);
            abort();
        }
        else if (res > 0) {
            // XXX: need to work out details of starting from last fence.
            // By examination of code, SyncActions won't take this path
        }
    }
Bail:
    if (sockname)
        free(sockname);
    sockname = NULL;
    ccn_charbuf_destroy(&config);
    if (h->running == -1)
        r_init_destroy(&h);
    return(h);
}