gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r17265 - gnunet/src/core


From: gnunet
Subject: [GNUnet-SVN] r17265 - gnunet/src/core
Date: Thu, 6 Oct 2011 21:27:35 +0200

Author: grothoff
Date: 2011-10-06 21:27:35 +0200 (Thu, 06 Oct 2011)
New Revision: 17265

Added:
   gnunet/src/core/gnunet-service-core_typemap.h
Modified:
   gnunet/src/core/gnunet-service-core_sessions.c
   gnunet/src/core/gnunet-service-core_sessions.h
   gnunet/src/core/gnunet-service-core_typemap.c
Log:
drafting typemap API

Modified: gnunet/src/core/gnunet-service-core_sessions.c
===================================================================
--- gnunet/src/core/gnunet-service-core_sessions.c      2011-10-06 19:03:36 UTC 
(rev 17264)
+++ gnunet/src/core/gnunet-service-core_sessions.c      2011-10-06 19:27:35 UTC 
(rev 17265)
@@ -19,7 +19,7 @@
 */
 
 /**
- * @file core/gnunet-service-core_neighbours.c
+ * @file core/gnunet-service-core_sessions.c
  * @brief code for managing of 'encrypted' sessions (key exchange done) 
  * @author Christian Grothoff
  */
@@ -33,7 +33,7 @@
  * Record kept for each request for transmission issued by a
  * client that is still pending.
  */
-struct ClientActiveRequest;
+struct GSC_ClientActiveRequest;
 
 /**
  * Data kept per session.
@@ -49,13 +49,13 @@
    * Head of list of requests from clients for transmission to
    * this peer.
    */
-  struct ClientActiveRequest *active_client_request_head;
+  struct GSC_ClientActiveRequest *active_client_request_head;
 
   /**
    * Tail of list of requests from clients for transmission to
    * this peer.
    */
-  struct ClientActiveRequest *active_client_request_tail;
+  struct GSC_ClientActiveRequest *active_client_request_tail;
 
   /**
    * Performance data for the peer.
@@ -294,8 +294,8 @@
 static void
 schedule_peer_messages (struct Neighbour *n)
 {
-  struct ClientActiveRequest *car;
-  struct ClientActiveRequest *pos;
+  struct GSC_ClientActiveRequest *car;
+  struct GSC_ClientActiveRequest *pos;
   struct Client *c;
   struct MessageEntry *mqe;
   unsigned int queue_size;
@@ -354,7 +354,7 @@
 free_neighbour (struct Neighbour *n)
 {
   struct MessageEntry *m;
-  struct ClientActiveRequest *car;
+  struct GSC_ClientActiveRequest *car;
 
 #if DEBUG_CORE
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1360,8 +1360,53 @@
 
 
 
+/**
+ * Send a message to the neighbour.
+ *
+ * @param cls the message
+ * @param key neighbour's identity
+ * @param value 'struct Neighbour' of the target
+ * @return always GNUNET_OK
+ */
+static int
+do_send_message (void *cls, const GNUNET_HashCode * key, void *value)
+{
+  struct GNUNET_MessageHeader *hdr = cls;
+  struct Neighbour *n = value;
+  struct MessageEntry *m;
+  uint16_t size;
 
+  size = ntohs (hdr->size);
+  m = GNUNET_malloc (sizeof (struct MessageEntry) + size);
+  memcpy (&m[1], hdr, size);
+  m->deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
+  m->slack_deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
+  m->priority = UINT_MAX;
+  m->sender_status = n->status;
+  m->size = size;
+  GNUNET_CONTAINER_DLL_insert (n->message_head,
+                              n->message_tail,
+                              m);
+  return GNUNET_OK;
+}
+
+
 /**
+ * Broadcast a message to all neighbours.
+ *
+ * @param msg message to transmit
+ */
+void
+GSC_SESSIONS_broadcast (const struct GNUNET_MessageHeader *msg)
+{
+  if (NULL == sessions)
+    return;
+  GNUNET_CONTAINER_multihashmap_iterate (sessions,
+                                         &do_send_message, msg);
+}
+
+
+/**
  * Helper function for GSC_SESSIONS_handle_client_iterate_peers.
  *
  * @param cls the 'struct GNUNET_SERVER_TransmitContext' to queue replies
@@ -1413,10 +1458,61 @@
 }
 
 
+/**
+ * End the session with the given peer (we are no longer
+ * connected). 
+ *
+ * @param pid identity of peer to kill session with
+ */
+void
+GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
+{
+}
 
+
 /**
- * Handle CORE_ITERATE_PEERS request.
+ * Traffic is being solicited for the given peer.  This means that the
+ * message queue on the transport-level (NEIGHBOURS subsystem) is now
+ * empty and it is now OK to transmit another (non-control) message.
  *
+ * @param pid identity of peer ready to receive data
+ */
+void
+GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid)
+{
+}
+
+
+/**
+ * Transmit a message to a particular peer.
+ *
+ * @param car original request that was queued and then solicited,
+ *            ownership does not change (dequeue will be called soon).
+ * @param msg message to transmit
+ */
+void
+GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
+                      const struct GNUNET_MessageHeader *msg)
+{
+}
+
+
+/**
+ * We have a new client, notify it about all current sessions.
+ *
+ * @param client the new client
+ */
+void
+GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client)
+{
+}
+
+
+/**
+ * Handle CORE_ITERATE_PEERS request. For this request type, the client
+ * does not have to have transmitted an INIT request.  All current peers
+ * are returned, regardless of which message types they accept. 
+ *
  * @param cls unused
  * @param client client sending the iteration request
  * @param message iteration request message
@@ -1439,7 +1535,10 @@
 
 
 /**
- * Handle CORE_PEER_CONNECTED request.  Notify client about existing 
neighbours.
+ * Handle CORE_PEER_CONNECTED request.   Notify client about connection
+ * to the given neighbour.  For this request type, the client does not
+ * have to have transmitted an INIT request.  All current peers are
+ * returned, regardless of which message types they accept.
  *
  * @param cls unused
  * @param client client sending the iteration request
@@ -1466,7 +1565,8 @@
 
 
 /**
- * Handle REQUEST_INFO request.
+ * Handle REQUEST_INFO request. For this request type, the client must
+ * have transmitted an INIT first.
  *
  * @param cls unused
  * @param client client sending the request
@@ -1576,8 +1676,11 @@
 
 
 
+/**
+ * Initialize sessions subsystem.
+ */
 int
-GSC_NEIGHBOURS_init ()
+GSC_SESSIONS_init ()
 {
   neighbours = GNUNET_CONTAINER_multihashmap_create (128);
   self.public_key = &my_public_key;
@@ -1589,8 +1692,11 @@
 }
 
 
+/**
+ * Shutdown sessions subsystem.
+ */
 void
-GSC_NEIGHBOURS_done ()
+GSC_SESSIONS_done ()
 {
   GNUNET_CONTAINER_multihashmap_iterate (neighbours, &free_neighbour_helper,
                                          NULL);

Modified: gnunet/src/core/gnunet-service-core_sessions.h
===================================================================
--- gnunet/src/core/gnunet-service-core_sessions.h      2011-10-06 19:03:36 UTC 
(rev 17264)
+++ gnunet/src/core/gnunet-service-core_sessions.h      2011-10-06 19:27:35 UTC 
(rev 17265)
@@ -87,6 +87,15 @@
 
 
 /**
+ * Broadcast a message to all neighbours.
+ *
+ * @param msg message to transmit
+ */
+void
+GSC_SESSIONS_broadcast (const struct GNUNET_MessageHeader *msg);
+
+
+/**
  * We have a new client, notify it about all current sessions.
  *
  * @param client the new client
@@ -96,6 +105,48 @@
 
 
 /**
+ * Handle CORE_ITERATE_PEERS request.  For this request type, the client
+ * does not have to have transmitted an INIT request.  All current peers
+ * are returned, regardless of which message types they accept.
+ *
+ * @param cls unused
+ * @param client client sending the iteration request
+ * @param message iteration request message
+ */
+void
+GSC_SESSIONS_handle_client_iterate_peers (void *cls, struct 
GNUNET_SERVER_Client *client,
+                                         const struct GNUNET_MessageHeader 
*message);
+
+
+/**
+ * Handle CORE_PEER_CONNECTED request.  Notify client about connection
+ * to the given neighbour.  For this request type, the client does not
+ * have to have transmitted an INIT request.  All current peers are
+ * returned, regardless of which message types they accept.
+ *
+ * @param cls unused
+ * @param client client sending the iteration request
+ * @param message iteration request message
+ */
+void
+GSC_SESSIONS_handle_client_have_peer (void *cls, struct GNUNET_SERVER_Client 
*client,
+                                     const struct GNUNET_MessageHeader 
*message);
+
+
+/**
+ * Handle REQUEST_INFO request.  For this request type, the client must have
+ * transmitted an INIT first.
+ *
+ * @param cls unused
+ * @param client client sending the request
+ * @param message iteration request message
+ */
+void
+GSC_SESSIONS_handle_client_request_info (void *cls, struct 
GNUNET_SERVER_Client *client,
+                                        const struct GNUNET_MessageHeader 
*message);
+
+
+/**
  * Initialize sessions subsystem.
  */
 void

Modified: gnunet/src/core/gnunet-service-core_typemap.c
===================================================================
--- gnunet/src/core/gnunet-service-core_typemap.c       2011-10-06 19:03:36 UTC 
(rev 17264)
+++ gnunet/src/core/gnunet-service-core_typemap.c       2011-10-06 19:27:35 UTC 
(rev 17265)
@@ -1,5 +1,35 @@
+/*
+     This file is part of GNUnet.
+     (C) 2011 Christian Grothoff (and other contributing authors)
 
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
 /**
+ * @file core/gnunet-service-core_typemap.c
+ * @brief management of map that specifies which message types this peer 
supports
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_transport_service.h"
+#include "gnunet_service_core.h"
+
+
+/**
  * A type map describing which messages a given neighbour is able
  * to process.
  */
@@ -16,6 +46,58 @@
 
 
 /**
+ * Compute a type map message for this peer.
+ *
+ * @return this peers current type map message.
+ */
+static struct GNUNET_MessageHeader *
+compute_type_map_message ()
+{
+  char *tmp;
+  uLongf dlen;
+  struct GNUNET_MessageHeader *hdr;
+
+#ifdef compressBound
+  dlen = compressBound (sizeof (my_type_map));
+#else
+  dlen = sizeof (my_type_map) + (sizeof (my_type_map) / 100) + 20;
+  /* documentation says 100.1% oldSize + 12 bytes, but we
+   * should be able to overshoot by more to be safe */
+#endif
+  hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader));
+  hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader));
+  tmp = (char *) &hdr[1];
+  if ((Z_OK !=
+       compress2 ((Bytef *) tmp, &dlen, (const Bytef *) my_type_map,
+                  sizeof (my_type_map), 9)) || (dlen >= sizeof (my_type_map)))
+  {
+    dlen = sizeof (my_type_map);
+    memcpy (tmp, my_type_map, sizeof (my_type_map));
+    hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP);
+  }
+  else
+  {
+    hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP);
+  }
+  return hdr;
+}
+
+
+/**
+ * Send my type map to all connected peers (it got changed).
+ */
+static void
+broadcast_my_type_map ()
+{
+  struct GNUNET_MessageHeader *hdr;
+
+  hdr = compute_type_map_message ();
+  GSC_SESSIONS_broadcast (hdr);x
+  GNUNET_free (hdr);
+}
+
+
+/**
  * Add a set of types to our type map.
  */
 void
@@ -63,97 +145,20 @@
 GSC_TYPEMAP_test_match (struct GSC_TypeMap *tmap,
                        const uint16_t *types,
                        unsigned int tcnt)
-{
+{  
   return GNUNET_YES; /* FIXME */
 }
 
 
-/**
- * Compute a type map message for this peer.
- *
- * @return this peers current type map message.
- */
-static struct GNUNET_MessageHeader *
-compute_type_map_message ()
+void
+GSC_TYPEMAP_init ()
 {
-  char *tmp;
-  uLongf dlen;
-  struct GNUNET_MessageHeader *hdr;
-
-#ifdef compressBound
-  dlen = compressBound (sizeof (my_type_map));
-#else
-  dlen = sizeof (my_type_map) + (sizeof (my_type_map) / 100) + 20;
-  /* documentation says 100.1% oldSize + 12 bytes, but we
-   * should be able to overshoot by more to be safe */
-#endif
-  hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader));
-  hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader));
-  tmp = (char *) &hdr[1];
-  if ((Z_OK !=
-       compress2 ((Bytef *) tmp, &dlen, (const Bytef *) my_type_map,
-                  sizeof (my_type_map), 9)) || (dlen >= sizeof (my_type_map)))
-  {
-    dlen = sizeof (my_type_map);
-    memcpy (tmp, my_type_map, sizeof (my_type_map));
-    hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP);
-  }
-  else
-  {
-    hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP);
-  }
-  return hdr;
 }
 
 
-/**
- * Send a type map message to the neighbour.
- *
- * @param cls the type map message
- * @param key neighbour's identity
- * @param value 'struct Neighbour' of the target
- * @return always GNUNET_OK
- */
-static int
-send_type_map_to_neighbour (void *cls, const GNUNET_HashCode * key, void 
*value)
+void
+GSC_TYPEMAP_done ()
 {
-  struct GNUNET_MessageHeader *hdr = cls;
-  struct Neighbour *n = value;
-  struct MessageEntry *m;
-  uint16_t size;
-
-  if (n == &self)
-    return GNUNET_OK;
-  size = ntohs (hdr->size);
-  m = GNUNET_malloc (sizeof (struct MessageEntry) + size);
-  memcpy (&m[1], hdr, size);
-  m->deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
-  m->slack_deadline = GNUNET_TIME_UNIT_FOREVER_ABS;
-  m->priority = UINT_MAX;
-  m->sender_status = n->status;
-  m->size = size;
-  m->next = n->messages;
-  n->messages = m;
-  return GNUNET_OK;
 }
 
-
-
-/**
- * Send my type map to all connected peers (it got changed).
- */
-static void
-broadcast_my_type_map ()
-{
-  struct GNUNET_MessageHeader *hdr;
-
-  if (NULL == neighbours)
-    return;
-  hdr = compute_type_map_message ();
-  GNUNET_CONTAINER_multihashmap_iterate (neighbours,
-                                         &send_type_map_to_neighbour, hdr);
-  GNUNET_free (hdr);
-}
-
-
-
+/* end of gnunet-service-core_typemap.c */

Added: gnunet/src/core/gnunet-service-core_typemap.h
===================================================================
--- gnunet/src/core/gnunet-service-core_typemap.h                               
(rev 0)
+++ gnunet/src/core/gnunet-service-core_typemap.h       2011-10-06 19:27:35 UTC 
(rev 17265)
@@ -0,0 +1,66 @@
+*
+     This file is part of GNUnet.
+     (C) 2011 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 3, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file core/gnunet-service-core_typemap.h
+ * @brief management of map that specifies which message types this peer 
supports
+ * @author Christian Grothoff
+ */
+#ifndef GNUNET_SERVICE_CORE_TYPEMAP_H
+#define GNUNET_SERVICE_CORE_TYPEMAP_H
+
+#include "gnunet_util_lib.h"
+#include "gnunet_transport_service.h"
+#include "gnunet_service_core.h"
+
+
+/**
+ * Add a set of types to our type map.
+ */
+void
+GSC_TYPEMAP_add (const uint16_t *types,
+                unsigned int tlen);
+
+
+/**
+ * Remove a set of types from our type map.
+ */
+void
+GSC_TYPEMAP_remove (const uint16_t *types,
+                   unsigned int tlen);
+
+
+/**
+ * Test if any of the types from the types array is in the
+ * given type map.
+ *
+ * @param map map to test
+ * @param types array of types
+ * @param tcnt number of entries in types
+ * @return GNUNET_YES if a type is in the map, GNUNET_NO if not
+ */ 
+int
+GSC_TYPEMAP_test_match (struct GSC_TypeMap *tmap,
+                       const uint16_t *types,
+                       unsigned int tcnt);
+
+
+#endif
+/* end of gnunet-service-core_typemap.h */




reply via email to

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