[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r29674 - gnunet-mqtt/src/mqtt
From: |
gnunet |
Subject: |
[GNUnet-SVN] r29674 - gnunet-mqtt/src/mqtt |
Date: |
Sat, 28 Sep 2013 23:04:20 +0200 |
Author: grothoff
Date: 2013-09-28 23:04:20 +0200 (Sat, 28 Sep 2013)
New Revision: 29674
Modified:
gnunet-mqtt/src/mqtt/gnunet-service-mqtt.c
gnunet-mqtt/src/mqtt/mqtt_api.c
Log:
-some minor stylistic fixes
Modified: gnunet-mqtt/src/mqtt/gnunet-service-mqtt.c
===================================================================
--- gnunet-mqtt/src/mqtt/gnunet-service-mqtt.c 2013-09-28 20:55:20 UTC (rev
29673)
+++ gnunet-mqtt/src/mqtt/gnunet-service-mqtt.c 2013-09-28 21:04:20 UTC (rev
29674)
@@ -153,7 +153,7 @@
/**
* The subscriber's identity.
*/
- const struct GNUNET_PeerIdentity *id;
+ struct GNUNET_PeerIdentity id;
/**
* Tunnel connecting us to the subscriber.
@@ -188,21 +188,29 @@
};
-/*
+/**
* Struct representing one active subscription in our service.
*/
struct Subscription
{
- /* Handle used to cancel the annnouncement */
+ /**
+ * Handle used to cancel the annnouncement
+ */
struct GNUNET_REGEX_announce_handle *regex_announce_handle;
- /* The subscribed client */
+ /**
+ * The subscribed client
+ */
struct ClientInfo *client;
- /* Unique ID for this subscription */
+ /**
+ * Unique ID for this subscription
+ */
uint64_t request_id;
- /* The automaton built using the subcription provided by the user */
+ /**
+ * The automaton built using the subcription provided by the user
+ */
regex_t automaton;
};
@@ -293,7 +301,7 @@
* @param regex_topic client identification of the client
*
*/
-void
+static void
add_prefix (const char *topic, char **prefixed_topic)
{
int n, i;
@@ -323,7 +331,7 @@
* @param regex_topic client identification of the client
*
*/
-void
+static void
get_regex (char *topic, char **regex_topic)
{
char *plus;
@@ -433,7 +441,7 @@
pos = pos->next;
}
- ret = GNUNET_malloc (sizeof (struct ClientInfo));
+ ret = GNUNET_new (struct ClientInfo);
ret->client_handle = client;
ret->transmit_handle = NULL;
GNUNET_CONTAINER_DLL_insert (client_head, client_tail, ret);
@@ -490,7 +498,6 @@
}
GNUNET_MESH_tunnel_destroy (subscriber->tunnel);
- GNUNET_free ((void *) subscriber->id);
GNUNET_free (subscriber);
}
@@ -535,17 +542,64 @@
}
-static void
-process_pending_subscriber_messages (struct RemoteSubscriberInfo *subscriber);
+
+/**
+ * Function called when the timer expires for a delivered message,
+ * triggering its deletion.
+ *
+ * @param cls closure (RegexSearchContext of the message to be deleted)
+ */
static void
delete_delivered_message (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct RegexSearchContext *context = cls;
+ struct GNUNET_CONTAINER_SList_Iterator it;
+ it = GNUNET_CONTAINER_slist_begin (search_contexts);
+
+ while (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES)
+ {
+ if (GNUNET_CONTAINER_slist_get (&it, NULL) == context)
+ {
+ GNUNET_CONTAINER_slist_erase (&it);
+ break;
+ }
+ else
+ GNUNET_CONTAINER_slist_next (&it);
+ }
+
+ context->free_task = GNUNET_SCHEDULER_NO_TASK;
+ regex_search_context_free (context);
+}
+
+
+/**
+ * Marks a message as delivered and sets the timer for deleting it
+ *
+ * @param pm pointer to the pending message
+ */
static void
-set_timer_for_deleting_message (struct PendingMessage *pm);
+set_timer_for_deleting_message (struct PendingMessage *pm)
+{
+ if (GNUNET_NO == pm->context->message_delivered)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "scheduling task to delete delivered PUBLISH message\n");
+ pm->context->message_delivered = GNUNET_YES;
+ pm->context->free_task = GNUNET_SCHEDULER_add_delayed (
+ message_delete_time,
+ delete_delivered_message, pm->context);
+ }
+}
+
+static void
+process_pending_subscriber_messages (struct RemoteSubscriberInfo *subscriber);
+
+
/**
* Callback called as a result of issuing
* a GNUNET_MESH_notify_transmit_ready request. A RemoteSubscriberInfo
@@ -574,9 +628,10 @@
if (buf == NULL)
{
/* subscriber disconnected */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Subscriber %s disconnected, %s",
- GNUNET_i2s (subscriber->id),
- "pending messages will be discarded\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Subscriber %s disconnected, pending messages will be
discarded\n",
+ GNUNET_i2s (&subscriber->id));
+
return 0;
}
@@ -591,7 +646,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitting %u bytes to subscriber %s\n", msize,
- GNUNET_i2s (subscriber->id));
+ GNUNET_i2s (&subscriber->id));
off += msize;
set_timer_for_deleting_message(pm);
@@ -601,7 +656,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Transmitted %zu/%zu bytes to subscriber %s\n",
- off, size, GNUNET_i2s (subscriber->id));
+ off, size, GNUNET_i2s (&subscriber->id));
process_pending_subscriber_messages (subscriber);
return off;
@@ -624,7 +679,7 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Not asking for transmission to %s now: %s\n",
- GNUNET_i2s (subscriber->id),
+ GNUNET_i2s (&subscriber->id),
subscriber->pending_head ==
NULL ? "no more messages" : "request already pending");
return;
@@ -633,7 +688,7 @@
msg = subscriber->pending_head->msg;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"asking for transmission of %u bytes to client %s\n",
- ntohs (msg->size), GNUNET_i2s (subscriber->id));
+ ntohs (msg->size), GNUNET_i2s (&subscriber->id));
subscriber->transmit_handle =
GNUNET_MESH_notify_transmit_ready (subscriber->tunnel,
@@ -645,58 +700,6 @@
/**
- * Function called when the timer expires for a delivered message,
- * triggering its deletion.
- *
- * @param cls closure (RegexSearchContext of the message to be deleted)
- */
-static void
-delete_delivered_message (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct RegexSearchContext *context = cls;
- struct GNUNET_CONTAINER_SList_Iterator it;
-
- it = GNUNET_CONTAINER_slist_begin (search_contexts);
-
- while (GNUNET_CONTAINER_slist_end (&it) != GNUNET_YES)
- {
- if (GNUNET_CONTAINER_slist_get (&it, NULL) == context)
- {
- GNUNET_CONTAINER_slist_erase (&it);
- break;
- }
- else
- GNUNET_CONTAINER_slist_next (&it);
- }
-
- context->free_task = GNUNET_SCHEDULER_NO_TASK;
- regex_search_context_free (context);
-}
-
-
-/**
- * Marks a message as delivered and sets the timer for deleting it
- *
- * @param pm pointer to the pending message
- */
-static void
-set_timer_for_deleting_message (struct PendingMessage *pm)
-{
- if (GNUNET_NO == pm->context->message_delivered)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "scheduling task to delete delivered PUBLISH message\n");
-
- pm->context->message_delivered = GNUNET_YES;
- pm->context->free_task = GNUNET_SCHEDULER_add_delayed (
- message_delete_time,
- delete_delivered_message, pm->context);
- }
-}
-
-
-/**
* Add a PendingMessage to the subscriber's list of messages to be sent
*
* @param subscriber the subscriber to send the message to
@@ -767,7 +770,7 @@
msg = GNUNET_malloc (msg_len);
memcpy (msg, context->publish_msg, msg_len);
- pm = GNUNET_malloc (sizeof (struct PendingMessage));
+ pm = GNUNET_new (struct PendingMessage);
pm->msg = msg;
pm->context = context;
@@ -776,7 +779,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"creating a new tunnel to %s\n", GNUNET_i2s(id));
- subscriber = GNUNET_malloc (sizeof (struct RemoteSubscriberInfo));
+ subscriber = GNUNET_new (struct RemoteSubscriberInfo);
subscriber->tunnel = GNUNET_MESH_tunnel_create (mesh_handle,
NULL,
@@ -786,9 +789,7 @@
subscriber->peer_added = GNUNET_NO;
subscriber->peer_connecting = GNUNET_NO;
- subscriber->id = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
- memcpy ((struct GNUNET_PeerIdentity*) subscriber->id, id,
- sizeof (struct GNUNET_PeerIdentity));
+ subscriber->id = *id;
GNUNET_CONTAINER_multihashmap_put (remote_subscribers, &id->hashPubKey,
subscriber, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
@@ -815,7 +816,7 @@
{
struct RegexSearchContext *context;
- context = GNUNET_malloc (sizeof (struct RegexSearchContext));
+ context = GNUNET_new (struct RegexSearchContext);
context->publish_msg = publish_msg;
context->file_path = file_path;
context->message_delivered = GNUNET_NO;
@@ -830,6 +831,7 @@
context, sizeof (struct RegexSearchContext));
}
+
/**
* Handle MQTT-PUBLISH-message.
*
@@ -875,11 +877,7 @@
GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK,
&file_name_hash);
file_name = GNUNET_h2s_full(&file_name_hash);
- GNUNET_asprintf (&file_path, "%s%s%s", current_dir_name,
DIR_SEPARATOR_STR, file_name );
- //file_path = GNUNET_malloc (strlen(current_dir_name)+
strlen(file_name) + 2);
- //strcpy(file_path, current_dir_name);
- //strcat(file_path, DIR_SEPARATOR_STR);
- //strcat(file_path, file_name);
+ GNUNET_asprintf (&file_path, "%s%s%s", current_dir_name,
DIR_SEPARATOR_STR, file_name );
if (NULL != (persistence_file = fopen(file_path, "w+")))
{
@@ -935,7 +933,7 @@
subscribe_msg->topic_len);
topic[subscribe_msg->topic_len - 1] = '\0';
- subscription = GNUNET_malloc (sizeof (struct Subscription));
+ subscription = GNUNET_new (struct Subscription);
get_regex (topic, ®ex_topic);
@@ -1126,7 +1124,7 @@
client_info = find_active_client (client);
unsub_ack_msg =
- GNUNET_malloc (sizeof (struct GNUNET_MQTT_ClientUnsubscribeAckMessage));
+ GNUNET_new (struct GNUNET_MQTT_ClientUnsubscribeAckMessage);
unsub_ack_msg->header.size =
sizeof (struct GNUNET_MQTT_ClientUnsubscribeAckMessage);
@@ -1134,7 +1132,7 @@
htons (GNUNET_MESSAGE_TYPE_MQTT_CLIENT_UNSUBSCRIBE_ACK);
unsub_ack_msg->request_id = subscription->request_id;
- pm = GNUNET_malloc (sizeof (struct PendingMessage));
+ pm = GNUNET_new (struct PendingMessage);
pm->msg = (struct GNUNET_MessageHeader*) unsub_ack_msg;
add_pending_client_message (client_info, pm);
@@ -1193,7 +1191,7 @@
return_msg->request_id = subscription->request_id;
- pm = GNUNET_malloc (sizeof (struct PendingMessage));
+ pm = GNUNET_new (struct PendingMessage);
pm->msg = (struct GNUNET_MessageHeader*) return_msg;
pm->context = context;
@@ -1239,7 +1237,6 @@
}
-
static int
free_remote_subscriber_iterator (void *cls, const struct GNUNET_HashCode *key,
void *value)
@@ -1345,7 +1342,7 @@
}
-static void*
+static void *
new_incoming_tunnel_callback (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
const struct GNUNET_PeerIdentity *initiator,
uint32_t port)
@@ -1361,10 +1358,11 @@
{
}
+
/**
* Look for old messages and call try to deliver them again by calling regex
search
*
- */
+ */
static void
look_for_old_messages ()
{
@@ -1386,12 +1384,7 @@
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, "PATHS",
"SERVICEHOME", ¤t_dir))
{
GNUNET_asprintf (¤t_dir_name, "%s%s", current_dir, folder_name);
- //current_dir_name = GNUNET_malloc (strlen(current_dir)+
strlen(folder_name)+1);
- //strcpy(current_dir_name, current_dir);
- //strcat(current_dir_name, folder_name);
-
-
if ((dir = opendir (current_dir_name)) != NULL)
{
while ((ent = readdir (dir)) != NULL) {
@@ -1399,11 +1392,7 @@
if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name,
".."))
continue;
- GNUNET_asprintf (&file_path, "%s%s%s",
current_dir_name, DIR_SEPARATOR_STR, ent->d_name );
- //file_path = GNUNET_malloc (strlen(current_dir_name)+
strlen(ent->d_name) + 1);
- //strcpy(file_path, current_dir_name);
- //strcat(file_path, DIR_SEPARATOR_STR);
- //strcat(file_path, ent->d_name);
+ GNUNET_asprintf (&file_path, "%s%s%s",
current_dir_name, DIR_SEPARATOR_STR, ent->d_name);
file = fopen(file_path, "r");
if (file != NULL)
{
@@ -1462,6 +1451,7 @@
}
}
+
/**
* Process statistics requests.
*
Modified: gnunet-mqtt/src/mqtt/mqtt_api.c
===================================================================
--- gnunet-mqtt/src/mqtt/mqtt_api.c 2013-09-28 20:55:20 UTC (rev 29673)
+++ gnunet-mqtt/src/mqtt/mqtt_api.c 2013-09-28 21:04:20 UTC (rev 29674)
@@ -29,7 +29,6 @@
#include "gnunet_mqtt_service.h"
#include "gnunet_protocols_mqtt.h"
#include "mqtt.h"
-#include "regex_utils.h"
#define LOG(kind,...) GNUNET_log_from (kind, "mqtt-api",__VA_ARGS__)
@@ -270,7 +269,6 @@
_("Failed to connect to the MQTT service!\n"));
return GNUNET_NO;
}
-
return GNUNET_YES;
}
@@ -341,7 +339,7 @@
{
struct GNUNET_MQTT_Handle *handle;
- handle = GNUNET_malloc (sizeof (struct GNUNET_MQTT_Handle));
+ handle = GNUNET_new (struct GNUNET_MQTT_Handle);
handle->cfg = cfg;
handle->uid_gen = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
UINT64_MAX);
@@ -795,7 +793,7 @@
GNUNET_break (0);
return NULL;
}
- ph = GNUNET_malloc (sizeof (struct GNUNET_MQTT_PublishHandle));
+ ph = GNUNET_new (struct GNUNET_MQTT_PublishHandle);
ph->mqtt_handle = handle;
ph->cont = cont;
ph->cont_cls = cont_cls;
@@ -891,7 +889,7 @@
GNUNET_assert (NULL != cb);
tsize = sizeof (struct GNUNET_MQTT_ClientSubscribeMessage) + topic_len;
- sh = GNUNET_malloc (sizeof (struct GNUNET_MQTT_SubscribeHandle));
+ sh = GNUNET_new (struct GNUNET_MQTT_SubscribeHandle);
sh->mqtt_handle = handle;
sh->cont = cont;
sh->cont_cls = cont_cls;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r29674 - gnunet-mqtt/src/mqtt,
gnunet <=