GNUnet  0.10.x
Data Structures | Functions | Variables
gnunet-service-ats_connectivity.c File Reference

ats service, interaction with 'connecivity' API More...

#include "platform.h"
#include "gnunet-service-ats.h"
#include "gnunet-service-ats_addresses.h"
#include "gnunet-service-ats_connectivity.h"
#include "gnunet-service-ats_plugins.h"
#include "ats.h"
Include dependency graph for gnunet-service-ats_connectivity.c:

Go to the source code of this file.

Data Structures

struct  ConnectionRequest
 Active connection requests. More...
 

Functions

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? More...
 
void GAS_handle_request_address (struct GNUNET_SERVICE_Client *client, const struct RequestAddressMessage *msg)
 Handle GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS messages from clients. More...
 
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. More...
 
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. More...
 
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). More...
 
void GAS_connectivity_init ()
 Shutdown connectivity subsystem. More...
 
static int free_request (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 Free the connection request from the map. More...
 
void GAS_connectivity_done ()
 Shutdown connectivity subsystem. More...
 

Variables

static struct GNUNET_CONTAINER_MultiPeerMapconnection_requests
 Address suggestion requests by peer. More...
 

Detailed Description

ats service, interaction with 'connecivity' API

Author
Matthias Wachs
Christian Grothoff

Definition in file gnunet-service-ats_connectivity.c.

Function Documentation

◆ GAS_connectivity_has_peer()

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?

Parameters
clsunused, NULL
peerpeer to query for
Returns
GNUNET_YES if so, GNUNET_NO if not

Definition at line 64 of file gnunet-service-ats_connectivity.c.

References GNUNET_CONTAINER_multipeermap_contains().

Referenced by GAS_plugin_init().

66 {
67  if (NULL == connection_requests)
68  return 0;
69  /* TODO: return sum of 'strength's of connectivity requests */
71  peer);
72 }
static struct GNUNET_CONTAINER_MultiPeerMap * connection_requests
Address suggestion requests by peer.
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)...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_handle_request_address()

void GAS_handle_request_address ( struct GNUNET_SERVICE_Client client,
const struct RequestAddressMessage msg 
)

Handle GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS messages from clients.

Handle 'request address' messages from clients.

Parameters
clientclient that sent the request
messagethe request message

Definition at line 82 of file gnunet-service-ats_connectivity.c.

References ConnectionRequest::client, GAS_plugin_request_connect_start(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, and RequestAddressMessage::peer.

Referenced by handle_request_address().

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 }
static struct GNUNET_CONTAINER_MultiPeerMap * connection_requests
Address suggestion requests by peer.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Active connection requests.
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. ...
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.
#define GNUNET_log(kind,...)
struct GNUNET_SERVICE_Client * client
Client that made the request.
struct GNUNET_PeerIdentity peer
Peer to get address suggestions for.
Definition: ats.h:105
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_matching_requests()

static int free_matching_requests ( void *  cls,
const struct GNUNET_PeerIdentity pid,
void *  value 
)
static

Free the connection request from the map if the closure matches the client.

Parameters
clsthe client to match
pidpeer for which the request was made
valuethe struct ConnectionRequest
Returns
GNUNET_OK (continue to iterate)

Definition at line 111 of file gnunet-service-ats_connectivity.c.

References ConnectionRequest::client, GAS_plugin_request_connect_stop(), GNUNET_assert, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_OK, GNUNET_YES, and value.

Referenced by free_request(), GAS_connectivity_remove_client(), and GAS_handle_request_address_cancel().

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 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Handle to a client that is connected to a service.
Definition: service.c:249
Active connection requests.
static char * value
Value of the record to add/remove.
#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:80
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_handle_request_address_cancel()

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.

Cancel 'request address' messages from clients.

Parameters
clientthe client that sent the request
msgthe request message

Definition at line 142 of file gnunet-service-ats_connectivity.c.

References free_matching_requests(), GNUNET_break, GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, RequestAddressMessage::peer, and RequestAddressMessage::strength.

Referenced by handle_request_address_cancel().

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 }
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.
static struct GNUNET_CONTAINER_MultiPeerMap * connection_requests
Address suggestion requests by peer.
uint32_t strength
How "strong" is our need for an address for this peer?
Definition: ats.h:100
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_log(kind,...)
struct GNUNET_PeerIdentity peer
Peer to get address suggestions for.
Definition: ats.h:105
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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_connectivity_remove_client()

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).

Parameters
clienthandle of the (now dead) client

Definition at line 163 of file gnunet-service-ats_connectivity.c.

References free_matching_requests(), and GNUNET_CONTAINER_multipeermap_iterate().

Referenced by client_disconnect_cb().

164 {
167  client);
168 }
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.
static struct GNUNET_CONTAINER_MultiPeerMap * connection_requests
Address suggestion requests by peer.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_connectivity_init()

void GAS_connectivity_init ( void  )

Shutdown connectivity subsystem.

Initialize connectivity subsystem.

Definition at line 175 of file gnunet-service-ats_connectivity.c.

References GNUNET_CONTAINER_multipeermap_create(), and GNUNET_NO.

Referenced by run().

176 {
179  GNUNET_NO);
180 }
static struct GNUNET_CONTAINER_MultiPeerMap * connection_requests
Address suggestion requests by peer.
#define GNUNET_NO
Definition: gnunet_common.h:81
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).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_request()

static int free_request ( void *  cls,
const struct GNUNET_PeerIdentity pid,
void *  value 
)
static

Free the connection request from the map.

Parameters
clsNULL
pidpeer for which the request was made
valuethe struct ConnectionRequest
Returns
GNUNET_OK (continue to iterate)

Definition at line 192 of file gnunet-service-ats_connectivity.c.

References ConnectionRequest::client, free_matching_requests(), GNUNET_OK, and value.

Referenced by GAS_connectivity_done().

195 {
196  struct ConnectionRequest *cr = value;
197 
199  pid,
200  cr);
201  return GNUNET_OK;
202 }
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.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Active connection requests.
static char * value
Value of the record to add/remove.
struct GNUNET_SERVICE_Client * client
Client that made the request.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_connectivity_done()

void GAS_connectivity_done ( void  )

Shutdown connectivity subsystem.

Definition at line 209 of file gnunet-service-ats_connectivity.c.

References free_request(), GAS_plugin_solver_lock(), GAS_plugin_solver_unlock(), GNUNET_CONTAINER_multipeermap_destroy(), and GNUNET_CONTAINER_multipeermap_iterate().

Referenced by cleanup_task(), and run().

210 {
213  &free_request,
214  NULL);
217  connection_requests = NULL;
218 }
void GAS_plugin_solver_lock()
Stop instant solving, there are many state updates happening in bulk right now.
static struct GNUNET_CONTAINER_MultiPeerMap * connection_requests
Address suggestion requests by peer.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
void GAS_plugin_solver_unlock()
Resume instant solving, we are done with the bulk state updates.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static int free_request(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Free the connection request from the map.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ connection_requests

struct GNUNET_CONTAINER_MultiPeerMap* connection_requests
static

Address suggestion requests by peer.

Definition at line 52 of file gnunet-service-ats_connectivity.c.