extending ats api to inform about addresses in use
authorMatthias Wachs <wachs@net.in.tum.de>
Fri, 4 Nov 2011 13:59:35 +0000 (13:59 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Fri, 4 Nov 2011 13:59:35 +0000 (13:59 +0000)
src/ats/ats.h
src/ats/ats_api_scheduling.c
src/ats/gnunet-service-ats.c
src/ats/gnunet-service-ats_scheduling.c
src/ats/gnunet-service-ats_scheduling.h
src/include/gnunet_ats_service.h
src/include/gnunet_protocols.h
src/transport/gnunet-service-transport_neighbours.c

index a45714f53a74bd1ef700e17fe3d10dbd495fa837..3ae6fdb654af974a0e1b5e1ddfe7cc639d8c984c 100644 (file)
@@ -84,6 +84,27 @@ struct AddressUpdateMessage
 
 };
 
+struct AddressUseMessage
+{
+  struct GNUNET_MessageHeader header;
+
+  struct GNUNET_PeerIdentity peer;
+
+  uint16_t in_use GNUNET_PACKED;
+
+  uint16_t address_length GNUNET_PACKED;
+
+  uint16_t plugin_name_length GNUNET_PACKED;
+
+  uint32_t session_id GNUNET_PACKED;
+
+  /* followed by:
+     - char address[address_length]
+     - char plugin_name[plugin_name_length] (including '\0'-termination).
+  */
+
+};
+
 
 struct AddressDestroyedMessage
 {
index 0bd7c4f943dd40e34265187dbf70de106699d1fe..b342d96576aa2a7cdc785640435fe8830ef37c66 100644 (file)
@@ -698,6 +698,63 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
 }
 
 
+/**
+ * An address is now in use or not used any more.
+ *
+ * @param sh handle
+ * @param peer identity of the peer
+ * @param plugin_name name of the transport plugin
+ * @param plugin_addr address  (if available)
+ * @param plugin_addr_len number of bytes in plugin_addr
+ * @param session session handle
+ * @param in_use GNUNET_YES if this address is now used, GNUNET_NO
+ * if address is not used any more
+ */
+void
+GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
+                              const struct GNUNET_PeerIdentity *peer,
+                              const char *plugin_name,
+                              const void *plugin_addr,
+                              size_t plugin_addr_len,
+                              struct Session *session,
+                              int in_use)
+{
+  struct PendingMessage *p;
+  struct AddressUseMessage *m;
+  char *pm;
+  size_t namelen;
+  size_t msize;
+
+  namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1;
+  msize = sizeof (struct AddressUseMessage) + plugin_addr_len + namelen;
+  if ( (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
+       (plugin_addr_len  >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
+       (namelen  >= GNUNET_SERVER_MAX_MESSAGE_SIZE) )
+  {
+    GNUNET_break (0);
+    return;
+  }
+  p = GNUNET_malloc (sizeof (struct PendingMessage) +  msize);
+  p->size = msize;
+  p->is_init = GNUNET_NO;
+  m = (struct AddressUseMessage*) &p[1];
+  m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE);
+  m->header.size = htons (msize);
+  m->peer = *peer;
+  m->in_use = htons(in_use);
+  m->address_length = htons (plugin_addr_len);
+  m->plugin_name_length = htons (namelen);
+  m->session_id = htonl (get_session_id (sh, session, peer));
+  pm = (char *) &m[1];
+  memcpy (pm, plugin_addr, plugin_addr_len);
+  memcpy (&pm[plugin_addr_len], plugin_name, namelen);
+  GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head,
+                                    sh->pending_tail,
+                                    p);
+
+  do_transmit (sh);
+}
+
 /**
  * A session got destroyed, stop including it as a valid address.
  *
index e497a7aaf33a5ef026f71ff9b4fda1e437853094..563550ece8203601aa5aa3a881c83a5e56b01d13 100644 (file)
@@ -137,7 +137,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
       GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, sizeof (struct RequestAddressMessage)},
     { &GAS_handle_address_update, NULL, 
       GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 0},
-    { &GAS_handle_address_destroyed, NULL, 
+    { &GAS_handle_address_in_use, NULL,
+      GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE, 0},
+    { &GAS_handle_address_destroyed, NULL,
       GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 0},
     { &GAS_handle_reservation_request, NULL, 
       GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, sizeof (struct ReservationRequestMessage)},
index 3ed5eb1dd0f624a000f60a0671881b38b7571921..bb95182c854e75e767055a08495cdc086415e4bc 100644 (file)
@@ -234,6 +234,69 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
 }
 
 
+/**
+ * Handle 'address in use' messages from clients.
+ *
+ * @param cls unused, NULL
+ * @param client client that sent the request
+ * @param message the request message
+ */
+void
+GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
+                           const struct GNUNET_MessageHeader *message)
+{
+  const struct AddressUseMessage * m;
+  const char *address;
+  const char *plugin_name;
+  uint16_t address_length;
+  uint16_t plugin_name_length;
+
+  uint16_t size;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received `%s' message\n",
+              "ADDRESS_IN_USE");
+  size = ntohs (message->size);
+  if (size < sizeof (struct AddressUseMessage))
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+  m = (const struct AddressUseMessage*) message;
+
+  address_length = ntohs (m->address_length);
+  plugin_name_length = ntohs (m->plugin_name_length);
+
+  address = (const char*) &m[1];
+  if (plugin_name_length != 0)
+    plugin_name = &address[address_length];
+  else
+    plugin_name = "";
+
+  if ( (address_length +
+        plugin_name_length +
+        sizeof (struct AddressUseMessage) != ntohs (message->size))  ||
+       (plugin_name[plugin_name_length - 1] != '\0') )
+  {
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+
+
+/*
+  GAS_addresses_update (&m->peer,
+                        plugin_name,
+                        address,
+                        address_length,
+                        ntohl (m->session_id),
+                        atsi,
+                        ats_count);
+*/
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
 /**
  * Handle 'address destroyed' messages from clients.
  *
index 9e188fe8f330b97fb99a533eb30e11510191cb50..7eeaba8b3ea69a83a778921cfe02065c913a1e64 100644 (file)
@@ -100,6 +100,17 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
                           const struct GNUNET_MessageHeader *message);
 
 
+/**
+ * Handle 'address in use' messages from clients.
+ *
+ * @param cls unused, NULL
+ * @param client client that sent the request
+ * @param message the request message
+ */
+void
+GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
+                           const struct GNUNET_MessageHeader *message);
+
 /**
  * Handle 'address destroyed' messages from clients.
  *
index 3d1c5b2b2e9eae5c015d6c8bf88e46ef8a9ca4f0..ed5631a33f5bbd83741ace8e7ba03a4127293320 100644 (file)
@@ -556,6 +556,27 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
                            uint32_t ats_count);
 
 
+/**
+ * An address is now in use or not used any more.
+ *
+ * @param sh handle
+ * @param peer identity of the peer
+ * @param plugin_name name of the transport plugin
+ * @param plugin_addr address  (if available)
+ * @param plugin_addr_len number of bytes in plugin_addr
+ * @param session session handle
+ * @param in_use GNUNET_YES if this address is now used, GNUNET_NO
+ * if address is not used any more
+ */
+void
+GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
+                              const struct GNUNET_PeerIdentity *peer,
+                              const char *plugin_name,
+                              const void *plugin_addr,
+                              size_t plugin_addr_len,
+                              struct Session *session,
+                              int in_use);
+
 /**
  * A session got destroyed, stop including it as a valid address.
  *
index fd52939f525cb98a023085b6ddcd1d327c8d3349..160ae26f118fd5fac53f32322c2f3400b192d534 100644 (file)
@@ -954,6 +954,11 @@ extern "C"
  */
 #define GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE 349
 
+/**
+ * Type of the 'struct AddressUseMessage' sent by ATS to client
+ * to confirm that an address is used or not used anymore
+ */
+#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE 350
 
 
 /*******************************************************************************
index 155efbb2f7fdf7cf7822dab46ac519b945081947..d0d5b099c79f0ce141749d0eab4beff8c997f8dd 100644 (file)
@@ -2025,6 +2025,14 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
   if (!is_connected(n))
     change_state (n, S_CONNECTED);
 
+  GNUNET_ATS_address_in_use (GST_ats,
+                             peer,
+                             plugin_name,
+                             sender_address,
+                             sender_address_len,
+                             session,
+                             GNUNET_YES);
+
 #if DEBUG_TRANSPORT
   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
               "Setting inbound quota of %u for peer `%s' to \n",
@@ -2137,6 +2145,14 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
   was_connected = is_connected(n);
   change_state (n, S_CONNECTED);
 
+  GNUNET_ATS_address_in_use (GST_ats,
+                             peer,
+                             plugin_name,
+                             sender_address,
+                             sender_address_len,
+                             session,
+                             GNUNET_YES);
+
   GST_neighbours_set_incoming_quota(&n->id, n->bandwidth_in);
 
   if (n->keepalive_task == GNUNET_SCHEDULER_NO_TASK)
@@ -2166,13 +2182,11 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
               "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
               ntohl (n->bandwidth_out.value__), GNUNET_i2s (peer));
 #endif
-
   q_msg.header.size = htons (sizeof (struct QuotaSetMessage));
   q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
   q_msg.quota = n->bandwidth_out;
   q_msg.peer = (*peer);
   GST_clients_broadcast (&q_msg.header, GNUNET_NO);
-
 }
 
 struct BlackListCheckContext