GNUnet  0.19.4
messenger_api_handle.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"
27 #include "messenger_api_handle.h"
28 
29 #include "messenger_api_util.h"
30 
34  void *identity_cls,
36  void *msg_cls)
37 {
39 
41 
42  handle->cfg = cfg;
43  handle->mq = NULL;
44 
45  handle->identity_callback = identity_callback;
46  handle->identity_cls = identity_cls;
47 
48  handle->msg_callback = msg_callback;
49  handle->msg_cls = msg_cls;
50 
51  handle->name = NULL;
52  handle->pubkey = NULL;
53 
54  handle->reconnect_time = GNUNET_TIME_relative_get_zero_ ();
55  handle->reconnect_task = NULL;
56 
58 
60 
61  return handle;
62 }
63 
64 static int
66  const struct GNUNET_HashCode *key,
67  void *value)
68 {
69  struct GNUNET_MESSENGER_Room *room = value;
70 
71  destroy_room (room);
72 
73  return GNUNET_YES;
74 }
75 
76 void
78 {
80 
83 
84  if (handle->mq)
86 
87  if (handle->name)
88  GNUNET_free(handle->name);
89 
90  if (handle->pubkey)
91  GNUNET_free(handle->pubkey);
92 
93  if (handle->rooms)
94  {
96 
98  }
99 
101 
103 }
104 
105 void
107  const char *name)
108 {
110 
111  if (handle->name)
112  GNUNET_free(handle->name);
113 
114  handle->name = name ? GNUNET_strdup(name) : NULL;
115 }
116 
117 const char*
119 {
121 
122  return handle->name;
123 }
124 
125 void
127  const struct GNUNET_IDENTITY_PublicKey *pubkey)
128 {
130 
131  if (!handle->pubkey)
132  handle->pubkey = GNUNET_new(struct GNUNET_IDENTITY_PublicKey);
133 
134  GNUNET_memcpy(handle->pubkey, pubkey, sizeof(*pubkey));
135 }
136 
137 const struct GNUNET_IDENTITY_PublicKey*
139 {
141 
142  if (handle->pubkey)
143  return handle->pubkey;
144 
145  return get_anonymous_public_key ();
146 }
147 
150 {
152 
153  return &(handle->contact_store);
154 }
155 
158  const struct GNUNET_HashCode *key)
159 {
160  GNUNET_assert((handle) && (key));
161 
163 
164  if ((!room) || (!(room->contact_id)))
165  return NULL;
166 
167  struct GNUNET_HashCode context;
169 
171 }
172 
173 void
175  const struct GNUNET_HashCode *key)
176 {
177  GNUNET_assert((handle) && (key));
178 
180 
181  if (room)
182  room->opened = GNUNET_YES;
183 }
184 
185 void
187  const struct GNUNET_PeerIdentity *door,
188  const struct GNUNET_HashCode *key)
189 {
190  GNUNET_assert((handle) && (door) && (key));
191 
193 
194  if (room)
195  add_to_list_tunnels (&(room->entries), door);
196 }
197 
198 void
200  const struct GNUNET_HashCode *key)
201 {
202  GNUNET_assert((handle) && (key));
203 
205 
206  if ((room) && (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (handle->rooms, key, room)))
207  destroy_room (room);
208 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static pa_context * context
Pulseaudio context.
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
static char * value
Value of the record to add/remove.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void(* GNUNET_MESSENGER_IdentityCallback)(void *cls, struct GNUNET_MESSENGER_Handle *handle)
Method called whenever the EGO of a handle changes or if the first connection fails to load a valid E...
void(* GNUNET_MESSENGER_MessageCallback)(void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_MessageFlags flags)
Method called whenever a message is sent or received from a room.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition: time.c:133
void get_context_from_member(const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *id, struct GNUNET_HashCode *context)
Calculates the context hash of a member in a room and returns it.
struct GNUNET_MESSENGER_Contact * get_store_contact(struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Returns a contact using a specific public key.
void clear_contact_store(struct GNUNET_MESSENGER_ContactStore *store)
Clears a contact store, wipes its content and deallocates its memory.
void init_contact_store(struct GNUNET_MESSENGER_ContactStore *store)
Initializes a contact store as fully empty.
void entry_handle_room_at(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Adds a tunnel for a room known to a handle identified by a given key to a list of opened connections.
const char * get_handle_name(const struct GNUNET_MESSENGER_Handle *handle)
Returns the current name of a given handle or NULL if no valid name was assigned yet.
static int iterate_destroy_room(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_MESSENGER_Handle * create_handle(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_IdentityCallback identity_callback, void *identity_cls, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls)
Creates and allocates a new handle using a given configuration and a custom message callback with a g...
void open_handle_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Marks a room known to a handle identified by a given key as open.
void destroy_handle(struct GNUNET_MESSENGER_Handle *handle)
Destroys a handle and frees its memory fully from the client API.
struct GNUNET_MESSENGER_Contact * get_handle_contact(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Returns the contact of a given handle in a room identified by a given key.
struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store(struct GNUNET_MESSENGER_Handle *handle)
Returns the used contact store of a given handle.
void close_handle_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Destroys and so implicitly closes a room known to a handle identified by a given key.
void set_handle_name(struct GNUNET_MESSENGER_Handle *handle, const char *name)
Sets the name of a handle to a specific name.
void set_handle_key(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Sets the public key of a given handle to a specific public key.
const struct GNUNET_IDENTITY_PublicKey * get_handle_key(const struct GNUNET_MESSENGER_Handle *handle)
Returns the public key of a given handle.
messenger api: client implementation of GNUnet MESSENGER service
void add_to_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels, const struct GNUNET_PeerIdentity *peer)
Adds a specific peer from a tunnel to the end of the list.
void destroy_room(struct GNUNET_MESSENGER_Room *room)
Destroys a room and frees its memory fully from the client API.
const struct GNUNET_IDENTITY_PublicKey * get_anonymous_public_key()
Returns the public identity key of GNUNET_IDENTITY_ego_get_anonymous() without recalculating it every...
messenger api: client implementation of GNUnet MESSENGER service
const char * name
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect to the service.
Definition: dns_api.c:81
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: dns_api.c:66
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:61
A 512-bit hashcode.
An identity key as per LSD0001.
GNUNET_MESSENGER_MessageCallback msg_callback
GNUNET_MESSENGER_IdentityCallback identity_callback
struct GNUNET_MESSENGER_ListTunnels entries
struct GNUNET_ShortHashCode * contact_id
The identity of the host (wraps the signing key of the peer).