gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r34880 - in gnunet/src: include rps


From: gnunet
Subject: [GNUnet-SVN] r34880 - in gnunet/src: include rps
Date: Tue, 13 Jan 2015 11:20:32 +0100

Author: ch3
Date: 2015-01-13 11:20:32 +0100 (Tue, 13 Jan 2015)
New Revision: 34880

Modified:
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/include/gnunet_rps_service.h
   gnunet/src/rps/gnunet-service-rps.c
   gnunet/src/rps/rps.h
   gnunet/src/rps/rps_api.c
Log:
implemented seeding

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2015-01-13 10:20:29 UTC (rev 
34879)
+++ gnunet/src/include/gnunet_protocols.h       2015-01-13 10:20:32 UTC (rev 
34880)
@@ -2678,7 +2678,12 @@
  */
 #define GNUNET_MESSAGE_TYPE_RPS_CS_REPLY        954
 
+/**
+ * RPS CS SEED Message for the Client to seed peers into rps
+ */
+#define GNUNET_MESSAGE_TYPE_RPS_CS_SEED        955
 
+
 
/*******************************************************************************/
 
 /**

Modified: gnunet/src/include/gnunet_rps_service.h
===================================================================
--- gnunet/src/include/gnunet_rps_service.h     2015-01-13 10:20:29 UTC (rev 
34879)
+++ gnunet/src/include/gnunet_rps_service.h     2015-01-13 10:20:32 UTC (rev 
34880)
@@ -65,7 +65,7 @@
  * @return handle to the rps service
  */
   struct GNUNET_RPS_Handle *
-GNUNET_RPS_connect( const struct GNUNET_CONFIGURATION_Handle *cfg );
+GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
 
 /**
  * Request n random peers.
@@ -95,7 +95,7 @@
  */
   void
 GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint64_t n,
-                     struct GNUNET_PeerIdentity * ids);
+                     const struct GNUNET_PeerIdentity * ids);
 
 /**
  * Cancle an issued request.
@@ -103,7 +103,7 @@
  * @param rh handle of the pending request to be canceled
  */
   void
-GNUNET_RPS_request_cancel ( struct GNUNET_RPS_Request_Handle *rh );
+GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh);
 
 /**
  * Disconnect from the rps service
@@ -111,7 +111,7 @@
  * @param h the handle to the rps service
  */
   void
-GNUNET_RPS_disconnect ( struct GNUNET_RPS_Handle *h );
+GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h);
 
 #if 0                           /* keep Emacsens' auto-indent happy */
 {

Modified: gnunet/src/rps/gnunet-service-rps.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps.c 2015-01-13 10:20:29 UTC (rev 34879)
+++ gnunet/src/rps/gnunet-service-rps.c 2015-01-13 10:20:32 UTC (rev 34880)
@@ -190,7 +190,7 @@
  * The size of sampler we need to be able to satisfy the client's need of
  * random peers.
  */
-static unsigned int sampler_size_client_need;
+//static unsigned int sampler_size_client_need;
 
 
 /**
@@ -526,8 +526,7 @@
  * @param message the actual message
  */
 static void
-// TODO rename
-handle_cs_request (void *cls,
+handle_client_request (void *cls,
             struct GNUNET_SERVER_Client *client,
             const struct GNUNET_MessageHeader *message)
 {
@@ -595,7 +594,50 @@
                              GNUNET_OK);
 }
 
+
 /**
+ * Handle seed from the client.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param message the actual message
+ */
+  static void
+handle_client_seed (void *cls,
+            struct GNUNET_SERVER_Client *client,
+            const struct GNUNET_MessageHeader *message)
+{
+  struct GNUNET_RPS_CS_SeedMessage *in_msg;
+  struct GNUNET_PeerIdentity *peers;
+  uint64_t i;
+
+  if (sizeof (struct GNUNET_RPS_CS_SeedMessage) < ntohs (message->size))
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client,
+              GNUNET_SYSERR);
+  }
+  in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message;
+  if (ntohs (message->size) - sizeof (struct GNUNET_RPS_CS_SeedMessage) /
+      sizeof (struct GNUNET_PeerIdentity) != GNUNET_ntohll (in_msg->num_peers))
+  {
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client,
+              GNUNET_SYSERR);
+  }
+
+  in_msg = (struct GNUNET_RPS_CS_SeedMessage *) message;
+  peers = (struct GNUNET_PeerIdentity *) &message[1];
+
+  for ( i = 0 ; i < GNUNET_ntohll (in_msg->num_peers) ; i++ )
+    RPS_sampler_update_list (&peers[i]);
+
+  GNUNET_SERVER_receive_done (client,
+                             GNUNET_OK);
+}
+
+
+/**
  * Handle a PUSH message from another peer.
  *
  * Check the proof of work and store the PeerID
@@ -1100,8 +1142,9 @@
 rps_start (struct GNUNET_SERVER_Handle *server)
 {
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
-    {&handle_cs_request, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST,
+    {&handle_client_request, NULL, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST,
       sizeof (struct GNUNET_RPS_CS_RequestMessage)},
+    {&handle_client_seed,    NULL, GNUNET_MESSAGE_TYPE_RPS_CS_SEED, 0},
     {NULL, NULL, 0, 0}
   };
 

Modified: gnunet/src/rps/rps.h
===================================================================
--- gnunet/src/rps/rps.h        2015-01-13 10:20:29 UTC (rev 34879)
+++ gnunet/src/rps/rps.h        2015-01-13 10:20:32 UTC (rev 34880)
@@ -150,12 +150,9 @@
   /**
    * Number of peers
    */
-  uint64_t n;
+  uint64_t num_peers;
 
-  /**
-   * Peers
-   */
-  struct GNUNET_PeerIdentity ids;
+  /* Followed by num_peers * GNUNET_PeerIdentity */
 };
 
 GNUNET_NETWORK_STRUCT_END

Modified: gnunet/src/rps/rps_api.c
===================================================================
--- gnunet/src/rps/rps_api.c    2015-01-13 10:20:29 UTC (rev 34879)
+++ gnunet/src/rps/rps_api.c    2015-01-13 10:20:32 UTC (rev 34880)
@@ -108,8 +108,6 @@
 };
 
 
-
-
 /**
  * This function is called, when the service replies to our request.
  * It calls the callback the caller gave us with the provided closure
@@ -141,9 +139,16 @@
 }
 
 /**
+ * Error handler for mq.
+ *
+ * This function is called whan mq encounters an error.
+ * Until now mq doesn't provide useful error messages.
+ *
+ * @param cls the closure
+ * @param error error code without specyfied meaning
  */
   static void
-mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
+mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 {
   //TODO LOG
 }
@@ -155,7 +160,7 @@
  * @return a handle to the service
  */
   struct GNUNET_RPS_Handle *
-GNUNET_RPS_connect( const struct GNUNET_CONFIGURATION_Handle *cfg )
+GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_RPS_Handle *h;
   //struct GNUNET_RPS_Request_Handle *rh;
@@ -197,19 +202,19 @@
   struct GNUNET_RPS_CS_RequestMessage *msg;
 
   // assert func != NULL
-  rh = GNUNET_new(struct GNUNET_RPS_Request_Handle);
+  rh = GNUNET_new (struct GNUNET_RPS_Request_Handle);
   rh->h = h;
   rh->n = req_handlers_size; // TODO ntoh
   rh->ready_cb = ready_cb;
   rh->ready_cb_cls = cls;
 
-  GNUNET_array_append(req_handlers, req_handlers_size, *rh);
+  GNUNET_array_append (req_handlers, req_handlers_size, *rh);
   //memcpy(&req_handlers[req_handlers_size-1], rh, sizeof(struct 
GNUNET_RPS_Request_Handle));
 
-  ev = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST);
-  msg->num_peers = GNUNET_htonll(n);
+  ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RPS_CS_REQUEST);
+  msg->num_peers = GNUNET_htonll (n);
   msg->n = rh->n;
-  GNUNET_MQ_send(h->mq, ev);
+  GNUNET_MQ_send (h->mq, ev);
   return rh;
 }
 
@@ -222,8 +227,16 @@
  */
   void
 GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint64_t n,
-                     struct GNUNET_PeerIdentity * ids)
+                     const struct GNUNET_PeerIdentity * ids)
 {
+  struct GNUNET_MQ_Envelope *ev;
+  struct GNUNET_RPS_CS_SeedMessage *msg;
+
+  ev = GNUNET_MQ_msg_extra (msg, n * sizeof (struct GNUNET_PeerIdentity),
+                            GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
+  msg->num_peers = GNUNET_htonll (n);
+  memcpy (&msg[1], ids, n * sizeof (struct GNUNET_PeerIdentity));
+  GNUNET_MQ_send (h->mq, ev);
 }
 
 /**
@@ -232,7 +245,7 @@
  * @param rh request handle of request to cancle
  */
   void
-GNUNET_RPS_request_cancel ( struct GNUNET_RPS_Request_Handle *rh )
+GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh)
 {
   // TODO
 }
@@ -243,10 +256,10 @@
  * @param h the handle to the rps service
  */
   void
-GNUNET_RPS_disconnect ( struct GNUNET_RPS_Handle *h )
+GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
 {
   if ( NULL != h->conn ) {
-    GNUNET_CLIENT_disconnect(h->conn);
+    GNUNET_CLIENT_disconnect (h->conn);
   }
 }
 




reply via email to

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