GNUnet  0.11.x
gnunet-service-ats_connectivity.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011-2015 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 
27 #include "platform.h"
28 #include "gnunet-service-ats.h"
32 #include "ats.h"
33 
34 
39 {
44 
45  /* TODO: allow client to express a 'strength' for this request */
46 };
47 
48 
53 
54 
63 unsigned int
65  const struct GNUNET_PeerIdentity *peer)
66 {
67  if (NULL == connection_requests)
68  return 0;
69  /* TODO: return sum of 'strength's of connectivity requests */
70  return GNUNET_CONTAINER_multipeermap_contains (connection_requests,
71  peer);
72 }
73 
74 
81 void
83  const struct RequestAddressMessage *msg)
84 {
85  struct ConnectionRequest *cr;
86 
88  "Received `%s' message\n",
89  "GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS");
90  /* FIXME: should not ignore "msg->strength" */
91  cr = GNUNET_new (struct ConnectionRequest);
92  cr->client = client;
93  (void) GNUNET_CONTAINER_multipeermap_put (connection_requests,
94  &msg->peer,
95  cr,
98 }
99 
100 
110 static int
112  const struct GNUNET_PeerIdentity *pid,
113  void *value)
114 {
115  struct GNUNET_SERVICE_Client *client = cls;
116  struct ConnectionRequest *cr = value;
117 
118  if (cr->client == client)
119  {
122  "Removed request pending for peer `%s\n",
123  GNUNET_i2s (pid));
125  GNUNET_CONTAINER_multipeermap_remove (connection_requests,
126  pid,
127  cr));
128  GNUNET_free (cr);
129  }
130  return GNUNET_OK;
131 }
132 
133 
141 void
143  const struct RequestAddressMessage *msg)
144 {
146  "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n",
147  GNUNET_i2s (&msg->peer));
148  GNUNET_break (0 == ntohl (msg->strength));
149  GNUNET_CONTAINER_multipeermap_get_multiple (connection_requests,
150  &msg->peer,
152  client);
153 }
154 
155 
162 void
164 {
165  GNUNET_CONTAINER_multipeermap_iterate (connection_requests,
167  client);
168 }
169 
170 
174 void
176 {
177  connection_requests
179  GNUNET_NO);
180 }
181 
182 
191 static int
192 free_request (void *cls,
193  const struct GNUNET_PeerIdentity *pid,
194  void *value)
195 {
196  struct ConnectionRequest *cr = value;
197 
199  pid,
200  cr);
201  return GNUNET_OK;
202 }
203 
204 
208 void
210 {
212  GNUNET_CONTAINER_multipeermap_iterate (connection_requests,
213  &free_request,
214  NULL);
216  GNUNET_CONTAINER_multipeermap_destroy (connection_requests);
217  connection_requests = NULL;
218 }
219 
220 
221 /* end of gnunet-service-ats_connectivity.c */
Connectivity client to ATS service: we would like to have address suggestions for this peer...
Definition: ats.h:87
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static int free_matching_requests(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Free the connection request from the map if the closure matches the client.
void GAS_plugin_solver_lock()
Stop instant solving, there are many state updates happening in bulk right now.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GAS_connectivity_remove_client(struct GNUNET_SERVICE_Client *client)
Unregister a client (which may have been a connectivity client, but this is not assured).
static struct GNUNET_CONTAINER_MultiPeerMap * connection_requests
Address suggestion requests by peer.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
ats service plugin management
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
uint32_t strength
How "strong" is our need for an address for this peer?
Definition: ats.h:99
void GAS_connectivity_init()
Shutdown connectivity subsystem.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
Handle to a client that is connected to a service.
Definition: service.c:250
void GAS_plugin_solver_unlock()
Resume instant solving, we are done with the bulk state updates.
Active connection requests.
static char * value
Value of the record to add/remove.
Internal representation of the hash map.
unsigned int GAS_connectivity_has_peer(void *cls, const struct GNUNET_PeerIdentity *peer)
Is the given peer in the list of peers for which we have an address request?
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
void GAS_plugin_request_connect_start(const struct GNUNET_PeerIdentity *pid)
Notify the plugin that a request to connect to a particular peer was given to us. ...
ats service, interaction with &#39;connecivity&#39; API
ats service address management
void GAS_connectivity_done()
Shutdown connectivity subsystem.
Allow multiple values with the same key.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void GAS_handle_request_address(struct GNUNET_SERVICE_Client *client, const struct RequestAddressMessage *msg)
Handle GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS messages from clients.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
The identity of the host (wraps the signing key of the peer).
void GAS_handle_request_address_cancel(struct GNUNET_SERVICE_Client *client, const struct RequestAddressMessage *msg)
Handle GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL messages from clients.
#define GNUNET_log(kind,...)
struct GNUNET_SERVICE_Client * client
Client that made the request.
void GAS_plugin_request_connect_stop(const struct GNUNET_PeerIdentity *pid)
Notify the plugin that a request to connect to a particular peer was dropped.
#define GNUNET_YES
Definition: gnunet_common.h:77
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static int free_request(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Free the connection request from the map.
int GNUNET_CONTAINER_multipeermap_contains(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Check if the map contains any value under the given key (including values that are NULL)...
struct GNUNET_PeerIdentity peer
Peer to get address suggestions for.
Definition: ats.h:104
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
automatic transport selection messages
#define GNUNET_free(ptr)
Wrapper around free.