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 | 129 |
1 files changed, 129 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..f1a79b321 --- /dev/null +++ b/src/service/messenger/gnunet-service-messenger_message_kind.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020--2024 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 "gnunet-service-messenger_message_kind.h" | ||
27 | |||
28 | #include "gnunet-service-messenger_room.h" | ||
29 | |||
30 | #include "messenger_api_message.h" | ||
31 | |||
32 | struct GNUNET_MESSENGER_Message* | ||
33 | create_message_info (struct GNUNET_MESSENGER_Service *service) | ||
34 | { | ||
35 | if (! service) | ||
36 | return NULL; | ||
37 | |||
38 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
39 | GNUNET_MESSENGER_KIND_INFO); | ||
40 | |||
41 | if (! message) | ||
42 | return NULL; | ||
43 | |||
44 | message->body.info.messenger_version = GNUNET_MESSENGER_VERSION; | ||
45 | |||
46 | return message; | ||
47 | } | ||
48 | |||
49 | |||
50 | struct GNUNET_MESSENGER_Message* | ||
51 | create_message_peer (struct GNUNET_MESSENGER_Service *service) | ||
52 | { | ||
53 | if (! service) | ||
54 | return NULL; | ||
55 | |||
56 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
57 | GNUNET_MESSENGER_KIND_PEER); | ||
58 | |||
59 | if (! message) | ||
60 | return NULL; | ||
61 | |||
62 | if (GNUNET_OK == get_service_peer_identity (service, | ||
63 | &(message->body.peer.peer))) | ||
64 | return message; | ||
65 | else | ||
66 | { | ||
67 | destroy_message (message); | ||
68 | return NULL; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | |||
73 | struct GNUNET_MESSENGER_Message* | ||
74 | create_message_miss (const struct GNUNET_PeerIdentity *peer) | ||
75 | { | ||
76 | if (! peer) | ||
77 | return NULL; | ||
78 | |||
79 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
80 | GNUNET_MESSENGER_KIND_MISS); | ||
81 | |||
82 | if (! message) | ||
83 | { | ||
84 | return NULL; | ||
85 | } | ||
86 | |||
87 | GNUNET_memcpy (&(message->body.miss.peer), peer, sizeof(struct | ||
88 | GNUNET_PeerIdentity)); | ||
89 | |||
90 | return message; | ||
91 | } | ||
92 | |||
93 | |||
94 | struct GNUNET_MESSENGER_Message* | ||
95 | create_message_merge (const struct GNUNET_HashCode *previous) | ||
96 | { | ||
97 | if (! previous) | ||
98 | return NULL; | ||
99 | |||
100 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
101 | GNUNET_MESSENGER_KIND_MERGE); | ||
102 | |||
103 | if (! message) | ||
104 | return NULL; | ||
105 | |||
106 | GNUNET_memcpy (&(message->body.merge.previous), previous, sizeof(struct | ||
107 | GNUNET_HashCode)); | ||
108 | |||
109 | return message; | ||
110 | } | ||
111 | |||
112 | |||
113 | struct GNUNET_MESSENGER_Message* | ||
114 | create_message_connection (const struct GNUNET_MESSENGER_SrvRoom *room) | ||
115 | { | ||
116 | if (! room) | ||
117 | return NULL; | ||
118 | |||
119 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
120 | GNUNET_MESSENGER_KIND_CONNECTION); | ||
121 | |||
122 | if (! message) | ||
123 | return NULL; | ||
124 | |||
125 | message->body.connection.amount = get_srv_room_amount_of_tunnels (room); | ||
126 | message->body.connection.flags = get_srv_room_connection_flags (room); | ||
127 | |||
128 | return message; | ||
129 | } | ||