aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-01-10 17:56:36 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-01-10 17:56:36 +0100
commit57e859b9915959d6ba7601c35761eeb2e6ebe46d (patch)
tree1ded67c9715bf78970ccf3ac08bfd54c1c65240b
parent5d649fb886893d2ab393473188854add22114d0c (diff)
downloadlibgnunetchat-57e859b9915959d6ba7601c35761eeb2e6ebe46d.tar.gz
libgnunetchat-57e859b9915959d6ba7601c35761eeb2e6ebe46d.zip
Added sending a file message after publication completed
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/gnunet_chat_file.c51
-rw-r--r--src/gnunet_chat_file.h47
-rw-r--r--src/gnunet_chat_lib.c2
3 files changed, 67 insertions, 33 deletions
diff --git a/src/gnunet_chat_file.c b/src/gnunet_chat_file.c
index 13f5c2f..deb5e13 100644
--- a/src/gnunet_chat_file.c
+++ b/src/gnunet_chat_file.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -24,11 +24,13 @@
24 24
25#include "gnunet_chat_file.h" 25#include "gnunet_chat_file.h"
26 26
27#include "gnunet_chat_context.h"
28
27#include <limits.h> 29#include <limits.h>
28 30
29struct GNUNET_CHAT_File* 31struct GNUNET_CHAT_File*
30file_create_from_message (struct GNUNET_CHAT_Handle *handle, 32file_create_from_message (struct GNUNET_CHAT_Handle *handle,
31 const struct GNUNET_MESSENGER_MessageFile* message) 33 const struct GNUNET_MESSENGER_MessageFile *message)
32{ 34{
33 GNUNET_assert((handle) && 35 GNUNET_assert((handle) &&
34 (message) && 36 (message) &&
@@ -66,7 +68,8 @@ file_create_from_message (struct GNUNET_CHAT_Handle *handle,
66 68
67struct GNUNET_CHAT_File* 69struct GNUNET_CHAT_File*
68file_create_from_disk (struct GNUNET_CHAT_Handle *handle, 70file_create_from_disk (struct GNUNET_CHAT_Handle *handle,
69 const char *name, const struct GNUNET_HashCode *hash, 71 const char *name,
72 const struct GNUNET_HashCode *hash,
70 const struct GNUNET_CRYPTO_SymmetricSessionKey *key) 73 const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
71{ 74{
72 GNUNET_assert((handle) && 75 GNUNET_assert((handle) &&
@@ -105,7 +108,7 @@ file_create_from_disk (struct GNUNET_CHAT_Handle *handle,
105} 108}
106 109
107void 110void
108file_destroy (struct GNUNET_CHAT_File* file) 111file_destroy (struct GNUNET_CHAT_File *file)
109{ 112{
110 GNUNET_assert(file); 113 GNUNET_assert(file);
111 114
@@ -164,8 +167,10 @@ file_destroy (struct GNUNET_CHAT_File* file)
164} 167}
165 168
166void 169void
167file_bind_upload (struct GNUNET_CHAT_File* file, 170file_bind_upload (struct GNUNET_CHAT_File *file,
168 GNUNET_CHAT_FileUploadCallback cb, void *cls) 171 struct GNUNET_CHAT_Context *context,
172 GNUNET_CHAT_FileUploadCallback cb,
173 void *cls)
169{ 174{
170 GNUNET_assert(file); 175 GNUNET_assert(file);
171 176
@@ -173,6 +178,7 @@ file_bind_upload (struct GNUNET_CHAT_File* file,
173 struct GNUNET_CHAT_FileUpload 178 struct GNUNET_CHAT_FileUpload
174 ); 179 );
175 180
181 upload->context = context;
176 upload->callback = cb; 182 upload->callback = cb;
177 upload->cls = cls; 183 upload->cls = cls;
178 184
@@ -184,8 +190,9 @@ file_bind_upload (struct GNUNET_CHAT_File* file,
184} 190}
185 191
186void 192void
187file_bind_downlaod (struct GNUNET_CHAT_File* file, 193file_bind_downlaod (struct GNUNET_CHAT_File *file,
188 GNUNET_CHAT_FileDownloadCallback cb, void *cls) 194 GNUNET_CHAT_FileDownloadCallback cb,
195 void *cls)
189{ 196{
190 GNUNET_assert(file); 197 GNUNET_assert(file);
191 198
@@ -204,8 +211,9 @@ file_bind_downlaod (struct GNUNET_CHAT_File* file,
204} 211}
205 212
206void 213void
207file_bind_unindex (struct GNUNET_CHAT_File* file, 214file_bind_unindex (struct GNUNET_CHAT_File *file,
208 GNUNET_CHAT_FileUnindexCallback cb, void *cls) 215 GNUNET_CHAT_FileUnindexCallback cb,
216 void *cls)
209{ 217{
210 GNUNET_assert(file); 218 GNUNET_assert(file);
211 219
@@ -224,7 +232,8 @@ file_bind_unindex (struct GNUNET_CHAT_File* file,
224} 232}
225 233
226void 234void
227file_update_upload (struct GNUNET_CHAT_File* file, uint64_t completed, 235file_update_upload (struct GNUNET_CHAT_File *file,
236 uint64_t completed,
228 uint64_t size) 237 uint64_t size)
229{ 238{
230 GNUNET_assert(file); 239 GNUNET_assert(file);
@@ -242,10 +251,22 @@ file_update_upload (struct GNUNET_CHAT_File* file, uint64_t completed,
242 if (completed < size) 251 if (completed < size)
243 return; 252 return;
244 253
254 struct GNUNET_MESSENGER_Message message;
255 message.header.kind = GNUNET_MESSENGER_KIND_FILE;
256
257 memcpy(&(message.body.file.key), &(file->key), sizeof(file->key));
258 memcpy(&(message.body.file.hash), &(file->hash), sizeof(file->hash));
259
260 strncpy(message.body.file.name, file->name, NAME_MAX);
261
262 message.body.file.uri = GNUNET_FS_uri_to_string(file->uri);
263
245 while (file->upload_head) 264 while (file->upload_head)
246 { 265 {
247 upload = file->upload_head; 266 upload = file->upload_head;
248 267
268 GNUNET_MESSENGER_send_message(upload->context->room, &message, NULL);
269
249 GNUNET_CONTAINER_DLL_remove( 270 GNUNET_CONTAINER_DLL_remove(
250 file->upload_head, 271 file->upload_head,
251 file->upload_tail, 272 file->upload_tail,
@@ -254,10 +275,13 @@ file_update_upload (struct GNUNET_CHAT_File* file, uint64_t completed,
254 275
255 GNUNET_free(upload); 276 GNUNET_free(upload);
256 } 277 }
278
279 GNUNET_free(message.body.file.uri);
257} 280}
258 281
259void 282void
260file_update_download (struct GNUNET_CHAT_File* file, uint64_t completed, 283file_update_download (struct GNUNET_CHAT_File *file,
284 uint64_t completed,
261 uint64_t size) 285 uint64_t size)
262{ 286{
263 GNUNET_assert(file); 287 GNUNET_assert(file);
@@ -290,7 +314,8 @@ file_update_download (struct GNUNET_CHAT_File* file, uint64_t completed,
290} 314}
291 315
292void 316void
293file_update_unindex (struct GNUNET_CHAT_File* file, uint64_t completed, 317file_update_unindex (struct GNUNET_CHAT_File *file,
318 uint64_t completed,
294 uint64_t size) 319 uint64_t size)
295{ 320{
296 GNUNET_assert(file); 321 GNUNET_assert(file);
diff --git a/src/gnunet_chat_file.h b/src/gnunet_chat_file.h
index 3642896..d436f0b 100644
--- a/src/gnunet_chat_file.h
+++ b/src/gnunet_chat_file.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V. 3 Copyright (C) 2021--2022 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -36,9 +36,10 @@
36 36
37struct GNUNET_CHAT_FileUpload 37struct GNUNET_CHAT_FileUpload
38{ 38{
39 struct GNUNET_CHAT_FileUpload* prev; 39 struct GNUNET_CHAT_FileUpload *prev;
40 struct GNUNET_CHAT_FileUpload* next; 40 struct GNUNET_CHAT_FileUpload *next;
41 41
42 struct GNUNET_CHAT_Context *context;
42 GNUNET_CHAT_FileUploadCallback callback; 43 GNUNET_CHAT_FileUploadCallback callback;
43 44
44 void *cls; 45 void *cls;
@@ -46,8 +47,8 @@ struct GNUNET_CHAT_FileUpload
46 47
47struct GNUNET_CHAT_FileDownload 48struct GNUNET_CHAT_FileDownload
48{ 49{
49 struct GNUNET_CHAT_FileDownload* prev; 50 struct GNUNET_CHAT_FileDownload *prev;
50 struct GNUNET_CHAT_FileDownload* next; 51 struct GNUNET_CHAT_FileDownload *next;
51 52
52 GNUNET_CHAT_FileDownloadCallback callback; 53 GNUNET_CHAT_FileDownloadCallback callback;
53 54
@@ -56,8 +57,8 @@ struct GNUNET_CHAT_FileDownload
56 57
57struct GNUNET_CHAT_FileUnindex 58struct GNUNET_CHAT_FileUnindex
58{ 59{
59 struct GNUNET_CHAT_FileUnindex* prev; 60 struct GNUNET_CHAT_FileUnindex *prev;
60 struct GNUNET_CHAT_FileUnindex* next; 61 struct GNUNET_CHAT_FileUnindex *next;
61 62
62 GNUNET_CHAT_FileUnindexCallback callback; 63 GNUNET_CHAT_FileUnindexCallback callback;
63 64
@@ -96,38 +97,46 @@ struct GNUNET_CHAT_File
96 97
97struct GNUNET_CHAT_File* 98struct GNUNET_CHAT_File*
98file_create_from_message (struct GNUNET_CHAT_Handle *handle, 99file_create_from_message (struct GNUNET_CHAT_Handle *handle,
99 const struct GNUNET_MESSENGER_MessageFile* message); 100 const struct GNUNET_MESSENGER_MessageFile *message);
100 101
101struct GNUNET_CHAT_File* 102struct GNUNET_CHAT_File*
102file_create_from_disk (struct GNUNET_CHAT_Handle *handle, 103file_create_from_disk (struct GNUNET_CHAT_Handle *handle,
103 const char *name, const struct GNUNET_HashCode *hash, 104 const char *name,
105 const struct GNUNET_HashCode *hash,
104 const struct GNUNET_CRYPTO_SymmetricSessionKey *key); 106 const struct GNUNET_CRYPTO_SymmetricSessionKey *key);
105 107
106void 108void
107file_destroy (struct GNUNET_CHAT_File* file); 109file_destroy (struct GNUNET_CHAT_File *file);
108 110
109void 111void
110file_bind_upload (struct GNUNET_CHAT_File* file, 112file_bind_upload (struct GNUNET_CHAT_File *file,
111 GNUNET_CHAT_FileUploadCallback cb, void *cls); 113 struct GNUNET_CHAT_Context *context,
114 GNUNET_CHAT_FileUploadCallback cb,
115 void *cls);
112 116
113void 117void
114file_bind_downlaod (struct GNUNET_CHAT_File* file, 118file_bind_downlaod (struct GNUNET_CHAT_File *file,
115 GNUNET_CHAT_FileDownloadCallback cb, void *cls); 119 GNUNET_CHAT_FileDownloadCallback cb,
120 void *cls);
116 121
117void 122void
118file_bind_unindex (struct GNUNET_CHAT_File* file, 123file_bind_unindex (struct GNUNET_CHAT_File *file,
119 GNUNET_CHAT_FileUnindexCallback cb, void *cls); 124 GNUNET_CHAT_FileUnindexCallback cb,
125 void *cls);
120 126
121void 127void
122file_update_upload (struct GNUNET_CHAT_File* file, uint64_t completed, 128file_update_upload (struct GNUNET_CHAT_File *file,
129 uint64_t completed,
123 uint64_t size); 130 uint64_t size);
124 131
125void 132void
126file_update_download (struct GNUNET_CHAT_File* file, uint64_t completed, 133file_update_download (struct GNUNET_CHAT_File *file,
134 uint64_t completed,
127 uint64_t size); 135 uint64_t size);
128 136
129void 137void
130file_update_unindex (struct GNUNET_CHAT_File* file, uint64_t completed, 138file_update_unindex (struct GNUNET_CHAT_File *file,
139 uint64_t completed,
131 uint64_t size); 140 uint64_t size);
132 141
133#endif /* GNUNET_CHAT_FILE_H_ */ 142#endif /* GNUNET_CHAT_FILE_H_ */
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index f7a2075..05590a0 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -678,7 +678,7 @@ GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context,
678 } 678 }
679 679
680file_upload: 680file_upload:
681 file_bind_upload(file, callback, cls); 681 file_bind_upload(file, context, callback, cls);
682 682
683 struct GNUNET_FS_BlockOptions bo; 683 struct GNUNET_FS_BlockOptions bo;
684 684