gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r4816 - in GNUnet: . src/applications src/applications/dht/


From: gnunet
Subject: [GNUnet-SVN] r4816 - in GNUnet: . src/applications src/applications/dht/tools src/applications/fs/ecrs src/applications/fs/fsui src/applications/identity src/applications/testing src/include
Date: Sun, 27 May 2007 20:08:08 -0600 (MDT)

Author: grothoff
Date: 2007-05-27 20:08:08 -0600 (Sun, 27 May 2007)
New Revision: 4816

Added:
   GNUnet/src/applications/testing/
   GNUnet/src/applications/testing/Makefile.am
   GNUnet/src/applications/testing/gnunet-testing.conf
   GNUnet/src/applications/testing/testing.c
   GNUnet/src/applications/testing/testingtest.c
   GNUnet/src/include/gnunet_util_core.h
Modified:
   GNUnet/configure.ac
   GNUnet/src/applications/Makefile.am
   GNUnet/src/applications/dht/tools/dhttest2.c
   GNUnet/src/applications/fs/ecrs/download.c
   GNUnet/src/applications/fs/ecrs/uri.c
   GNUnet/src/applications/fs/ecrs/uritest.c
   GNUnet/src/applications/fs/fsui/upload.c
   GNUnet/src/applications/identity/clientapi.c
   GNUnet/src/applications/identity/identity.c
   GNUnet/src/applications/identity/identity.h
   GNUnet/src/include/Makefile.am
   GNUnet/src/include/gnunet_core.h
   GNUnet/src/include/gnunet_ecrs_lib.h
   GNUnet/src/include/gnunet_identity_lib.h
   GNUnet/src/include/gnunet_protocols.h
   GNUnet/src/include/gnunet_testing_lib.h
Log:
API cleanup and new identity functions and new testing library

Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2007-05-28 01:53:20 UTC (rev 4815)
+++ GNUnet/configure.ac 2007-05-28 02:08:08 UTC (rev 4816)
@@ -608,6 +608,7 @@
 src/applications/stats/Makefile
 src/applications/tbench/Makefile
 src/applications/template/Makefile
+src/applications/testing/Makefile
 src/applications/topology_default/Makefile
 src/applications/topology_f2f/Makefile
 src/applications/tracekit/Makefile

Modified: GNUnet/src/applications/Makefile.am
===================================================================
--- GNUnet/src/applications/Makefile.am 2007-05-28 01:53:20 UTC (rev 4815)
+++ GNUnet/src/applications/Makefile.am 2007-05-28 02:08:08 UTC (rev 4816)
@@ -15,13 +15,14 @@
 endif
 
 SUBDIRS        = \
+ identity \
+ testing \
  advertising \
  bootstrap_http \
  datastore \
  rpc \
  fragmentation \
  getoption \
- identity \
  fs \
  state \
  stats \

Modified: GNUnet/src/applications/dht/tools/dhttest2.c
===================================================================
--- GNUnet/src/applications/dht/tools/dhttest2.c        2007-05-28 01:53:20 UTC 
(rev 4815)
+++ GNUnet/src/applications/dht/tools/dhttest2.c        2007-05-28 02:08:08 UTC 
(rev 4816)
@@ -204,11 +204,11 @@
   hash("key", 3, &key);
   
   /* switch to peer2 */
-  GC_set_configuration_value_number(cfg,
+  GC_set_configuration_value_string(cfg,
                                    ectx,
                                    "NETWORK",
-                                   "PORT",
-                                   12087);
+                                   "HOST",
+                                   "localhost:12087");
   hash("key", 3, &key);
   value = MALLOC(8);
   value->size = ntohl(8);
@@ -250,11 +250,11 @@
   printf("Peer2 tests successful.\n");
 
   /* switch to peer1 */
-  GC_set_configuration_value_number(cfg,
+  GC_set_configuration_value_string(cfg,
                                    ectx,
                                    "NETWORK",
-                                   "PORT",
-                                   2087);
+                                   "HOST",
+                                   "localhost:2087");
   printf("Peer1 gets key\n");
   CHECK(1 == DHT_LIB_get(cfg,
                         ectx,

Modified: GNUnet/src/applications/fs/ecrs/download.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/download.c  2007-05-28 01:53:20 UTC (rev 
4815)
+++ GNUnet/src/applications/fs/ecrs/download.c  2007-05-28 02:08:08 UTC (rev 
4816)
@@ -1471,22 +1471,17 @@
     return SYSERR;
   }
   if (ECRS_isLocationUri(uri)) {
-    const Location * loc = &uri->data.loc;
     struct ClientServerConnection * sock;
+    P2P_hello_MESSAGE * hello;
 
     sock = client_connection_create(rm->ectx,
                                    rm->cfg);
-
+    hello = ECRS_getHelloFromUri(uri);
     gnunet_identity_peer_add(sock,
-                            &loc->peer,
-                            loc->expirationTime,
-                            loc->proto,
-                            loc->sas,
-                            loc->mtu,
-                            loc->address,
-                            &loc->helloSignature);
+                            hello);
+    FREE(hello);
     connection_destroy(sock);
-    hash(&loc->peer,
+    hash(&uri->data.loc.peer,
         sizeof(PublicKey),
         &rm->target.hashPubKey);
     rm->have_target = YES;

Modified: GNUnet/src/applications/fs/ecrs/uri.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/uri.c       2007-05-28 01:53:20 UTC (rev 
4815)
+++ GNUnet/src/applications/fs/ecrs/uri.c       2007-05-28 02:08:08 UTC (rev 
4816)
@@ -1078,14 +1078,15 @@
  */
 struct ECRS_URI *
 ECRS_uriFromLocation(const struct ECRS_URI * baseUri,
-                    const PublicKey * sender,
-                    TIME_T expirationTime,
-                    unsigned short proto,
-                    unsigned short sas,
-                    unsigned int mtu,
-                    const char * address,
+                    const P2P_hello_MESSAGE * helloa,
                     ECRS_SignFunction signer,
-                    void * signer_cls) {
+                    void * signer_cls) { 
+  const PublicKey * sender = &helloa->publicKey;
+  TIME_T expirationTime = ntohl(helloa->expirationTime);
+  unsigned short proto = ntohs(helloa->protocol);
+  unsigned short sas = ntohs(helloa->senderAddressSize);
+  unsigned int mtu = ntohl(helloa->MTU);
+  const char * address = (const char*) &helloa[1];
   struct ECRS_URI * uri;
   P2P_hello_MESSAGE * hello;
   

Modified: GNUnet/src/applications/fs/ecrs/uritest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/uritest.c   2007-05-28 01:53:20 UTC (rev 
4815)
+++ GNUnet/src/applications/fs/ecrs/uritest.c   2007-05-28 02:08:08 UTC (rev 
4816)
@@ -64,20 +64,26 @@
   PublicKey pk;
   struct PrivateKey * hk;
   struct ECRS_URI * baseURI;
+  P2P_hello_MESSAGE * fake;
 
   baseURI = ECRS_stringToUri(NULL, 
"gnunet://ecrs/chk/C282GG70GKK41O4551011DO413KFBVTVMQG1OG30I0K4045N0G41HAPB82G680A02JRVVFO8URVRU2F159011DO41000000022RG820.RNVVVVOOLCLK065B5D04HTNVNSIB2AI022RG8200HSLK1CO1000ATQ98824DMA2032LIMG50CG0K057NVUVG200000H000004400000.42");
   hk = makePrivateKey();
   getPublicKey(hk,
               &pk);
+  fake = MALLOC(sizeof(P2P_hello_MESSAGE) + 4);
+  memcpy(&fake[1],
+        "GNU!",
+        4);
+  fake->senderAddressSize = htons(4);
+  fake->expirationTime = htonl(TIME(NULL) + 60);
+  fake->protocol = htons(42);
+  fake->MTU = htonl(1500);
+  fake->publicKey = pk;
   uri = ECRS_uriFromLocation(baseURI,
-                            &pk,
-                            TIME(NULL) + 60,
-                            42, /* PROTO */
-                            4, /* SAS */
-                            1500, /* MTU */
-                            "GNU!", /* location */
+                            fake,
                             (ECRS_SignFunction) &sign,
                             hk);
+  FREE(fake);
   freePrivateKey(hk);
   if (uri == NULL) {
     GE_BREAK(NULL, 0);

Modified: GNUnet/src/applications/fs/fsui/upload.c
===================================================================
--- GNUnet/src/applications/fs/fsui/upload.c    2007-05-28 01:53:20 UTC (rev 
4815)
+++ GNUnet/src/applications/fs/fsui/upload.c    2007-05-28 02:08:08 UTC (rev 
4816)
@@ -362,36 +362,18 @@
        (utc->shared->doIndex == YES) ) {
     /* generate location URI for non-anonymous download */
     struct ClientServerConnection  * sock;
-    PublicKey my_publicKey;
-    unsigned short proto;
-    TIME_T expirationTime;
-    unsigned short sas;
-    unsigned int mtu;
-    char * address;
+    P2P_hello_MESSAGE * hello;
     
     sock = client_connection_create(utc->shared->ctx->ectx,
                                    utc->shared->ctx->cfg);
                                    
-    address = NULL;
     if (OK == gnunet_identity_get_self(sock,
-                                      &my_publicKey,
-                                      &expirationTime,
-                                      &proto,
-                                      &sas,
-                                      &mtu,
-                                      &address)) {
+                                      &hello)) {
       loc = ECRS_uriFromLocation(utc->uri,
-                                &my_publicKey,
-                                expirationTime,
-                                proto,
-                                sas,
-                                mtu,
-                                address,
+                                hello,
                                 (ECRS_SignFunction) 
&gnunet_identity_sign_function,
                                 sock);
-      if ( (sas > 0) &&
-          (address != NULL) )
-       FREE(address);
+      FREE(hello);
     } else {
       /* may happen if no transports are available... */
       loc = ECRS_dupUri(utc->uri);

Modified: GNUnet/src/applications/identity/clientapi.c
===================================================================
--- GNUnet/src/applications/identity/clientapi.c        2007-05-28 01:53:20 UTC 
(rev 4815)
+++ GNUnet/src/applications/identity/clientapi.c        2007-05-28 02:08:08 UTC 
(rev 4816)
@@ -36,45 +36,29 @@
  * @return OK on success, SYSERR on error
  */
 int gnunet_identity_peer_add(struct ClientServerConnection * sock,
-                            const PublicKey * key,
-                            TIME_T expirationTime,
-                            unsigned short proto,
-                            unsigned short sas,
-                            unsigned int mtu,
-                            const char * address,
-                            const Signature * signature) {
-  CS_identity_hello_MESSAGE * msg;
+                            const P2P_hello_MESSAGE * hello) {
+  P2P_hello_MESSAGE * msg;
 
-  msg = MALLOC(sizeof(CS_identity_hello_MESSAGE) + sas);
-  msg->m.header.type = htons(CS_PROTO_identity_HELLO);
-  msg->m.header.size = htons(sizeof(CS_identity_hello_MESSAGE) + sas);
-  msg->m.signature = *signature;
-  msg->m.publicKey = *key;
-  hash(key,
-       sizeof(PublicKey),
-       &msg->m.senderIdentity.hashPubKey);
-  msg->m.expirationTime = htonl(expirationTime);
-  msg->m.MTU = htonl(mtu);
-  msg->m.senderAddressSize = htons(sas);
-  msg->m.protocol = htons(proto);
-  memcpy(&msg[1],
-        address,
-        sas);
+  msg = MALLOC(P2P_hello_MESSAGE_size(hello));
+  memcpy(msg,
+        hello,
+        P2P_hello_MESSAGE_size(hello));
+  msg->header.type = htons(CS_PROTO_identity_HELLO);
   /* check that signature is valid -- internal
      sanity check... */
-  if (SYSERR == verifySig(&msg->m.senderIdentity,
-                         P2P_hello_MESSAGE_size(&msg->m)
+  if (SYSERR == verifySig(&msg->senderIdentity,
+                         P2P_hello_MESSAGE_size(msg)
                          - sizeof(Signature)
                          - sizeof(PublicKey)
                          - sizeof(MESSAGE_HEADER),
-                         &msg->m.signature,
-                         key)) {
+                         &msg->signature,
+                         &msg->publicKey)) {
     GE_BREAK(NULL, 0);
     FREE(msg);
     return SYSERR;
   } 
   if (SYSERR == connection_write(sock,
-                                &msg->m.header)) {
+                                &msg->header)) {
     FREE(msg);
     return SYSERR;
   }
@@ -129,14 +113,9 @@
  * @return SYSERR on error, OK on success
  */
 int gnunet_identity_get_self(struct ClientServerConnection * sock,
-                            PublicKey * key,
-                            TIME_T * expirationTime,
-                            unsigned short * proto,
-                            unsigned short * sas,
-                            unsigned int * mtu,
-                            char ** address) {
+                            P2P_hello_MESSAGE ** msg) {
   MESSAGE_HEADER req;
-  CS_identity_hello_MESSAGE * reply;
+  P2P_hello_MESSAGE * reply;
 
   req.size = htons(sizeof(MESSAGE_HEADER));
   req.type = htons(CS_PROTO_identity_request_HELLO);
@@ -148,28 +127,43 @@
     connection_close_temporarily(sock);
     return SYSERR;
   }
-  if ( (ntohs(reply->m.header.size) < sizeof(CS_identity_hello_MESSAGE)) ||
-       (ntohs(reply->m.header.type) != CS_PROTO_identity_HELLO) ||
-       (ntohs(reply->m.header.size) != ntohs(reply->m.senderAddressSize) + 
sizeof(CS_identity_hello_MESSAGE)) ) {
+  if ( (ntohs(reply->header.size) < sizeof(P2P_hello_MESSAGE)) ||
+       (ntohs(reply->header.type) != CS_PROTO_identity_HELLO) ||
+       (ntohs(reply->header.size) != P2P_hello_MESSAGE_size(reply)) ) {
     FREE(reply);
     return SYSERR;
   }
-  *key = reply->m.publicKey;
-  *expirationTime = ntohl(reply->m.expirationTime);
-  *proto = ntohs(reply->m.protocol);
-  *sas = ntohs(reply->m.senderAddressSize);
-  *mtu = ntohl(reply->m.MTU);
-  if (*sas > 0) {
-    *address = MALLOC(*sas);
-    memcpy(*address,
-          &reply[1],
-          *sas);
-  } 
-  FREE(reply);
+  reply->header.type = htons(p2p_PROTO_hello);
+  *msg = reply;
   return OK;
 }
 
 
+/**
+ * Request the peer to connect to another peer
+ * @return SYSERR on error, YES if connection is now there
+ *         NO if connection is not yet present
+ */
+int gnunet_identity_request_connect(struct ClientServerConnection * sock,
+                                   const PeerIdentity * peer) {
+  
+  CS_identity_connect_MESSAGE msg;
+  int result;
 
+  msg.header.type
+    = htons(CS_PROTO_identity_CONNECT);
+  msg.header.size
+    = htons(sizeof(CS_identity_connect_MESSAGE));
+  msg.other 
+    = *peer;
+  if (SYSERR == connection_write(sock,
+                                &msg.header))
+    return SYSERR;
+  if (SYSERR == connection_read_result(sock,
+                                      &result))
+    return SYSERR;
+  return result;
+}
 
+
 /* end of clientapi.c */

Modified: GNUnet/src/applications/identity/identity.c
===================================================================
--- GNUnet/src/applications/identity/identity.c 2007-05-28 01:53:20 UTC (rev 
4815)
+++ GNUnet/src/applications/identity/identity.c 2007-05-28 02:08:08 UTC (rev 
4816)
@@ -32,7 +32,7 @@
  */
 
 #include "platform.h"
-#include "gnunet_util.h"
+#include "gnunet_util_core.h"
 #include "gnunet_protocols.h"
 #include "gnunet_directories.h"
 #include "gnunet_identity_service.h"
@@ -1101,23 +1101,37 @@
 }
 
 
+static int identityRequestConnectHandler(struct ClientHandle * sock,
+                                        const MESSAGE_HEADER * message) {
+  const CS_identity_connect_MESSAGE * msg;
+  unsigned int bpm;
+
+  if (sizeof(CS_identity_connect_MESSAGE) != ntohs(message->size))
+    return SYSERR;
+  msg = (const CS_identity_connect_MESSAGE*) message;
+  coreAPI->unicast(&msg->other,
+                  NULL,
+                  0,
+                  0);
+  bpm = coreAPI->queryBPMfromPeer(&msg->other);
+  return coreAPI->sendValueToClient(sock,
+                                   bpm == 0 ? NO : YES);
+}
+
 static int identityHelloHandler(struct ClientHandle * sock,
                                const MESSAGE_HEADER * message) {
-  const CS_identity_hello_MESSAGE * msg;
+  const P2P_hello_MESSAGE * msg;
   P2P_hello_MESSAGE * hello;
 
-  if (sizeof(CS_identity_hello_MESSAGE) < ntohs(message->size))
+  if (sizeof(P2P_hello_MESSAGE) < ntohs(message->size))
     return SYSERR;
-  GE_ASSERT(NULL,
-           sizeof(CS_identity_hello_MESSAGE)
-           == sizeof(P2P_hello_MESSAGE));
-  msg = (const CS_identity_hello_MESSAGE*) message;
-  hello = MALLOC(ntohs(msg->m.header.size));
-  memcpy(hello, msg, ntohs(msg->m.header.size));
+  msg = (const P2P_hello_MESSAGE*) message;
+  hello = MALLOC(ntohs(msg->header.size));
+  memcpy(hello, msg, ntohs(msg->header.size));
   hello->header.type = htons(p2p_PROTO_hello);
   coreAPI->injectMessage(NULL,
                         (const char*) hello,
-                        ntohs(msg->m.header.size),
+                        ntohs(msg->header.size),
                         NO,
                         NULL);
   FREE(hello);
@@ -1143,7 +1157,6 @@
   P2P_hello_MESSAGE * hello;
   int pos;
   int ret;
-  CS_identity_hello_MESSAGE * reply;
 
   /* we cannot permanently load transport
      since that would cause a cyclic dependency;
@@ -1159,14 +1172,10 @@
   coreAPI->releaseService(tapi);
   if (hello == NULL)
     return SYSERR;
-  GE_ASSERT(NULL,
-           sizeof(CS_identity_hello_MESSAGE)
-           == sizeof(P2P_hello_MESSAGE));
-  reply = (CS_identity_hello_MESSAGE*) hello;
-  reply->m.header.type = htons(CS_PROTO_identity_HELLO);
+  hello->header.type = htons(CS_PROTO_identity_HELLO);
   ret = coreAPI->sendToClient(sock,
-                             &reply->m.header);
-  FREE(reply);
+                             &hello->header);
+  FREE(hello);
   return ret;
 }
 
@@ -1277,7 +1286,9 @@
               &cronDiscardHosts,
               0,
               CRON_DISCARD_HOSTS_INTERVAL,
-              NULL);
+              NULL); 
+  coreAPI->registerClientHandler(CS_PROTO_identity_CONNECT,
+                                  &identityRequestConnectHandler);
   coreAPI->registerClientHandler(CS_PROTO_identity_HELLO,
                                 &identityHelloHandler);
   coreAPI->registerClientHandler(CS_PROTO_identity_request_HELLO,
@@ -1295,6 +1306,8 @@
   int j;
   HostEntry * entry;
 
+  coreAPI->unregisterClientHandler(CS_PROTO_identity_CONNECT,
+                                  &identityRequestConnectHandler);
   coreAPI->unregisterClientHandler(CS_PROTO_identity_HELLO,
                                   &identityHelloHandler);
   coreAPI->unregisterClientHandler(CS_PROTO_identity_request_HELLO,

Modified: GNUnet/src/applications/identity/identity.h
===================================================================
--- GNUnet/src/applications/identity/identity.h 2007-05-28 01:53:20 UTC (rev 
4815)
+++ GNUnet/src/applications/identity/identity.h 2007-05-28 02:08:08 UTC (rev 
4816)
@@ -27,29 +27,23 @@
 #include "gnunet_core.h"
 
 /**
- * Format of the message to inform gnunetd about a 
- * HELLO from the client-side.  Just another name
- * for the P2P_hello_MESSAGE -- except that in this
- * struct the "type" will be different!  Note that
- * the code depends on the structual (and size-wise)
- * equality of CS_identity_hello_MESSAGE and
- * P2P_hello_MESSAGE.
+ * Format of the signature response.
  */
 typedef struct {
+  MESSAGE_HEADER header;
 
-  P2P_hello_MESSAGE m;
+  Signature sig;
+} CS_identity_signature_MESSAGE;
 
-} CS_identity_hello_MESSAGE;
 
-
 /**
- * Format of the signature response.
+ * Format of the connection request.
  */
 typedef struct {
   MESSAGE_HEADER header;
 
-  Signature sig;
-} CS_identity_signature_MESSAGE;
+  PeerIdentity other;
+} CS_identity_connect_MESSAGE;
 
 
 #endif

Added: GNUnet/src/applications/testing/Makefile.am
===================================================================
--- GNUnet/src/applications/testing/Makefile.am                         (rev 0)
+++ GNUnet/src/applications/testing/Makefile.am 2007-05-28 02:08:08 UTC (rev 
4816)
@@ -0,0 +1,34 @@
+INCLUDES = -I$(top_srcdir)/src/include
+
+plugindir = $(libdir)/GNUnet
+
+lib_LTLIBRARIES = \
+  libgnunettesting_api.la
+
+libgnunettesting_api_la_SOURCES = \
+  testing.c 
+libgnunettesting_api_la_LIBADD = \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/util/crypto/libgnunetutil_crypto.la \
+  $(top_builddir)/src/util/config_impl/libgnunetutil_config.la \
+  $(top_builddir)/src/util/network_client/libgnunetutil_network_client.la \
+  $(top_builddir)/src/applications/identity/libgnunetidentity_api.la 
+
+
+check_PROGRAMS = \
+  testingtest
+
+TESTS = $(check_PROGRAMS)
+
+testingtest_SOURCES = \
+ testingtest.c 
+testingtest_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/applications/testing/libgnunettesting_api.la
+
+
+pkgdata_DATA = \
+ gnunet-testing.conf
+
+EXTRA_DIST = \
+ $(pkgdata_DATA)

Added: GNUnet/src/applications/testing/gnunet-testing.conf
===================================================================
--- GNUnet/src/applications/testing/gnunet-testing.conf                         
(rev 0)
+++ GNUnet/src/applications/testing/gnunet-testing.conf 2007-05-28 02:08:08 UTC 
(rev 4816)
@@ -0,0 +1,67 @@
+# This is the configuration template for the GNUnet daemon when running
+# testcases (via make check).  This file is not used during
+* normal operation.
+[PATHS]
+GNUNETD_HOME     = /tmp/FIXME
+
+[GNUNETD]
+HELLOEXPIRES     = 60
+LOGFILE         = $GNUNETD_HOME/logs
+KEEPLOG         = 0
+PIDFILE         = $GNUNETD_HOME/gnunetd.pid
+HOSTS          = $GNUNETD_HOME/data/hosts/
+APPLICATIONS = ""
+TRANSPORTS = ""
+
+[LOGGING]
+USER-LEVEL = ERROR
+ADMIN-LEVEL = ERROR
+
+[MODULES]
+sqstore = "sqstore_sqlite"
+topology = "topology_default"
+
+[NETWORK]
+PORT = 12087
+INTERFACE = eth0
+HELOEXCHANGE = NO
+TRUSTED = 127.0.0.0/8;
+
+[LOAD]
+INTERFACES      = eth0
+BASICLIMITING = YES
+MAXNETUPBPSTOTAL       = 50000
+MAXNETDOWNBPSTOTAL     = 50000
+MAXCPULOAD             = 100
+
+[TCP]
+PORT = 2086
+
+[HTTP]
+PORT = 1080
+
+[UDP]
+PORT = 2086
+
+[TCP6]
+PORT = 2088
+
+[UDP6]
+PORT = 2088
+
+
+
+[FS]
+QUOTA  = 1024
+ACTIVEMIGRATION = NO
+DIR          = $GNUNETD_HOME/fs-dir
+INDEX-DIRECTORY = $GNUNETD_HOME/data/shared/
+INDEX-QUOTA = 8192
+
+[GAP]
+TABLESIZE = 65536
+
+[DHT]
+BUCKETCOUNT = 160
+MASTER-TABLE-SIZE = 65536
+

Added: GNUnet/src/applications/testing/testing.c
===================================================================
--- GNUnet/src/applications/testing/testing.c                           (rev 0)
+++ GNUnet/src/applications/testing/testing.c   2007-05-28 02:08:08 UTC (rev 
4816)
@@ -0,0 +1,291 @@
+/*
+     This file is part of GNUnet.
+     (C) 2007 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 2, 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 applications/testing/testingtest.c
+ * @brief testcase for testing library
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_protocols.h"
+#include "gnunet_identity_lib.h"
+#include "gnunet_util_config_impl.h"
+#include "gnunet_testing_lib.h"
+
+static void updatePort(struct GC_Configuration *cfg,
+                      const char * section,
+                      unsigned short offset) {
+  unsigned long long old;
+
+  if ( (YES == GC_have_configuration_value(cfg,
+                                          section,
+                                          "PORT")) &&
+       (0 == GC_get_configuration_value_number(cfg,
+                                              section,
+                                              "PORT",
+                                              0,
+                                              65535,
+                                              65535,
+                                              &old)) ) {
+    old += offset;
+    GE_ASSERT(NULL,
+             0 == GC_set_configuration_value_number(cfg,
+                                                    NULL,
+                                                    section,
+                                                    "PORT",
+                                                    old));
+  }
+}
+
+/**
+ * Starts a gnunet daemon.
+ *
+ * @param app_port port to listen on for local clients
+ * @param tra_offset offset to add to transport ports
+ * @param gnunetd_home directory to use for the home directory
+ * @param transports transport services that should be loaded
+ * @param applications application services that should be loaded
+ * @param pid of the process (set)
+ * @param peer identity of the peer (set)
+ * @return OK on success, SYSERR on error
+ */
+int gnunet_testing_start_daemon(unsigned short app_port,
+                               unsigned short tra_offset,
+                               const char * gnunetd_home,
+                               const char * transports,
+                               const char * applications,
+                               pid_t * pid,
+                               PeerIdentity * peer) {
+  int ret;
+  char * ipath;
+  char * dpath;
+  struct GC_Configuration * cfg;
+  char host[128];
+  struct ClientServerConnection * sock;
+  P2P_hello_MESSAGE * hello;
+
+  disk_directory_remove(NULL, gnunetd_home);
+  ipath = os_get_installation_path(IPK_DATADIR);
+  if (ipath == NULL)
+    return SYSERR;
+  dpath = MALLOC(strlen(ipath) + 128);
+  strcpy(dpath, ipath);
+  FREE(ipath);
+  strcat(dpath, DIR_SEPARATOR_STR "gnunet-testing.conf");
+  cfg = GC_create_C_impl();
+  if (-1 == GC_parse_configuration(cfg,
+                                  dpath)) {
+    GC_free(cfg);
+    FREE(dpath);
+    return SYSERR;
+  }
+  FREE(dpath);
+  updatePort(cfg, "TCP", tra_offset);
+  updatePort(cfg, "TCP6", tra_offset);
+  updatePort(cfg, "UDP", tra_offset);
+  updatePort(cfg, "UDP6", tra_offset);
+  updatePort(cfg, "HTTP", tra_offset);
+  updatePort(cfg, "SMTP", tra_offset);
+  GC_set_configuration_value_string(cfg,       
+                                   NULL,
+                                   "PATHS",
+                                   "GNUNETD_HOME",
+                                   gnunetd_home);
+  if (transports != NULL)
+    GC_set_configuration_value_string(cfg,     
+                                     NULL,
+                                     "GNUNETD",
+                                     "TRANSPORTS",
+                                     transports);
+  if (applications != NULL)
+    GC_set_configuration_value_string(cfg,
+                                     NULL,
+                                     "GNUNETD",
+                                     "APPLICATIONS",
+                                     applications);
+  GC_set_configuration_value_number(cfg,
+                                   NULL,
+                                   "NETWORK",
+                                   "PORT",
+                                   app_port);
+  dpath = STRDUP("/tmp/gnunet-config.XXXXXX");
+  ret = mkstemp(dpath);
+  if (ret == -1) {
+    GE_LOG_STRERROR_FILE(NULL,
+                         GE_ERROR | GE_USER | GE_BULK,
+                         "mkstemp",
+                        dpath);
+    FREE(dpath);
+    GC_free(cfg);
+    return SYSERR;
+  }
+  CLOSE(ret);  
+  if (0 != GC_write_configuration(cfg,
+                                 dpath)) {
+    FREE(dpath);
+    GC_free(cfg);
+    return SYSERR;
+  }  
+  GC_free(cfg);
+
+  cfg = GC_create_C_impl();
+  /* cfg is now client CFG for os_daemon_start */
+  SNPRINTF(host,
+          128,
+          "localhost:%u",
+          app_port);
+  GC_set_configuration_value_string(cfg,
+                                   NULL,
+                                   "NETWORK",
+                                   "HOST",
+                                   host);
+
+  ret = os_daemon_start(NULL,
+                       cfg,
+                       dpath,
+                       NO);
+  if (ret == -1) {
+    GC_free(cfg);
+    return SYSERR; 
+  } 
+  *pid = ret;
+
+  /* now get peer ID */
+  if (OK != connection_wait_for_running(NULL,
+                                       cfg,
+                                       30 * cronSECONDS)) {
+    GC_free(cfg);
+    UNLINK(dpath);
+    FREE(dpath);
+    return SYSERR;
+  }
+  // UNLINK(dpath);
+  FREE(dpath);
+  sock = client_connection_create(NULL,
+                                 cfg);
+  ret = gnunet_identity_get_self(sock,
+                                &hello);
+  if (ret == OK) {
+    hash(&hello->publicKey,
+        sizeof(PublicKey),
+        &peer->hashPubKey);
+    FREE(hello);
+  }
+  connection_destroy(sock);
+  GC_free(cfg);
+
+  return ret;
+}
+
+/**
+ * Establish a connection between two GNUnet daemons
+ * (both must run on this machine).
+ * 
+ * @param port1 client port of the first daemon
+ * @param port2 client port of the second daemon
+ * @return OK on success, SYSERR on failure
+ */
+int gnunet_testing_connect_daemons(unsigned short port1,
+                                  unsigned short port2) {
+  char host[128];
+  GC_Configuration * cfg1 = GC_create_C_impl();
+  GC_Configuration * cfg2 = GC_create_C_impl();
+  struct ClientServerConnection * sock1;
+  struct ClientServerConnection * sock2;
+  int ret;
+  P2P_hello_MESSAGE * h1;
+  P2P_hello_MESSAGE * h2;
+
+  ret = SYSERR;
+  SNPRINTF(host,
+          128,
+          "localhost:%u",
+          port1);
+  GC_set_configuration_value_string(cfg1,
+                                   NULL,
+                                   "NETWORK",
+                                   "HOST",
+                                   host);
+  SNPRINTF(host,
+          128,
+          "localhost:%u",
+          port2);
+  GC_set_configuration_value_string(cfg2,
+                                   NULL,
+                                   "NETWORK",
+                                   "HOST",
+                                   host);
+  if ( (OK == connection_wait_for_running(NULL,
+                                         cfg1,
+                                         30 * cronSECONDS) ) &&
+       (OK == connection_wait_for_running(NULL,
+                                         cfg2,
+                                         30 * cronSECONDS) ) ) {    
+    sock1 = client_connection_create(NULL,
+                                    cfg1);
+    sock2 = client_connection_create(NULL,
+                                    cfg2);
+    h1 = NULL;
+    h2 = NULL;
+    if ( (OK == gnunet_identity_get_self(sock1,
+                                        &h1)) &&
+        (OK == gnunet_identity_get_self(sock2,
+                                        &h2)) &&
+        (OK == gnunet_identity_peer_add(sock1,
+                                        h2)) &&
+        (OK == gnunet_identity_peer_add(sock2,
+                                        h1)) ) {
+      ret = 10;
+      while (ret-- >= 0) {
+       if (YES == gnunet_identity_request_connect(sock1,
+                                                  &h2->senderIdentity)) {
+         ret = OK;
+         break;
+       }
+       PTHREAD_SLEEP(2 * cronSECONDS);
+      }
+    }
+    FREENONNULL(h1);
+    FREENONNULL(h2);
+    connection_destroy(sock1);
+    connection_destroy(sock2);
+  } else {
+    fprintf(stderr,
+           "Failed to establish connection with peers.\n");
+  }
+  return ret;
+}
+
+
+/**
+ * Shutdown the GNUnet daemon waiting on the given port
+ * and running under the given pid.
+ *
+ * @return OK on success, SYSERR on failure
+ */
+int gnunet_testing_stop_daemon(unsigned short port,
+                              pid_t pid) {
+  if (os_daemon_stop(NULL, pid) != YES)
+    return SYSERR;
+  return OK;
+}
+
+/* end of testing.c */


Property changes on: GNUnet/src/applications/testing/testing.c
___________________________________________________________________
Name: svn:eol-style
   + native

Added: GNUnet/src/applications/testing/testingtest.c
===================================================================
--- GNUnet/src/applications/testing/testingtest.c                               
(rev 0)
+++ GNUnet/src/applications/testing/testingtest.c       2007-05-28 02:08:08 UTC 
(rev 4816)
@@ -0,0 +1,71 @@
+/*
+     This file is part of GNUnet.
+     (C) 2007 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 2, 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 applications/testing/testingtest.c
+ * @brief testcase for testing library
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_protocols.h"
+#include "gnunet_testing_lib.h"
+
+/**
+ * Testcase
+ * @return 0: ok, -1: error
+ */
+int main(int argc,
+        const char ** argv) {
+  pid_t daemon1;
+  pid_t daemon2;
+  PeerIdentity p1;
+  PeerIdentity p2;
+  int ret = 0;
+
+  if (OK != gnunet_testing_start_daemon(12087,
+                                       10000,
+                                       "/tmp/gnunet-testing-1",
+                                       "tcp",
+                                       "stats",
+                                       &daemon1,
+                                       &p1))
+    ret |= 1;
+  if (OK != gnunet_testing_start_daemon(22087,
+                                       20000,
+                                       "/tmp/gnunet-testing-2",
+                                       "tcp",
+                                       "stats",
+                                       &daemon2,
+                                       &p2))
+    ret |= 2;
+  if (OK != gnunet_testing_connect_daemons(12087,
+                                          22087))
+    ret |= 4;
+  if (OK != gnunet_testing_stop_daemon(12087,
+                                      daemon1))
+    ret |= 8;
+  if (OK != gnunet_testing_stop_daemon(22087,
+                                      daemon2))
+    ret |= 16;
+  return ret;
+}
+
+/* end of testingtest.c */


Property changes on: GNUnet/src/applications/testing/testingtest.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: GNUnet/src/include/Makefile.am
===================================================================
--- GNUnet/src/include/Makefile.am      2007-05-28 01:53:20 UTC (rev 4815)
+++ GNUnet/src/include/Makefile.am      2007-05-28 02:08:08 UTC (rev 4816)
@@ -55,6 +55,7 @@
   gnunet_util_config.h \
   gnunet_util_config_impl.h \
   gnunet_util_containers.h \
+  gnunet_util_core.h \
   gnunet_util_cron.h \
   gnunet_util_crypto.h \
   gnunet_util_disk.h \

Modified: GNUnet/src/include/gnunet_core.h
===================================================================
--- GNUnet/src/include/gnunet_core.h    2007-05-28 01:53:20 UTC (rev 4815)
+++ GNUnet/src/include/gnunet_core.h    2007-05-28 02:08:08 UTC (rev 4816)
@@ -27,9 +27,8 @@
 #ifndef COREAPI_H
 #define COREAPI_H
 
-#include "gnunet_util.h"
+#include "gnunet_util_core.h"
 #include "gnunet_util_cron.h"
-#include "gnunet_util_crypto.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -81,63 +80,6 @@
 } TSession;
 
 /**
- * @brief hello.  A hello body contains the current HostAddress, the
- * host identity (hash), the time how long the HostAddress is valid, a
- * signature signing the information above and the public key of the
- * host.  The hash of the public key must match the host identity.<p>
- *
- * The signature goes over the message starting at the PeerIdentity
- * and includes the senderAddress.  Since the senderAddress may be
- * long, what is actually signed is the hash of these bytes.
- */
-typedef struct {
-  MESSAGE_HEADER header;
-
-  /**
-   * The signature
-   */
-  Signature signature;
-
-  /**
-   * The public key
-   */
-  PublicKey publicKey;
-
-  /**
-   * Whose identity follows? No, this is NOT a duplicate
-   * as a node may send us the identity of ANOTHER node!
-   */
-  PeerIdentity senderIdentity;
-
-  /**
-   * time this address expires  (network byte order)
-   */
-  TIME_T expirationTime;
-
-  /**
-   * advertised MTU for sending (replies can have a different
-   * MTU!)
-   */
-  unsigned int MTU;
-
-  /**
-   * size of the sender address
-   */
-  unsigned short senderAddressSize;
-
-  /**
-   * protocol supported by the node (only one protocol
-   * can be advertised by the same hello)
-   * Examples are UDP, TCP, etc. This field is
-   * in network byte order
-   */
-  unsigned short protocol;
-
-} P2P_hello_MESSAGE;
-
-#define P2P_hello_MESSAGE_size(helo) ((sizeof(P2P_hello_MESSAGE) + 
ntohs((helo)->senderAddressSize)))
-
-/**
  * Opaque handle for client connections passed by
  * the core to the CSHandlers.
  */

Modified: GNUnet/src/include/gnunet_ecrs_lib.h
===================================================================
--- GNUnet/src/include/gnunet_ecrs_lib.h        2007-05-28 01:53:20 UTC (rev 
4815)
+++ GNUnet/src/include/gnunet_ecrs_lib.h        2007-05-28 02:08:08 UTC (rev 
4816)
@@ -27,7 +27,7 @@
 #ifndef GNUNET_ECRS_LIB_H
 #define GNUNET_ECRS_LIB_H
 
-#include "gnunet_util.h"
+#include "gnunet_util_core.h"
 #include "gnunet_core.h"
 #include <extractor.h>
 
@@ -346,12 +346,7 @@
  */
 struct ECRS_URI *
 ECRS_uriFromLocation(const struct ECRS_URI * baseUri,
-                    const PublicKey * sender,
-                    TIME_T expirationTime,
-                    unsigned short proto,
-                    unsigned short sas,
-                    unsigned int mtu,
-                    const char * address,
+                    const P2P_hello_MESSAGE * hello,
                     ECRS_SignFunction signer,
                     void * signer_cls);
 

Modified: GNUnet/src/include/gnunet_identity_lib.h
===================================================================
--- GNUnet/src/include/gnunet_identity_lib.h    2007-05-28 01:53:20 UTC (rev 
4815)
+++ GNUnet/src/include/gnunet_identity_lib.h    2007-05-28 02:08:08 UTC (rev 
4816)
@@ -27,9 +27,8 @@
 #ifndef GNUNET_IDENTITY_LIB_H
 #define GNUNET_IDENTITY_LIB_H
 
-#include "gnunet_util.h"
+#include "gnunet_util_core.h"
 #include "gnunet_util_network_client.h"
-#include "gnunet_util_crypto.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -38,6 +37,7 @@
 #endif
 #endif
 
+
 /**
  * Inform gnunetd about another peer.
  *
@@ -45,13 +45,7 @@
  * @return OK on success, SYSERR on error
  */
 int gnunet_identity_peer_add(struct ClientServerConnection * sock,
-                            const PublicKey * key,
-                            TIME_T expirationTime,
-                            unsigned short proto,
-                            unsigned short sas,
-                            unsigned int mtu,
-                            const char * address,
-                            const Signature * signature);
+                            const P2P_hello_MESSAGE * hello);
 
 /**
  * Function to request the peer to sign something
@@ -65,19 +59,20 @@
 /**
  * Function to request one of the peer's identities 
  * (that is, external addresses).
- * Except for the "sock" argument, all arguments are
- * set by the function.
+ *
  * @return SYSERR on error, OK on success
  */
 int gnunet_identity_get_self(struct ClientServerConnection * sock,
-                            PublicKey * key,
-                            TIME_T * expirationTime,
-                            unsigned short * proto,
-                            unsigned short * sas,
-                            unsigned int * mtu,
-                            char ** address);
+                            P2P_hello_MESSAGE ** hello);
 
 
+/**
+ * Request the peer to connect to another peer
+ * @return SYSERR on error, YES if connection is now there
+ *         NO if connection is not yet present
+ */
+int gnunet_identity_request_connect(struct ClientServerConnection * sock,
+                                   const PeerIdentity * peer);
 
 #if 0 /* keep Emacsens' auto-indent happy */
 {

Modified: GNUnet/src/include/gnunet_protocols.h
===================================================================
--- GNUnet/src/include/gnunet_protocols.h       2007-05-28 01:53:20 UTC (rev 
4815)
+++ GNUnet/src/include/gnunet_protocols.h       2007-05-28 02:08:08 UTC (rev 
4816)
@@ -193,6 +193,12 @@
 /* *********** messages for identity module ************* */
 
 /**
+ * Client asks the daemon to try to connect to
+ * a particular peer.
+ */
+#define CS_PROTO_identity_CONNECT 27
+
+/**
  * Client informs the Daemon about how to contact
  * a particular peer -- or daemon informs client
  * about how other peers should contact it.

Modified: GNUnet/src/include/gnunet_testing_lib.h
===================================================================
--- GNUnet/src/include/gnunet_testing_lib.h     2007-05-28 01:53:20 UTC (rev 
4815)
+++ GNUnet/src/include/gnunet_testing_lib.h     2007-05-28 02:08:08 UTC (rev 
4816)
@@ -21,6 +21,11 @@
 /**
  * @file include/gnunet_testing_lib.h
  * @brief convenience API for writing testcases for GNUnet
+ *        Many testcases need to start and stop gnunetd,
+ *        and this library is supposed to make that easier
+ *        for TESTCASES.  Normal programs should always
+ *        use functions from gnunet_util_os.h.  This API is
+ *        ONLY for writing testcases!
  * @author Christian Grothoff
  */
 
@@ -39,7 +44,8 @@
 /**
  * Starts a gnunet daemon.
  *
- * @param port port to listen on for local clients
+ * @param app_port port to listen on for local clients
+ * @param tra_offset offset to add to transport ports
  * @param gnunetd_home directory to use for the home directory
  * @param transports transport services that should be loaded
  * @param applications application services that should be loaded
@@ -47,7 +53,8 @@
  * @param peer identity of the peer (set)
  * @return OK on success, SYSERR on error
  */
-int gnunet_testing_start_daemon(unsigned short port,
+int gnunet_testing_start_daemon(unsigned short app_port,
+                               unsigned short tra_offset,
                                const char * gnunetd_home,
                                const char * transports,
                                const char * applications,

Added: GNUnet/src/include/gnunet_util_core.h
===================================================================
--- GNUnet/src/include/gnunet_util_core.h                               (rev 0)
+++ GNUnet/src/include/gnunet_util_core.h       2007-05-28 02:08:08 UTC (rev 
4816)
@@ -0,0 +1,95 @@
+/*
+     This file is part of GNUnet.
+     (C) 2007 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 2, 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 include/gnunet_util_core.h
+ * @brief shared stuff between clients and core
+ *
+ * @author Christian Grothoff
+ */
+
+#ifndef GNUNET_UTIL_CORE_H
+#define GNUNET_UTIL_CORE_H
+
+#include "gnunet_util.h"
+#include "gnunet_util_crypto.h"
+
+
+/**
+ * @brief hello.  A hello body contains the current HostAddress, the
+ * host identity (hash), the time how long the HostAddress is valid, a
+ * signature signing the information above and the public key of the
+ * host.  The hash of the public key must match the host identity.<p>
+ *
+ * The signature goes over the message starting at the PeerIdentity
+ * and includes the senderAddress.  Since the senderAddress may be
+ * long, what is actually signed is the hash of these bytes.
+ */
+typedef struct {
+  MESSAGE_HEADER header;
+
+  /**
+   * The signature
+   */
+  Signature signature;
+
+  /**
+   * The public key
+   */
+  PublicKey publicKey;
+
+  /**
+   * Whose identity follows? No, this is NOT a duplicate
+   * as a node may send us the identity of ANOTHER node!
+   */
+  PeerIdentity senderIdentity;
+
+  /**
+   * time this address expires  (network byte order)
+   */
+  TIME_T expirationTime;
+
+  /**
+   * advertised MTU for sending (replies can have a different
+   * MTU!)
+   */
+  unsigned int MTU;
+
+  /**
+   * size of the sender address
+   */
+  unsigned short senderAddressSize;
+
+  /**
+   * protocol supported by the node (only one protocol
+   * can be advertised by the same hello)
+   * Examples are UDP, TCP, etc. This field is
+   * in network byte order
+   */
+  unsigned short protocol;
+
+} P2P_hello_MESSAGE;
+
+#define P2P_hello_MESSAGE_size(hello) ((sizeof(P2P_hello_MESSAGE) + 
ntohs((hello)->senderAddressSize)))
+
+
+/* ifndef GNUNET_UTIL_CORE_H */
+#endif
+/* end of gnunet_util_core.h */


Property changes on: GNUnet/src/include/gnunet_util_core.h
___________________________________________________________________
Name: svn:eol-style
   + native





reply via email to

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