GNUnet 0.21.1
messenger_api_message_kind.c
Go to the documentation of this file.
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 */
27
29
32{
33 if (! key)
34 return NULL;
35
38
39 if (! message)
40 return NULL;
41
43 return message;
44}
45
46
49{
51}
52
53
56{
57 if (! name)
58 return NULL;
59
62
63 if (! message)
64 return NULL;
65
66 message->body.name.name = GNUNET_strdup (name);
67 return message;
68}
69
70
73{
74 if (! key)
75 return NULL;
76
79
80 if (! message)
81 return NULL;
82
84 return message;
85}
86
87
89create_message_id (const struct GNUNET_ShortHashCode *unique_id)
90{
91 if (! unique_id)
92 return NULL;
93
96
97 if (! message)
98 return NULL;
99
100 GNUNET_memcpy (&(message->body.id.id), unique_id, sizeof(struct
102 );
103
104 return message;
105}
106
107
110{
111 if (! hash)
112 return NULL;
113
114 struct GNUNET_HashCode zero;
115 memset (&zero, 0, sizeof(zero));
116
117 if (0 == GNUNET_CRYPTO_hash_cmp (hash, &zero))
118 return NULL;
119
120 struct GNUNET_MESSENGER_Message *message = create_message (
122
123 if (! message)
124 return NULL;
125
126 GNUNET_memcpy (&(message->body.request.hash), hash, sizeof(struct
128
129 return message;
130}
131
132
135 const struct GNUNET_HashCode *key)
136{
137 if ((! door) || (! key))
138 return NULL;
139
140 struct GNUNET_MESSENGER_Message *message = create_message (
142
143 if (! message)
144 return NULL;
145
146 GNUNET_memcpy (&(message->body.invite.door), door, sizeof(struct
148 );
149 GNUNET_memcpy (&(message->body.invite.key), key, sizeof(struct
151
152 return message;
153}
154
155
157create_message_text (const char *text)
158{
159 if (! text)
160 return NULL;
161
162 struct GNUNET_MESSENGER_Message *message = create_message (
164
165 if (! message)
166 return NULL;
167
168 message->body.text.text = GNUNET_strdup (text);
169 return message;
170}
171
172
175 const struct GNUNET_TIME_Relative delay)
176{
177 if (! hash)
178 return NULL;
179
180 struct GNUNET_MESSENGER_Message *message = create_message (
182
183 if (! message)
184 return NULL;
185
186 GNUNET_memcpy (&(message->body.deletion.hash), hash, sizeof(struct
188 message->body.deletion.delay = GNUNET_TIME_relative_hton (delay);
189
190 return message;
191}
192
193
196{
197 if (! ticket)
198 return NULL;
199
200 struct GNUNET_MESSENGER_Message *message = create_message (
202
203 if (! message)
204 return NULL;
205
207
208 return message;
209}
struct GNUNET_HashCode key
The key used in the DHT.
static char * name
Name (label) of the records to list.
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
static const struct GNUNET_CRYPTO_PrivateKey zero
Public key of all zeros.
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
Definition: crypto_hash.c:221
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public(const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: crypto_pkey.c:619
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
@ GNUNET_MESSENGER_KIND_INVITE
The invite kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_TEXT
The text kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_DELETE
The delete kind.
@ GNUNET_MESSENGER_KIND_TICKET
The ticket kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:618
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_MESSENGER_Message * create_message_name(const char *name)
Creates and allocates a new name message containing the name to change to.
struct GNUNET_MESSENGER_Message * create_message_delete(const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay)
Creates and allocates a new delete message containing the hash of a message to delete after a specifi...
struct GNUNET_MESSENGER_Message * create_message_ticket(const struct GNUNET_RECLAIM_Ticket *ticket)
Creates and allocates a new ticket message containing the identifier of a ticket to exchange it with ...
struct GNUNET_MESSENGER_Message * create_message_join(const struct GNUNET_CRYPTO_PrivateKey *key)
Creates and allocates a new join message containing the clients public key.
struct GNUNET_MESSENGER_Message * create_message_request(const struct GNUNET_HashCode *hash)
Creates and allocates a new request message containing the hash of a missing message.
struct GNUNET_MESSENGER_Message * create_message_text(const char *text)
Creates and allocates a new text message containing a string representing text.
struct GNUNET_MESSENGER_Message * create_message_leave()
Creates and allocates a new leave message.
struct GNUNET_MESSENGER_Message * create_message_key(const struct GNUNET_CRYPTO_PrivateKey *key)
Creates and allocates a new key message containing the public key to change to derived from its priva...
struct GNUNET_MESSENGER_Message * create_message_invite(const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Creates and allocates a new invite message containing the peer identity of an entrance peer to a room...
struct GNUNET_MESSENGER_Message * create_message_id(const struct GNUNET_ShortHashCode *unique_id)
Creates and allocates a new id message containing the unique member id to change to.
A private key for an identity as per LSD0001.
A 512-bit hashcode.
struct GNUNET_MESSENGER_MessageText text
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageKey key
struct GNUNET_MESSENGER_MessageInvite invite
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_MESSENGER_MessageDelete deletion
struct GNUNET_MESSENGER_MessageTicket ticket
struct GNUNET_HashCode hash
The hash of the message to delete.
struct GNUNET_TIME_RelativeNBO delay
The delay of the delete operation to get processed.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
struct GNUNET_HashCode key
The hash identifying the port of the room.
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
struct GNUNET_CRYPTO_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_CRYPTO_PublicKey key
The new public key which replaces the current senders public key.
char * name
The new name which replaces the current senders name.
struct GNUNET_HashCode hash
The hash of the requested message.
char * text
The containing text.
char * identifier
The identifier of a ticket.
struct GNUNET_MESSENGER_MessageBody body
Body.
The identity of the host (wraps the signing key of the peer).
The authorization ticket.
char gns_name[63 *2+2]
The ticket.
A 256-bit hashcode.
Time for relative time used by GNUnet, in microseconds.