aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gnunet_chat_context.c31
-rw-r--r--src/gnunet_chat_context.h15
-rw-r--r--src/gnunet_chat_context_intern.c44
-rw-r--r--src/gnunet_chat_handle.h1
-rw-r--r--src/gnunet_chat_handle_intern.c12
5 files changed, 97 insertions, 6 deletions
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c
index 3505d42..5d502be 100644
--- a/src/gnunet_chat_context.c
+++ b/src/gnunet_chat_context.c
@@ -29,8 +29,10 @@
29#include "gnunet_chat_util.h" 29#include "gnunet_chat_util.h"
30 30
31#include "gnunet_chat_context_intern.c" 31#include "gnunet_chat_context_intern.c"
32#include <gnunet/gnunet_common.h>
32#include <gnunet/gnunet_messenger_service.h> 33#include <gnunet/gnunet_messenger_service.h>
33#include <gnunet/gnunet_namestore_service.h> 34#include <gnunet/gnunet_namestore_service.h>
35#include <gnunet/gnunet_scheduler_lib.h>
34 36
35static const unsigned int initial_map_size_of_room = 8; 37static const unsigned int initial_map_size_of_room = 8;
36static const unsigned int initial_map_size_of_contact = 4; 38static const unsigned int initial_map_size_of_contact = 4;
@@ -45,12 +47,16 @@ init_new_context (struct GNUNET_CHAT_Context *context,
45 context->topic = NULL; 47 context->topic = NULL;
46 context->deleted = GNUNET_NO; 48 context->deleted = GNUNET_NO;
47 49
50 context->request_task = NULL;
51
48 context->timestamps = GNUNET_CONTAINER_multishortmap_create( 52 context->timestamps = GNUNET_CONTAINER_multishortmap_create(
49 initial_map_size, GNUNET_NO); 53 initial_map_size, GNUNET_NO);
50 context->dependencies = GNUNET_CONTAINER_multihashmap_create( 54 context->dependencies = GNUNET_CONTAINER_multihashmap_create(
51 initial_map_size, GNUNET_NO); 55 initial_map_size, GNUNET_NO);
52 context->messages = GNUNET_CONTAINER_multihashmap_create( 56 context->messages = GNUNET_CONTAINER_multihashmap_create(
53 initial_map_size, GNUNET_NO); 57 initial_map_size, GNUNET_NO);
58 context->requests = GNUNET_CONTAINER_multihashmap_create(
59 initial_map_size, GNUNET_NO);
54 context->taggings = GNUNET_CONTAINER_multihashmap_create( 60 context->taggings = GNUNET_CONTAINER_multihashmap_create(
55 initial_map_size, GNUNET_NO); 61 initial_map_size, GNUNET_NO);
56 context->invites = GNUNET_CONTAINER_multihashmap_create( 62 context->invites = GNUNET_CONTAINER_multihashmap_create(
@@ -117,6 +123,9 @@ context_destroy (struct GNUNET_CHAT_Context *context)
117 (context->files) 123 (context->files)
118 ); 124 );
119 125
126 if (context->request_task)
127 GNUNET_SCHEDULER_cancel(context->request_task);
128
120 if (context->query) 129 if (context->query)
121 GNUNET_NAMESTORE_cancel(context->query); 130 GNUNET_NAMESTORE_cancel(context->query);
122 131
@@ -142,6 +151,7 @@ context_destroy (struct GNUNET_CHAT_Context *context)
142 GNUNET_CONTAINER_multishortmap_destroy(context->timestamps); 151 GNUNET_CONTAINER_multishortmap_destroy(context->timestamps);
143 GNUNET_CONTAINER_multihashmap_destroy(context->dependencies); 152 GNUNET_CONTAINER_multihashmap_destroy(context->dependencies);
144 GNUNET_CONTAINER_multihashmap_destroy(context->messages); 153 GNUNET_CONTAINER_multihashmap_destroy(context->messages);
154 GNUNET_CONTAINER_multihashmap_destroy(context->requests);
145 GNUNET_CONTAINER_multihashmap_destroy(context->taggings); 155 GNUNET_CONTAINER_multihashmap_destroy(context->taggings);
146 GNUNET_CONTAINER_multihashmap_destroy(context->invites); 156 GNUNET_CONTAINER_multihashmap_destroy(context->invites);
147 GNUNET_CONTAINER_multihashmap_destroy(context->files); 157 GNUNET_CONTAINER_multihashmap_destroy(context->files);
@@ -153,6 +163,26 @@ context_destroy (struct GNUNET_CHAT_Context *context)
153} 163}
154 164
155void 165void
166context_request_message (struct GNUNET_CHAT_Context* context,
167 const struct GNUNET_HashCode *hash)
168{
169 GNUNET_assert((context) && (hash));
170
171 if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put(context->requests,
172 hash, NULL, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE))
173 return;
174
175 if (context->request_task)
176 return;
177
178 context->request_task = GNUNET_SCHEDULER_add_with_priority(
179 GNUNET_SCHEDULER_PRIORITY_IDLE,
180 cb_context_request_messages,
181 context
182 );
183}
184
185void
156context_update_room (struct GNUNET_CHAT_Context *context, 186context_update_room (struct GNUNET_CHAT_Context *context,
157 struct GNUNET_MESSENGER_Room *room) 187 struct GNUNET_MESSENGER_Room *room)
158{ 188{
@@ -178,6 +208,7 @@ context_update_room (struct GNUNET_CHAT_Context *context,
178 initial_map_size_of_room, GNUNET_NO); 208 initial_map_size_of_room, GNUNET_NO);
179 209
180 GNUNET_CONTAINER_multihashmap_clear(context->messages); 210 GNUNET_CONTAINER_multihashmap_clear(context->messages);
211 GNUNET_CONTAINER_multihashmap_clear(context->requests);
181 GNUNET_CONTAINER_multihashmap_clear(context->invites); 212 GNUNET_CONTAINER_multihashmap_clear(context->invites);
182 GNUNET_CONTAINER_multihashmap_clear(context->files); 213 GNUNET_CONTAINER_multihashmap_clear(context->files);
183 214
diff --git a/src/gnunet_chat_context.h b/src/gnunet_chat_context.h
index 4dce842..33dd8a5 100644
--- a/src/gnunet_chat_context.h
+++ b/src/gnunet_chat_context.h
@@ -25,6 +25,7 @@
25#ifndef GNUNET_CHAT_CONTEXT_H_ 25#ifndef GNUNET_CHAT_CONTEXT_H_
26#define GNUNET_CHAT_CONTEXT_H_ 26#define GNUNET_CHAT_CONTEXT_H_
27 27
28#include <gnunet/gnunet_common.h>
28#include <gnunet/gnunet_gnsrecord_lib.h> 29#include <gnunet/gnunet_gnsrecord_lib.h>
29#include <gnunet/gnunet_messenger_service.h> 30#include <gnunet/gnunet_messenger_service.h>
30#include <gnunet/gnunet_util_lib.h> 31#include <gnunet/gnunet_util_lib.h>
@@ -43,9 +44,12 @@ struct GNUNET_CHAT_Context
43 char *topic; 44 char *topic;
44 int deleted; 45 int deleted;
45 46
47 struct GNUNET_SCHEDULER_Task *request_task;
48
46 struct GNUNET_CONTAINER_MultiShortmap *timestamps; 49 struct GNUNET_CONTAINER_MultiShortmap *timestamps;
47 struct GNUNET_CONTAINER_MultiHashMap *dependencies; 50 struct GNUNET_CONTAINER_MultiHashMap *dependencies;
48 struct GNUNET_CONTAINER_MultiHashMap *messages; 51 struct GNUNET_CONTAINER_MultiHashMap *messages;
52 struct GNUNET_CONTAINER_MultiHashMap *requests;
49 struct GNUNET_CONTAINER_MultiHashMap *taggings; 53 struct GNUNET_CONTAINER_MultiHashMap *taggings;
50 struct GNUNET_CONTAINER_MultiHashMap *invites; 54 struct GNUNET_CONTAINER_MultiHashMap *invites;
51 struct GNUNET_CONTAINER_MultiHashMap *files; 55 struct GNUNET_CONTAINER_MultiHashMap *files;
@@ -93,6 +97,17 @@ void
93context_destroy (struct GNUNET_CHAT_Context* context); 97context_destroy (struct GNUNET_CHAT_Context* context);
94 98
95/** 99/**
100 * Request a message from a chat <i>context</i> with a
101 * given <i>hash</i>.
102 *
103 * @param[in,out] context Chat context
104 * @param[in] hash Message hash
105 */
106void
107context_request_message (struct GNUNET_CHAT_Context* context,
108 const struct GNUNET_HashCode *hash);
109
110/**
96 * Updates the connected messenger <i>room</i> of a 111 * Updates the connected messenger <i>room</i> of a
97 * selected chat <i>context</i>. 112 * selected chat <i>context</i>.
98 * 113 *
diff --git a/src/gnunet_chat_context_intern.c b/src/gnunet_chat_context_intern.c
index 7d37c3b..b990c29 100644
--- a/src/gnunet_chat_context_intern.c
+++ b/src/gnunet_chat_context_intern.c
@@ -28,6 +28,7 @@
28 28
29#include <gnunet/gnunet_common.h> 29#include <gnunet/gnunet_common.h>
30#include <gnunet/gnunet_error_codes.h> 30#include <gnunet/gnunet_error_codes.h>
31#include <gnunet/gnunet_messenger_service.h>
31 32
32#define GNUNET_UNUSED __attribute__ ((unused)) 33#define GNUNET_UNUSED __attribute__ ((unused))
33 34
@@ -79,6 +80,49 @@ it_destroy_context_invites (GNUNET_UNUSED void *cls,
79 return GNUNET_YES; 80 return GNUNET_YES;
80} 81}
81 82
83enum GNUNET_GenericReturnValue
84it_iterate_context_requests (void *cls,
85 const struct GNUNET_HashCode *key,
86 GNUNET_UNUSED void *value)
87{
88 struct GNUNET_CHAT_Context *context = cls;
89
90 GNUNET_assert((context) && (context->room) && (key));
91
92 GNUNET_MESSENGER_get_message(context->room, key);
93
94 return GNUNET_YES;
95}
96
97void
98cb_context_request_messages (void *cls)
99{
100 struct GNUNET_CHAT_Context *context = cls;
101
102 GNUNET_assert(context);
103
104 context->request_task = NULL;
105
106 if (!(context->room))
107 {
108 context->request_task = GNUNET_SCHEDULER_add_with_priority(
109 GNUNET_SCHEDULER_PRIORITY_IDLE,
110 cb_context_request_messages,
111 context
112 );
113
114 return;
115 }
116
117 GNUNET_CONTAINER_multihashmap_iterate(
118 context->requests,
119 it_iterate_context_requests,
120 context
121 );
122
123 GNUNET_CONTAINER_multihashmap_clear(context->requests);
124}
125
82void 126void
83cont_context_write_records (void *cls, 127cont_context_write_records (void *cls,
84 enum GNUNET_ErrorCode ec) 128 enum GNUNET_ErrorCode ec)
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h
index a20c5be..677c153 100644
--- a/src/gnunet_chat_handle.h
+++ b/src/gnunet_chat_handle.h
@@ -25,6 +25,7 @@
25#ifndef GNUNET_CHAT_HANDLE_H_ 25#ifndef GNUNET_CHAT_HANDLE_H_
26#define GNUNET_CHAT_HANDLE_H_ 26#define GNUNET_CHAT_HANDLE_H_
27 27
28#include <gnunet/gnunet_common.h>
28#include <gnunet/gnunet_arm_service.h> 29#include <gnunet/gnunet_arm_service.h>
29#include <gnunet/gnunet_fs_service.h> 30#include <gnunet/gnunet_fs_service.h>
30#include <gnunet/gnunet_gns_service.h> 31#include <gnunet/gnunet_gns_service.h>
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c
index d1fd051..b0d6458 100644
--- a/src/gnunet_chat_handle_intern.c
+++ b/src/gnunet_chat_handle_intern.c
@@ -1017,20 +1017,20 @@ on_handle_message (void *cls,
1017 if ((handle->destruction) || 1017 if ((handle->destruction) ||
1018 (GNUNET_OK != handle_request_context_by_room(handle, room))) 1018 (GNUNET_OK != handle_request_context_by_room(handle, room)))
1019 return; 1019 return;
1020
1021 struct GNUNET_CHAT_Context *context = GNUNET_CONTAINER_multihashmap_get(
1022 handle->contexts, GNUNET_MESSENGER_room_get_key(room)
1023 );
1020 1024
1021 GNUNET_MESSENGER_get_message(room, &(msg->header.previous)); 1025 context_request_message(context, &(msg->header.previous));
1022 1026
1023 if (GNUNET_MESSENGER_KIND_MERGE == msg->header.kind) 1027 if (GNUNET_MESSENGER_KIND_MERGE == msg->header.kind)
1024 GNUNET_MESSENGER_get_message(room, &(msg->body.merge.previous)); 1028 context_request_message(context, &(msg->body.merge.previous));
1025 1029
1026 if ((GNUNET_CHAT_KIND_UNKNOWN == util_message_kind_from_kind(msg->header.kind)) || 1030 if ((GNUNET_CHAT_KIND_UNKNOWN == util_message_kind_from_kind(msg->header.kind)) ||
1027 (GNUNET_OK != intern_provide_contact_for_member(handle, sender, NULL))) 1031 (GNUNET_OK != intern_provide_contact_for_member(handle, sender, NULL)))
1028 return; 1032 return;
1029 1033
1030 struct GNUNET_CHAT_Context *context = GNUNET_CONTAINER_multihashmap_get(
1031 handle->contexts, GNUNET_MESSENGER_room_get_key(room)
1032 );
1033
1034 const struct GNUNET_TIME_Absolute timestamp = GNUNET_TIME_absolute_ntoh( 1034 const struct GNUNET_TIME_Absolute timestamp = GNUNET_TIME_absolute_ntoh(
1035 msg->header.timestamp 1035 msg->header.timestamp
1036 ); 1036 );