gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r17999 - in gnunet/src: ats include transport


From: gnunet
Subject: [GNUnet-SVN] r17999 - in gnunet/src: ats include transport
Date: Fri, 4 Nov 2011 14:59:35 +0100

Author: wachs
Date: 2011-11-04 14:59:35 +0100 (Fri, 04 Nov 2011)
New Revision: 17999

Modified:
   gnunet/src/ats/ats.h
   gnunet/src/ats/ats_api_scheduling.c
   gnunet/src/ats/gnunet-service-ats.c
   gnunet/src/ats/gnunet-service-ats_scheduling.c
   gnunet/src/ats/gnunet-service-ats_scheduling.h
   gnunet/src/include/gnunet_ats_service.h
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/transport/gnunet-service-transport_neighbours.c
Log:
extending ats api to inform about addresses in use


Modified: gnunet/src/ats/ats.h
===================================================================
--- gnunet/src/ats/ats.h        2011-11-04 13:58:18 UTC (rev 17998)
+++ gnunet/src/ats/ats.h        2011-11-04 13:59:35 UTC (rev 17999)
@@ -84,7 +84,28 @@
 
 };
 
+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
 {
   struct GNUNET_MessageHeader header;

Modified: gnunet/src/ats/ats_api_scheduling.c
===================================================================
--- gnunet/src/ats/ats_api_scheduling.c 2011-11-04 13:58:18 UTC (rev 17998)
+++ gnunet/src/ats/ats_api_scheduling.c 2011-11-04 13:59:35 UTC (rev 17999)
@@ -699,6 +699,63 @@
 
 
 /**
+ * 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.
  *
  * @param sh handle

Modified: gnunet/src/ats/gnunet-service-ats.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats.c 2011-11-04 13:58:18 UTC (rev 17998)
+++ gnunet/src/ats/gnunet-service-ats.c 2011-11-04 13:59:35 UTC (rev 17999)
@@ -137,7 +137,9 @@
       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)},

Modified: gnunet/src/ats/gnunet-service-ats_scheduling.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_scheduling.c      2011-11-04 13:58:18 UTC 
(rev 17998)
+++ gnunet/src/ats/gnunet-service-ats_scheduling.c      2011-11-04 13:59:35 UTC 
(rev 17999)
@@ -235,6 +235,69 @@
 
 
 /**
+ * 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.
  *
  * @param cls unused, NULL

Modified: gnunet/src/ats/gnunet-service-ats_scheduling.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_scheduling.h      2011-11-04 13:58:18 UTC 
(rev 17998)
+++ gnunet/src/ats/gnunet-service-ats_scheduling.h      2011-11-04 13:59:35 UTC 
(rev 17999)
@@ -101,6 +101,17 @@
 
 
 /**
+ * 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.
  *
  * @param cls unused, NULL

Modified: gnunet/src/include/gnunet_ats_service.h
===================================================================
--- gnunet/src/include/gnunet_ats_service.h     2011-11-04 13:58:18 UTC (rev 
17998)
+++ gnunet/src/include/gnunet_ats_service.h     2011-11-04 13:59:35 UTC (rev 
17999)
@@ -557,6 +557,27 @@
 
 
 /**
+ * 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.
  *
  * @param sh handle

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2011-11-04 13:58:18 UTC (rev 
17998)
+++ gnunet/src/include/gnunet_protocols.h       2011-11-04 13:59:35 UTC (rev 
17999)
@@ -954,6 +954,11 @@
  */
 #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
 
 
 
/*******************************************************************************

Modified: gnunet/src/transport/gnunet-service-transport_neighbours.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_neighbours.c  2011-11-04 
13:58:18 UTC (rev 17998)
+++ gnunet/src/transport/gnunet-service-transport_neighbours.c  2011-11-04 
13:59:35 UTC (rev 17999)
@@ -2025,6 +2025,14 @@
   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 @@
   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 @@
               "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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]