aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_context_intern.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet_chat_context_intern.c')
-rw-r--r--src/gnunet_chat_context_intern.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/gnunet_chat_context_intern.c b/src/gnunet_chat_context_intern.c
index c4a3d5b..f8c61e1 100644
--- a/src/gnunet_chat_context_intern.c
+++ b/src/gnunet_chat_context_intern.c
@@ -78,3 +78,100 @@ cont_context_write_records (void *cls,
78 emsg 78 emsg
79 ); 79 );
80} 80}
81
82void
83error_context_write_records (void *cls)
84{
85 struct GNUNET_CHAT_Context *context = cls;
86
87 handle_send_internal_message(
88 context->handle,
89 context,
90 GNUNET_CHAT_FLAG_WARNING,
91 _("Failed opening records!")
92 );
93}
94
95void
96monitor_context_write_records (void *cls,
97 const struct GNUNET_IDENTITY_PrivateKey *zone,
98 const char *label,
99 GNUNET_UNUSED unsigned int rd_count,
100 GNUNET_UNUSED const struct GNUNET_GNSRECORD_Data *rd)
101{
102 struct GNUNET_CHAT_Context *context = cls;
103
104 const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key(
105 context->room
106 );
107
108 struct GNUNET_MESSENGER_RoomEntryRecord room;
109 GNUNET_CRYPTO_get_peer_identity(context->handle->cfg, &(room.door));
110
111 GNUNET_memcpy(
112 &(room.key),
113 hash,
114 sizeof(room.key)
115 );
116
117 struct GNUNET_TIME_Absolute expiration = GNUNET_TIME_absolute_get_forever_();
118
119 const char *nick = context->nick;
120 const char *topic = context->topic;
121
122 if (topic)
123 {
124 struct GNUNET_HashCode topic_hash;
125 GNUNET_CRYPTO_hash(topic, strlen(topic), &topic_hash);
126
127 if (0 != GNUNET_CRYPTO_hash_cmp(&topic_hash, hash))
128 topic = NULL;
129 }
130
131 unsigned int count = 1;
132
133 struct GNUNET_GNSRECORD_Data data [3];
134 data[0].record_type = GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY;
135 data[0].data = &room;
136 data[0].data_size = sizeof(room);
137 data[0].expiration_time = expiration.abs_value_us;
138 data[0].flags = GNUNET_GNSRECORD_RF_PRIVATE;
139
140 if (nick)
141 {
142 data[count].record_type = GNUNET_GNSRECORD_TYPE_NICK;
143 data[count].data = nick;
144 data[count].data_size = strlen(nick);
145 data[count].expiration_time = expiration.abs_value_us;
146 data[count].flags = (
147 GNUNET_GNSRECORD_RF_PRIVATE |
148 GNUNET_GNSRECORD_RF_SUPPLEMENTAL
149 );
150
151 count++;
152 }
153
154 if (topic)
155 {
156 data[count].record_type = GNUNET_DNSPARSER_TYPE_TXT;
157 data[count].data = topic;
158 data[count].data_size = strlen(topic);
159 data[count].expiration_time = expiration.abs_value_us;
160 data[count].flags = (
161 GNUNET_GNSRECORD_RF_PRIVATE |
162 GNUNET_GNSRECORD_RF_SUPPLEMENTAL
163 );
164
165 count++;
166 }
167
168 GNUNET_NAMESTORE_records_commit(
169 context->handle->namestore,
170 zone,
171 label,
172 count,
173 data,
174 cont_context_write_records,
175 context
176 );
177}