Exemple #1
0
void friend_history_clear(FRIEND *f)
{
    uint8_t path[512], *p;

    message_clear(&messages_friend, &f->msg);

    {
        /* We get the file path of the log file */
        p = path + datapath(path);

        if(countof(path) - (p - path) < TOX_PUBLIC_KEY_SIZE * 2 + sizeof(LOGFILE_EXT))
        {
            /* We ensure that we have enough space in the buffer,
               if not we fail */
            debug("error/history_clear: path too long\n");
            return;
        }

        cid_to_string(p, f->cid);
        p += TOX_PUBLIC_KEY_SIZE * 2;
        memcpy((char*)p, LOGFILE_EXT, sizeof(LOGFILE_EXT));
    }

    remove((const char *)path);
}
Exemple #2
0
static void cmdDelivered(void *base)
{
	node_t *node = (node_t *) base;
	msg_id_t msgid;
	message_t *msg;
	queue_t *q;
 	
 	assert(node);
	assert(node->sysdata);
	logger(node->sysdata->logging, 3, 
		"node:%d DELIVERED (flags:%x, mask:%x)",
		node->handle, node->data.flags, node->data.mask);

	// get the messageID
	assert(BIT_TEST(node->data.mask, DATA_MASK_ID));
	msgid = node->data.id;
	assert(msgid >= 0);

	logger(node->sysdata->logging, 2, "processDelivered.  Node:%d, msg_id:%d", node->handle, msgid);

	// find message in node->out_msg
	msg = node_findoutmsg(node, msgid);
	if (msg == NULL) {
		// didn't find the message that is being marked as delivered.
		assert(0);
	}
	else {

		if (BIT_TEST(msg->flags, FLAG_MSG_NOREPLY)) {
			// message is NOREPLY,

			logger(node->sysdata->logging, 2, "delivery(%d): Noreply.", msgid);
		
			// assert that message doesnt have source-node.
			assert(msg->source_node == NULL);
			
			// tell the queue that the node has finished processing a message.  This
			// will find the node, and remove it from the node_busy list.
			assert(msg->queue);
			assert(msg->target_node);
			queue_msg_done(msg->queue, msg->target_node);
						
			// then remove from the queue->msg_proc list
			assert(msg->queue);
			q = msg->queue;
			ll_remove(&q->msg_proc, msg);
			msg->queue = NULL;
			
			// set action to remove the message.
			assert(BIT_TEST(msg->flags, FLAG_MSG_ACTIVE));
			message_clear(msg);
			assert(node->sysdata->msg_used > 0);
			node->sysdata->msg_used --;
			assert(node->sysdata->msg_used >= 0);
			node->sysdata->msg_next = msg->id;

			// if there are more messages in the queue, then we need to deliver them.
			if (ll_count(&q->msg_pending) > 0) {
				logger(node->sysdata->logging, 2, "delivery(%d): setting delivery action.", msgid);
				queue_deliver(q);
			}
			else {
				logger(node->sysdata->logging, 2, "delivery(%d): no items to deliver.", msgid);
			}
		}
		else {
			// message is expecting a reply, so we need to tell the source that it was delivered.
			
			// mark the message as delivered.
			assert(BIT_TEST(msg->flags, FLAG_MSG_DELIVERED) == 0);
			BIT_SET(msg->flags, FLAG_MSG_DELIVERED);

			// send delivery message back to source.
			assert(msg->source_node);
			assert(msg->source_id >= 0);
			sendDelivered(msg->source_node, msg->source_id);

			// but we dont need to original payload anymore, so we can release that back into the bufpool.
			assert(msg->data);
			assert(node->sysdata);
			assert(node->sysdata->bufpool);
			expbuf_clear(msg->data);
			expbuf_pool_return(node->sysdata->bufpool, msg->data);
			msg->data = NULL;
		}
	}
}
Exemple #3
0
static void cmdReply(void *base)
{
	node_t *node = (node_t *) base;
	msg_id_t id;
	message_t *msg;
	stats_t *stats;
	queue_t *q;

 	assert(node);
	assert(node->handle >= 0);
	assert(node->sysdata);
	logger(node->sysdata->logging, 3, 
		"node:%d REPLY (flags:%x, mask:%x)", node->handle, node->data.flags, node->data.mask);

	// make sure that we have the minimum information that we need.
	if (BIT_TEST(node->data.mask, DATA_MASK_ID) && BIT_TEST(node->data.mask, DATA_MASK_PAYLOAD)) {

		id = node->data.id;
		assert(id >= 0);

		// find the message that the reply belongs to.
		assert(node->sysdata);
		assert(node->sysdata->msg_list);
		assert(id < node->sysdata->msg_max);
		msg = node->sysdata->msg_list[id];
		assert(msg);
		assert(msg->id == id);
		assert(BIT_TEST(msg->flags, FLAG_MSG_ACTIVE));
		assert(msg->target_node == node);

		// apply the payload which is part of the reply, replacing the payload which was the request.
		assert(node->sysdata);
		assert(node->sysdata->bufpool);
		assert(node->data.payload);
		assert(msg->data == NULL);
		msg->data = node->data.payload;
		node->data.payload = NULL;
		
		// send the payload to the source node of the message.
		assert(msg->source_node);
		sendReply(msg->source_node, msg);

		// tell the queue that the node has finished processing a message.  This
		// will find the node, and remove it from the node_busy list.
		assert(msg->queue);
		assert(msg->target_node);
		queue_msg_done(msg->queue, msg->target_node);

		// then remove from the queue->msg_proc list
		assert(msg->queue);
		q = msg->queue;
		ll_remove(&q->msg_proc, msg);
		msg->queue = NULL;

		assert(msg->data);
		assert(node->sysdata);
		assert(node->sysdata->bufpool);
		expbuf_clear(msg->data);
		expbuf_pool_return(node->sysdata->bufpool, msg->data);
		msg->data = NULL;


		// set action to remove the message.
		msg->source_node = NULL;
		msg->target_node = NULL;
		assert(BIT_TEST(msg->flags, FLAG_MSG_ACTIVE));
		message_clear(msg);
		assert(node->sysdata->msg_used > 0);
		node->sysdata->msg_used --;
		assert(node->sysdata->msg_used >= 0);
		node->sysdata->msg_next = msg->id;

		// if there are more messages in the queue, then we need to deliver them.
		if (ll_count(&q->msg_pending) > 0) {
			logger(node->sysdata->logging, 2, "delivery: setting delivery action.");
			queue_deliver(q);
		}
		else {
			logger(node->sysdata->logging, 2, "delivery: no items to deliver.");
		}


		stats = node->sysdata->stats;
		assert(stats);
		stats->replies ++;
	}
	else {
		// we should handle failure a bit better, and log the information.
		assert(0);
	}
	
}