diff options
Diffstat (limited to 'src/service/messenger/gnunet-service-messenger_message_kind.c')
-rw-r--r-- | src/service/messenger/gnunet-service-messenger_message_kind.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/service/messenger/gnunet-service-messenger_message_kind.c b/src/service/messenger/gnunet-service-messenger_message_kind.c new file mode 100644 index 000000000..0cc3afeaf --- /dev/null +++ b/src/service/messenger/gnunet-service-messenger_message_kind.c | |||
@@ -0,0 +1,109 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020--2023 GNUnet e.V. | ||
4 | |||
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 | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @author Tobias Frisch | ||
22 | * @file src/messenger/gnunet-service-messenger_message_kind.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "platform.h" | ||
27 | #include "gnunet-service-messenger_message_kind.h" | ||
28 | |||
29 | #include "messenger_api_util.h" | ||
30 | |||
31 | struct GNUNET_MESSENGER_Message* | ||
32 | create_message_info (struct GNUNET_MESSENGER_Service *service) | ||
33 | { | ||
34 | if (! service) | ||
35 | return NULL; | ||
36 | |||
37 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
38 | GNUNET_MESSENGER_KIND_INFO); | ||
39 | |||
40 | if (! message) | ||
41 | return NULL; | ||
42 | |||
43 | message->body.info.messenger_version = GNUNET_MESSENGER_VERSION; | ||
44 | |||
45 | return message; | ||
46 | } | ||
47 | |||
48 | |||
49 | struct GNUNET_MESSENGER_Message* | ||
50 | create_message_peer (struct GNUNET_MESSENGER_Service *service) | ||
51 | { | ||
52 | if (! service) | ||
53 | return NULL; | ||
54 | |||
55 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
56 | GNUNET_MESSENGER_KIND_PEER); | ||
57 | |||
58 | if (! message) | ||
59 | return NULL; | ||
60 | |||
61 | if (GNUNET_OK == get_service_peer_identity (service, | ||
62 | &(message->body.peer.peer))) | ||
63 | return message; | ||
64 | else | ||
65 | { | ||
66 | destroy_message (message); | ||
67 | return NULL; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | |||
72 | struct GNUNET_MESSENGER_Message* | ||
73 | create_message_miss (const struct GNUNET_PeerIdentity *peer) | ||
74 | { | ||
75 | if (! peer) | ||
76 | return NULL; | ||
77 | |||
78 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
79 | GNUNET_MESSENGER_KIND_MISS); | ||
80 | |||
81 | if (! message) | ||
82 | { | ||
83 | return NULL; | ||
84 | } | ||
85 | |||
86 | GNUNET_memcpy (&(message->body.miss.peer), peer, sizeof(struct | ||
87 | GNUNET_PeerIdentity)); | ||
88 | |||
89 | return message; | ||
90 | } | ||
91 | |||
92 | |||
93 | struct GNUNET_MESSENGER_Message* | ||
94 | create_message_merge (const struct GNUNET_HashCode *previous) | ||
95 | { | ||
96 | if (! previous) | ||
97 | return NULL; | ||
98 | |||
99 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
100 | GNUNET_MESSENGER_KIND_MERGE); | ||
101 | |||
102 | if (! message) | ||
103 | return NULL; | ||
104 | |||
105 | GNUNET_memcpy (&(message->body.merge.previous), previous, sizeof(struct | ||
106 | GNUNET_HashCode)); | ||
107 | |||
108 | return message; | ||
109 | } | ||