GNUnet  0.19.5
gnunet-service-messenger_message_kind.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2020--2021 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  */
26 #include "platform.h"
28 
29 #include "messenger_api_util.h"
30 
33 {
34  if (!ego)
35  return NULL;
36 
38 
39  if (!message)
40  return NULL;
41 
42  GNUNET_memcpy(&(message->body.info.host_key), &(ego->pub), sizeof(ego->pub));
43 
45 
46  return message;
47 }
48 
51 {
52  if (!ego)
53  return NULL;
54 
56 
57  if (!message)
58  return NULL;
59 
60  GNUNET_memcpy(&(message->body.join.key), &(ego->pub), sizeof(ego->pub));
61 
62  return message;
63 }
64 
67 {
69 }
70 
73 {
74  if (!name)
75  return NULL;
76 
78 
79  if (!message)
80  return NULL;
81 
82  message->body.name.name = GNUNET_strdup(name);
83  return message;
84 }
85 
88 {
89  if (!key)
90  return NULL;
91 
93 
94  if (!message)
95  return NULL;
96 
98  return message;
99 }
100 
103 {
104  if (!service)
105  return NULL;
106 
108 
109  if (!message)
110  return NULL;
111 
113  return message;
114  else
115  {
116  destroy_message (message);
117  return NULL;
118  }
119 }
120 
122 create_message_id (const struct GNUNET_ShortHashCode *unique_id)
123 {
124  if (!unique_id)
125  return NULL;
126 
128 
129  if (!message)
130  return NULL;
131 
132  GNUNET_memcpy(&(message->body.id.id), unique_id, sizeof(struct GNUNET_ShortHashCode));
133 
134  return message;
135 }
136 
139 {
140  if (!peer)
141  return NULL;
142 
144 
145  if (!message)
146  {
147  return NULL;
148  }
149 
150  GNUNET_memcpy(&(message->body.miss.peer), peer, sizeof(struct GNUNET_PeerIdentity));
151 
152  return message;
153 }
154 
156 create_message_merge (const struct GNUNET_HashCode *previous)
157 {
158  if (!previous)
159  return NULL;
160 
162 
163  if (!message)
164  return NULL;
165 
166  GNUNET_memcpy(&(message->body.merge.previous), previous, sizeof(struct GNUNET_HashCode));
167 
168  return message;
169 }
170 
173 {
174  if (!hash)
175  return NULL;
176 
177  struct GNUNET_HashCode zero;
178  memset (&zero, 0, sizeof(zero));
179 
180  if (0 == GNUNET_CRYPTO_hash_cmp (hash, &zero))
181  return NULL;
182 
184 
185  if (!message)
186  return NULL;
187 
188  GNUNET_memcpy(&(message->body.request.hash), hash, sizeof(struct GNUNET_HashCode));
189 
190  return message;
191 }
192 
195  const struct GNUNET_HashCode *key)
196 {
197  if ((!door) || (!key))
198  return NULL;
199 
201 
202  if (!message)
203  return NULL;
204 
205  GNUNET_memcpy(&(message->body.invite.door), door, sizeof(struct GNUNET_PeerIdentity));
206  GNUNET_memcpy(&(message->body.invite.key), key, sizeof(struct GNUNET_HashCode));
207 
208  return message;
209 }
210 
212 create_message_text (const char *text)
213 {
214  if (!text)
215  return NULL;
216 
218 
219  if (!message)
220  return NULL;
221 
222  message->body.text.text = GNUNET_strdup(text);
223  return message;
224 }
225 
228  const struct GNUNET_TIME_Relative delay)
229 {
230  if (!hash)
231  return NULL;
232 
234 
235  if (!message)
236  return NULL;
237 
238  GNUNET_memcpy(&(message->body.deletion.hash), hash, sizeof(struct GNUNET_HashCode));
240 
241  return message;
242 }
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
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_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_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_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_name(const char *name)
Creates and allocates a new name message containing the name to change to.
struct GNUNET_MESSENGER_Message * create_message_key(const struct GNUNET_IDENTITY_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_merge(const struct GNUNET_HashCode *previous)
Creates and allocates a new merge message containing the hash of a second previous message besides th...
struct GNUNET_MESSENGER_Message * create_message_info(const struct GNUNET_MESSENGER_Ego *ego)
Creates and allocates a new info message containing the hosts EGO public key and a newly generated un...
struct GNUNET_MESSENGER_Message * create_message_miss(const struct GNUNET_PeerIdentity *peer)
Creates and allocates a new miss message containing the missing peer identity.
struct GNUNET_MESSENGER_Message * create_message_peer(const struct GNUNET_MESSENGER_Service *service)
Creates and allocates a new peer message containing a services peer identity.
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.
struct GNUNET_MESSENGER_Message * create_message_leave()
Creates and allocates a new leave message.
struct GNUNET_MESSENGER_Message * create_message_join(const struct GNUNET_MESSENGER_Ego *ego)
Creates and allocates a new join message containing the clients EGO public key.
int get_service_peer_identity(const struct GNUNET_MESSENGER_Service *service, struct GNUNET_PeerIdentity *peer)
Tries to write the peer identity of the peer running a service on to the peer parameter.
static const struct GNUNET_IDENTITY_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:220
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_key_get_public(const struct GNUNET_IDENTITY_PrivateKey *privkey, struct GNUNET_IDENTITY_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: identity_api.c:179
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_MESSENGER_VERSION
Version number of GNUnet Messenger API.
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ 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_PEER
The peer 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_MERGE
The merge 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
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
messenger api: client implementation of GNUnet MESSENGER service
const char * name
A 512-bit hashcode.
A private key for an identity as per LSD0001.
struct GNUNET_IDENTITY_PublicKey pub
struct GNUNET_MESSENGER_MessageText text
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageKey key
struct GNUNET_MESSENGER_MessageInvite invite
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_MESSENGER_MessagePeer peer
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_MESSENGER_MessageDelete deletion
struct GNUNET_MESSENGER_MessageInfo info
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.
uint32_t messenger_version
The version of GNUnet Messenger API.
struct GNUNET_IDENTITY_PublicKey host_key
The senders key to verify its signatures.
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_IDENTITY_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_IDENTITY_PublicKey key
The new public key which replaces the current senders public key.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
char * name
The new name which replaces the current senders name.
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
struct GNUNET_HashCode hash
The hash of the requested message.
char * text
The containing text.
struct GNUNET_MESSENGER_MessageBody body
Body.
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.