gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r27286 - gnunet/src/experimentation


From: gnunet
Subject: [GNUnet-SVN] r27286 - gnunet/src/experimentation
Date: Fri, 24 May 2013 13:25:39 +0200

Author: wachs
Date: 2013-05-24 13:25:34 +0200 (Fri, 24 May 2013)
New Revision: 27286

Modified:
   gnunet/src/experimentation/gnunet-daemon-experimentation.h
   gnunet/src/experimentation/gnunet-daemon-experimentation_capabilites.c
   gnunet/src/experimentation/gnunet-daemon-experimentation_nodes.c
Log:
changes


Modified: gnunet/src/experimentation/gnunet-daemon-experimentation.h
===================================================================
--- gnunet/src/experimentation/gnunet-daemon-experimentation.h  2013-05-24 
11:18:40 UTC (rev 27285)
+++ gnunet/src/experimentation/gnunet-daemon-experimentation.h  2013-05-24 
11:25:34 UTC (rev 27286)
@@ -43,6 +43,25 @@
 extern uint32_t GSE_node_capabilities;
 
 /**
+ * Capabilities a node has or an experiment requires
+ */
+enum GNUNET_EXPERIMENTATION_capabilities
+{
+       NONE = 0,
+       PLUGIN_TCP = 1,
+       PLUGIN_UDP = 2,
+       PLUGIN_UNIX = 4,
+       PLUGIN_HTTP_CLIENT = 8,
+       PLUGIN_HTTP_SERVER = 16,
+       PLUGIN_HTTPS_CLIENT = 32,
+       PLUGIN_HTTPS_SERVER = 64,
+       PLUGIN_WLAN = 128,
+       HAVE_IPV6 = 256,
+       BEHIND_NAT = 512
+};
+
+
+/**
  * A experimentation node
  */
 struct Node
@@ -61,6 +80,8 @@
         * Core transmission handle
         */
        struct GNUNET_CORE_TransmitHandle *cth;
+
+       uint32_t capabilities;
 };
 
 /**
@@ -70,6 +91,8 @@
 struct Experimentation_Request
 {
        struct GNUNET_MessageHeader msg;
+
+       uint32_t capabilities;
 };
 
 /**
@@ -79,6 +102,8 @@
 struct Experimentation_Response
 {
        struct GNUNET_MessageHeader msg;
+
+       uint32_t capabilities;
 };
 
 

Modified: gnunet/src/experimentation/gnunet-daemon-experimentation_capabilites.c
===================================================================
--- gnunet/src/experimentation/gnunet-daemon-experimentation_capabilites.c      
2013-05-24 11:18:40 UTC (rev 27285)
+++ gnunet/src/experimentation/gnunet-daemon-experimentation_capabilites.c      
2013-05-24 11:25:34 UTC (rev 27286)
@@ -33,35 +33,18 @@
 
 uint32_t GSE_node_capabilities;
 
-/**
- * Capabilities a node has or an experiment requires
- */
-enum ExperimentationCapabilities
-{
-       NONE = 0,
-       PLUGIN_TCP = 1,
-       PLUGIN_UDP = 2,
-       PLUGIN_UNIX = 4,
-       PLUGIN_HTTP_CLIENT = 8,
-       PLUGIN_HTTP_SERVER = 16,
-       PLUGIN_HTTPS_CLIENT = 32,
-       PLUGIN_HTTPS_SERVER = 64,
-       PLUGIN_WLAN = 128,
-       HAVE_IPV6 = 256,
-       BEHIND_NAT = 512
-};
 
-#define ExperimentationCapabilities_Count 11;
+#define GNUNET_EXPERIMENTATION_capabilities_count 11;
 
 /**
  * Capabilities a node has or an experiment requires string
  */
-#define ExperimentationCapabilities_String {"NONE", "PLUGIN_TCP", 
"PLUGIN_UDP", "PLUGIN_UNIX", "PLUGIN_HTTP_CLIENT", "PLUGIN_HTTP_SERVER", 
"PLUGIN_HTTPS_CLIENT", "PLUGIN_HTTPS_SERVER", "PLUGIN_WLAN", "HAVE_IPV6", 
"BEHIND_NAT"}
+#define GNUNET_EXPERIMENTATION_capabilities_string {"NONE", "PLUGIN_TCP", 
"PLUGIN_UDP", "PLUGIN_UNIX", "PLUGIN_HTTP_CLIENT", "PLUGIN_HTTP_SERVER", 
"PLUGIN_HTTPS_CLIENT", "PLUGIN_HTTPS_SERVER", "PLUGIN_WLAN", "HAVE_IPV6", 
"BEHIND_NAT"}
 
 const char *
 GNUNET_EXPERIMENTATION_capability_to_str (uint32_t cap)
 {
-       char * capstr[] = ExperimentationCapabilities_String;
+       char * capstr[] = GNUNET_EXPERIMENTATION_capabilities_string;
        unsigned index = 0;
        uint32_t test = 0;
 

Modified: gnunet/src/experimentation/gnunet-daemon-experimentation_nodes.c
===================================================================
--- gnunet/src/experimentation/gnunet-daemon-experimentation_nodes.c    
2013-05-24 11:18:40 UTC (rev 27285)
+++ gnunet/src/experimentation/gnunet-daemon-experimentation_nodes.c    
2013-05-24 11:25:34 UTC (rev 27286)
@@ -166,6 +166,7 @@
 
        msg.msg.size = htons (size);
        msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST);
+       msg.capabilities = htonl (GSE_node_capabilities);
        memcpy (buf, &msg, size);
 
        GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending request to peer %s\n"),
@@ -185,6 +186,7 @@
        n->cth = GNUNET_CORE_notify_transmit_ready(ch, GNUNET_NO, 0,
                                                                
GNUNET_TIME_relative_get_forever_(),
                                                                peer, size, 
send_request_cb, n);
+       n->capabilities = NONE;
 
        GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multihashmap_put 
(nodes_requested,
                        &peer->hashPubKey, n, 
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
@@ -209,6 +211,7 @@
 
        msg.msg.size = htons (size);
        msg.msg.type = htons (GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE);
+       msg.capabilities = htonl (GSE_node_capabilities);
        memcpy (buf, &msg, size);
 
        GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Sending response to peer %s\n"),
@@ -216,20 +219,33 @@
        return size;
 }
 
+static void node_make_active (struct Node *n)
+{
+  GNUNET_CONTAINER_multihashmap_put (nodes_active,
+                       &n->id.hashPubKey, n, 
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+       update_stats (nodes_active);
+       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' as active 
node\n"),
+                       GNUNET_i2s (&n->id));
+}
 
-static void handle_request (const struct GNUNET_PeerIdentity *peer)
+
+static void handle_request (const struct GNUNET_PeerIdentity *peer,
+                                                                               
                                const struct GNUNET_MessageHeader *message)
 {
        struct Node *n;
+       struct Experimentation_Request *rm = (struct Experimentation_Request *) 
message;
 
        if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, 
&peer->hashPubKey)))
        {
                        GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from 
%s peer `%s'\n"),
                                        "REQUEST", "active", GNUNET_i2s (peer));
+                       n->capabilities = ntohl (rm->capabilities);
        }
        else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get 
(nodes_requested, &peer->hashPubKey)))
        {
                        GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from 
%s peer `%s'\n"),
                                        "REQUEST", "requested", GNUNET_i2s 
(peer));
+                       n->capabilities = ntohl (rm->capabilities);
                        GNUNET_CONTAINER_multihashmap_remove (nodes_requested, 
&peer->hashPubKey, n);
                        if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
                        {
@@ -242,57 +258,51 @@
                                n->cth = NULL;
                        }
                        update_stats (nodes_requested);
-                 GNUNET_CONTAINER_multihashmap_put (nodes_active,
-                                       &peer->hashPubKey, n, 
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
-                       update_stats (nodes_active);
-                       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' 
active node \n"),
-                                       GNUNET_i2s (peer));
+                       node_make_active (n);
        }
        else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get 
(nodes_inactive, &peer->hashPubKey)))
        {
                        GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from 
%s peer `%s'\n"),
                                        "REQUEST", "inactive", GNUNET_i2s 
(peer));
+                       n->capabilities = ntohl (rm->capabilities);
                        GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, 
&peer->hashPubKey, n);
                        update_stats (nodes_inactive);
-                 GNUNET_CONTAINER_multihashmap_put (nodes_active,
-                                       &peer->hashPubKey, n, 
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
-                       update_stats (nodes_active);
-                       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' 
active node \n"),
-                                       GNUNET_i2s (peer));
+                       node_make_active (n);
        }
        else
        {
                        /* Create new node */
                        n = GNUNET_malloc (sizeof (struct Node));
                        n->id = *peer;
+                       n->capabilities = NONE;
+                       n->capabilities = ntohl (rm->capabilities);
                        GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from 
%s peer `%s'\n"),
                                        "REQUEST", "new", GNUNET_i2s (peer));
-                 GNUNET_CONTAINER_multihashmap_put (nodes_active,
-                                       &peer->hashPubKey, n, 
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
-                       update_stats (nodes_active);
-                       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' 
active node \n"),
-                                       GNUNET_i2s (peer));
+                       node_make_active (n);
        }
-
        n->cth = GNUNET_CORE_notify_transmit_ready (ch, GNUNET_NO, 0,
                                                                
GNUNET_TIME_relative_get_forever_(),
                                                                peer, sizeof 
(struct Experimentation_Response),
                                                                
send_response_cb, n);
 }
 
-static void handle_response (const struct GNUNET_PeerIdentity *peer)
+static void handle_response (const struct GNUNET_PeerIdentity *peer,
+                                                                               
                                 const struct GNUNET_MessageHeader *message)
 {
        struct Node *n;
+       struct Experimentation_Request *rm = (struct Experimentation_Request *) 
message;
 
        if (NULL != (n = GNUNET_CONTAINER_multihashmap_get (nodes_active, 
&peer->hashPubKey)))
        {
                        GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from 
%s peer `%s'\n"),
                                        "RESPONSE", "active", GNUNET_i2s 
(peer));
+                       n->capabilities = ntohl (rm->capabilities);
        }
        else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get 
(nodes_requested, &peer->hashPubKey)))
        {
                        GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from 
%s peer `%s'\n"),
                                        "RESPONSE", "requested", GNUNET_i2s 
(peer));
+                       n->capabilities = ntohl (rm->capabilities);
                        GNUNET_CONTAINER_multihashmap_remove (nodes_requested, 
&peer->hashPubKey, n);
                        if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
                        {
@@ -305,28 +315,22 @@
                                n->cth = NULL;
                        }
                        update_stats (nodes_requested);
-                 GNUNET_CONTAINER_multihashmap_put (nodes_active,
-                                       &peer->hashPubKey, n, 
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
-                       update_stats (nodes_active);
-                       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' 
active node \n"),
-                                       GNUNET_i2s (peer));
+                       node_make_active (n);
        }
        else if (NULL != (n = GNUNET_CONTAINER_multihashmap_get 
(nodes_inactive, &peer->hashPubKey)))
        {
                        GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from 
peer `%s'\n"),
                                        "RESPONSE", "inactive", GNUNET_i2s 
(peer));
+                       n->capabilities = ntohl (rm->capabilities);
                        GNUNET_CONTAINER_multihashmap_remove (nodes_inactive, 
&peer->hashPubKey, n);
                        update_stats (nodes_inactive);
-                 GNUNET_CONTAINER_multihashmap_put (nodes_active,
-                                       &peer->hashPubKey, n, 
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
-                       update_stats (nodes_active);
-                       GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Added peer `%s' 
active node \n"),
-                                       GNUNET_i2s (peer));
+                       node_make_active (n);
        }
        else
        {
                        GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Received %s from 
%s peer `%s'\n"),
                                        "RESPONSE", "unknown", GNUNET_i2s 
(peer));
+                       return;
        }
 }
 
@@ -390,10 +394,10 @@
 
        switch (ntohs (message->type)) {
                case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_REQUEST:
-                       handle_request (other);
+                       handle_request (other, message);
                        break;
                case GNUNET_MESSAGE_TYPE_EXPERIMENTATION_RESPONSE:
-                       handle_response (other);
+                       handle_response (other, message);
                        break;
                default:
                        break;




reply via email to

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