GNUnet  0.17.6
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 */
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;
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));
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));
150  &msg->peer,
152  client);
153 }
154 
155 
162 void
164 {
165  if (NULL != connection_requests)
168  client);
169 }
170 
171 
175 void
177 {
180  GNUNET_NO);
181 }
182 
183 
192 static int
193 free_request (void *cls,
194  const struct GNUNET_PeerIdentity *pid,
195  void *value)
196 {
197  struct ConnectionRequest *cr = value;
198 
200  pid,
201  cr);
202  return GNUNET_OK;
203 }
204 
205 
209 void
211 {
214  &free_request,
215  NULL);
218  connection_requests = NULL;
219 }
220 
221 
222 /* end of gnunet-service-ats_connectivity.c */
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
automatic transport selection messages
static char * value
Value of the record to add/remove.
ats service address management
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?
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).
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.
void GAS_connectivity_init()
Shutdown connectivity subsystem.
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_handle_request_address(struct GNUNET_SERVICE_Client *client, const struct RequestAddressMessage *msg)
Handle GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS messages from clients.
static struct GNUNET_CONTAINER_MultiPeerMap * connection_requests
Address suggestion requests by peer.
static int free_request(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Free the connection request from the map.
void GAS_connectivity_done()
Shutdown connectivity subsystem.
ats service, interaction with 'connecivity' API
void GAS_plugin_solver_unlock()
Resume instant solving, we are done with the bulk state updates.
void GAS_plugin_solver_lock()
Stop instant solving, there are many state updates happening in bulk right now.
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.
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.
ats service plugin management
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
enum GNUNET_GenericReturnValue 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).
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
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).
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.
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.
enum GNUNET_GenericReturnValue 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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_log(kind,...)
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_YES
@ GNUNET_NO
Definition: gnunet_common.h:98
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
Active connection requests.
struct GNUNET_SERVICE_Client * client
Client that made the request.
Internal representation of the hash map.
The identity of the host (wraps the signing key of the peer).
Handle to a client that is connected to a service.
Definition: service.c:251
Connectivity client to ATS service: we would like to have address suggestions for this peer.
Definition: ats.h:88
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.