gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r4875 - in GNUnet/src: applications/fs/ecrs applications/fs


From: gnunet
Subject: [GNUnet-SVN] r4875 - in GNUnet/src: applications/fs/ecrs applications/fs/fsui applications/gap applications/testing include
Date: Wed, 30 May 2007 22:35:55 -0600 (MDT)

Author: grothoff
Date: 2007-05-30 22:35:55 -0600 (Wed, 30 May 2007)
New Revision: 4875

Added:
   GNUnet/src/applications/gap/gaptest3.c
   GNUnet/src/applications/testing/README
Modified:
   GNUnet/src/applications/fs/ecrs/download.c
   GNUnet/src/applications/fs/ecrs/ecrs.h
   GNUnet/src/applications/fs/ecrs/uri.c
   GNUnet/src/applications/fs/ecrs/uritest.c
   GNUnet/src/applications/fs/fsui/upload.c
   GNUnet/src/applications/gap/Makefile.am
   GNUnet/src/applications/gap/gaptest.c
   GNUnet/src/applications/gap/gaptest2.c
   GNUnet/src/include/gnunet_ecrs_lib.h
Log:
better location URIs

Modified: GNUnet/src/applications/fs/ecrs/download.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/download.c  2007-05-31 03:55:56 UTC (rev 
4874)
+++ GNUnet/src/applications/fs/ecrs/download.c  2007-05-31 04:35:55 UTC (rev 
4875)
@@ -1472,16 +1472,6 @@
     return SYSERR;
   }
   if (ECRS_isLocationUri(uri)) {
-    struct ClientServerConnection * sock;
-    P2P_hello_MESSAGE * hello;
-
-    sock = client_connection_create(rm->ectx,
-                                   rm->cfg);
-    hello = ECRS_getHelloFromUri(uri);
-    gnunet_identity_peer_add(sock,
-                            hello);
-    FREE(hello);
-    connection_destroy(sock);
     hash(&uri->data.loc.peer,
         sizeof(PublicKey),
         &rm->target.hashPubKey);

Modified: GNUnet/src/applications/fs/ecrs/ecrs.h
===================================================================
--- GNUnet/src/applications/fs/ecrs/ecrs.h      2007-05-31 03:55:56 UTC (rev 
4874)
+++ GNUnet/src/applications/fs/ecrs/ecrs.h      2007-05-31 04:35:55 UTC (rev 
4875)
@@ -52,7 +52,7 @@
   FileIdentifier fi;
 
   /**
-   * Public key of the peer sharing the file.
+   * Identity of the peer sharing the file.
    */
   PublicKey peer;
 
@@ -63,35 +63,6 @@
   TIME_T expirationTime;
 
   /**
-   * Transport protocol to use to contact the peer.
-   */
-  unsigned short proto;
-
-  /**
-   * Size of the address.
-   */
-  unsigned short sas;
-
-  /**
-   * MTU of the transport.
-   */
-  unsigned int mtu;
-
-  /**
-   * Address of the peer.
-   */
-  char * address;
-
-  /**
-   * RSA signature of the HELLO information
-   * (as constructed from the rest of the info
-   * in this struct).  This allows anyone to
-   * reconstruct a valid HELLO message from 
-   * the location URI.
-   */
-  Signature helloSignature;
-
-  /**
    * RSA signature over the FileIdentifier,
    * hash of the peer and expiration time.
    * (everything until proto).  

Modified: GNUnet/src/applications/fs/ecrs/uri.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/uri.c       2007-05-31 03:55:56 UTC (rev 
4874)
+++ GNUnet/src/applications/fs/ecrs/uri.c       2007-05-31 04:35:55 UTC (rev 
4875)
@@ -67,7 +67,7 @@
  * </li><li>
  *
  * The last category identifies a datum on a specific machine.  The
- * format is 
"gnunet://ecrs/loc/HEX1.HEX2.SIZE.PEER.SIG1.SIG2.PROTO.SAS.MTU.EXPTIME.ADDR".  
PEER is
+ * format is "gnunet://ecrs/loc/HEX1.HEX2.SIZE.PEER.SIG1.EXPTIME".  PEER is
  * the BinName of the public key of the peer storing the datum, SIG1 certifies
  * that this peer has this content; SIG2 is a signature for a HELLO
  * about peer, which is encoded in PROTO, SAS, MTU, EXPTIME and ADDR.
@@ -175,26 +175,20 @@
   EncName queryhash;
   char * peerId;
   char * peerSig;
-  char * peerHSig;
-  char * peerAddr;
 
   hash2enc(&loc->fi.chk.key,
            &keyhash);
   hash2enc(&loc->fi.chk.query,
            &queryhash);
-  n = 2148 + ntohs(loc->sas) * 2;
+  n = 2148;
   peerId = bin2enc(&loc->peer,
-                  sizeof(PublicKey));
+                   sizeof(PublicKey));
   peerSig = bin2enc(&loc->contentSignature,
                    sizeof(Signature));
-  peerHSig = bin2enc(&loc->helloSignature,
-                    sizeof(Signature));
-  peerAddr = bin2enc(loc->address,
-                    loc->sas);
   ret = MALLOC(n);
   SNPRINTF(ret,
           n,
-          "%s%s%s.%s.%llu.%s.%s.%s.%u.%u.%u.%u.%s",
+          "%s%s%s.%s.%llu.%s.%s.%u",
           ECRS_URI_PREFIX,
           ECRS_LOCATION_INFIX,
           (char*)&keyhash,
@@ -202,16 +196,9 @@
           ntohll(loc->fi.file_length),
           peerId,
           peerSig,
-          peerHSig,
-          loc->proto,
-          loc->sas,
-          loc->mtu,
-          loc->expirationTime,
-          peerAddr);
-  FREE(peerId);
+          loc->expirationTime);
   FREE(peerSig);
-  FREE(peerHSig);
-  FREE(peerAddr);
+  FREE(peerId);
   return ret;
 }
 
@@ -410,33 +397,6 @@
 }
 
 /**
- * (re)construct the HELLO message of the peer offering the data
- *
- * @return HELLO message
- */
-static P2P_hello_MESSAGE *
-getHelloFromLoc(const Location * loc) {
-  P2P_hello_MESSAGE * hello;
-
-  hello = MALLOC(sizeof(P2P_hello_MESSAGE) + loc->sas);
-  hello->header.size = htons(sizeof(P2P_hello_MESSAGE) + loc->sas);
-  hello->header.type = htons(p2p_PROTO_hello);
-  hello->MTU = htonl(loc->mtu);
-  hello->senderAddressSize = htons(loc->sas);
-  hello->protocol = htons(loc->proto);
-  hello->expirationTime = htonl(loc->expirationTime);
-  hello->publicKey = loc->peer;
-  hash(&hello->publicKey,
-       sizeof(PublicKey),
-       &hello->senderIdentity.hashPubKey);
-  hello->signature = loc->helloSignature;
-  memcpy(&hello[1],
-        loc->address,
-        loc->sas);
-  return hello;
-}
-
-/**
  * Parses an URI that identifies a location (and file).
  * Also verifies validity of the location URI.
  *
@@ -449,13 +409,11 @@
                            Location * loc) {
   unsigned int pos;
   unsigned int npos;
-  unsigned int proto;
-  unsigned int sas;
   int ret;
   size_t slen;
   char * dup;
   char * addr;
-  P2P_hello_MESSAGE * hello;
+
  
   GE_ASSERT(ectx, uri != NULL);
   addr = NULL;
@@ -492,12 +450,13 @@
                       &loc->fi.chk.query)) ||
        (1 != SSCANF(&dup[pos+sizeof(EncName)*2],
                    "%llu",
-                   &loc->fi.file_length)) ) 
+                   &loc->fi.file_length)) )
     goto ERR;
+  loc->fi.file_length = htonll(loc->fi.file_length);
   ret = enc2bin(&dup[npos],
                &loc->peer,
-               sizeof(PublicKey));
-  if (ret == -1) 
+               sizeof(PublicKey));
+  if (ret == -1)
     goto ERR;
   npos += ret;
   if (dup[npos++] != '.')
@@ -510,71 +469,18 @@
   npos += ret;
   if (dup[npos++] != '.')
     goto ERR;
-  ret = enc2bin(&dup[npos],
-               &loc->helloSignature,
-               sizeof(Signature));
-  if (ret == -1) 
-    goto ERR;
-  npos += ret;
-  if (dup[npos++] != '.')
-    goto ERR;
-  ret = 4;
-  pos = npos;
-  while ( (dup[npos] != '\0') &&
-         (ret > 0) ) {
-    if (dup[npos] == '.')
-      ret--;    
-    npos++;
-  }
-  if (ret != 0)
-    goto ERR;
-  dup[npos-1] = '\0';
-  if (4 != SSCANF(&dup[pos],
-                 "%u.%u.%u.%u",
-                 &proto,
-                 &sas,
-                 &loc->mtu,
+  if (1 != SSCANF(&dup[npos],
+                 "%u",
                  &loc->expirationTime))
     goto ERR;
-  if ( (proto >= 65536) ||
-       (sas >= 65536) )
-    goto ERR;
-  loc->proto = (unsigned short) proto;
-  loc->sas = (unsigned short) sas;
-  addr = MALLOC(sas);
-  loc->address = addr;
-  ret = enc2bin(&dup[npos],
-               addr,
-               sas);
-  if (ret == -1)
-    goto ERR;
-  npos += ret;
-  if (dup[npos] != '\0')
-    goto ERR;
-  loc->fi.file_length = htonll(loc->fi.file_length);
-  
   /* Finally: verify sigs! */
   if (OK != verifySig(&loc->fi,
                      sizeof(FileIdentifier) + 
-                     sizeof(PublicKey) +
+                     sizeof(PeerIdentity) +
                      sizeof(TIME_T),
                      &loc->contentSignature,
                      &loc->peer)) 
     goto ERR;
-  hello = getHelloFromLoc(loc);
-  if (hello == NULL) 
-    goto ERR;
-  if (OK != verifySig(&hello->senderIdentity,
-                     P2P_hello_MESSAGE_size(hello) -
-                     sizeof(MESSAGE_HEADER) -
-                     sizeof(Signature) -
-                     sizeof(PublicKey),
-                     &loc->helloSignature,
-                     &hello->publicKey)) { 
-    FREE(hello);
-    goto ERR;
-  }
-  FREE(hello);
   FREE(dup);
   return OK;
  ERR:
@@ -640,7 +546,6 @@
         0);
     break;
   case loc:
-    FREENONNULL(uri->data.loc.address);
     break;
   default:
     /* do nothing */
@@ -804,12 +709,6 @@
     }
     break;
   case loc:
-    if (ret->data.loc.sas > 0) {
-      ret->data.loc.address = MALLOC(ret->data.loc.sas);
-      memcpy(ret->data.loc.address,
-            uri->data.loc.address,
-            ret->data.loc.sas);
-    }
     break;
   default:
     break;
@@ -1006,14 +905,6 @@
               sizeof(unsigned short) +
               sizeof(unsigned short)) != 0)
       return NO;
-    if (memcmp(&uri1->data.loc.helloSignature,
-              &uri2->data.loc.helloSignature,
-              sizeof(Signature) * 2) != 0)
-      return NO;
-    if (memcmp(uri1->data.loc.address,
-              uri2->data.loc.address,
-              uri1->data.loc.sas) != 0)
-      return NO;
     return YES;               
   default:
     return NO;
@@ -1035,18 +926,6 @@
 }
 
 /**
- * (re)construct the HELLO message of the peer offering the data
- *
- * @return NULL if this is not a location URI
- */
-P2P_hello_MESSAGE *
-ECRS_getHelloFromUri(const struct ECRS_URI * uri) {
-  if (uri->type != loc)
-    return NULL;
-  return getHelloFromLoc(&uri->data.loc);
-}
-
-/**
  * Obtain the URI of the content itself.
  *
  * @return NULL if argument is not a location URI
@@ -1078,18 +957,11 @@
  */
 struct ECRS_URI *
 ECRS_uriFromLocation(const struct ECRS_URI * baseUri,
-                    const P2P_hello_MESSAGE * helloa,
+                    const PublicKey * sender,
+                    TIME_T expirationTime,
                     ECRS_SignFunction signer,
                     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;
-  
 
   if (baseUri->type != chk)
     return NULL;
@@ -1099,35 +971,9 @@
   uri->data.loc.fi = baseUri->data.fi;
   uri->data.loc.peer = *sender;
   uri->data.loc.expirationTime = expirationTime;
-  uri->data.loc.proto = proto;
-  uri->data.loc.sas = sas;
-  uri->data.loc.mtu = mtu;
-  if (sas > 0) {
-    uri->data.loc.address = MALLOC(sas);
-    memcpy(uri->data.loc.address,
-          address,
-          sas);
-  } else {
-    uri->data.loc.address = NULL;
-  }
-  hello = ECRS_getHelloFromUri(uri);
-  if (hello == NULL) {
-    GE_BREAK(NULL, 0);
-    FREENONNULL(uri->data.loc.address);
-    FREE(uri);
-    return NULL;
-  }
   signer(signer_cls,
-        P2P_hello_MESSAGE_size(hello)
-        - sizeof(Signature)
-        - sizeof(PublicKey)
-        - sizeof(MESSAGE_HEADER), 
-        &hello->senderIdentity,
-        &uri->data.loc.helloSignature);
-  FREE(hello);
-  signer(signer_cls,
         sizeof(FileIdentifier) + 
-        sizeof(PublicKey) +
+        sizeof(PeerIdentity) +
         sizeof(TIME_T),
         &uri->data.loc.fi,
         &uri->data.loc.contentSignature);

Modified: GNUnet/src/applications/fs/ecrs/uritest.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/uritest.c   2007-05-31 03:55:56 UTC (rev 
4874)
+++ GNUnet/src/applications/fs/ecrs/uritest.c   2007-05-31 04:35:55 UTC (rev 
4875)
@@ -71,26 +71,16 @@
   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,
-                            fake,
+                            &pk,
+                            43,
                             (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-31 03:55:56 UTC (rev 
4874)
+++ GNUnet/src/applications/fs/fsui/upload.c    2007-05-31 04:35:55 UTC (rev 
4875)
@@ -370,9 +370,11 @@
     if (OK == gnunet_identity_get_self(sock,
                                       &hello)) {
       loc = ECRS_uriFromLocation(utc->uri,
-                                hello,
+                                &hello->publicKey,
+                                ntohl(hello->expirationTime),
                                 (ECRS_SignFunction) 
&gnunet_identity_sign_function,
                                 sock);
+                                
       FREE(hello);
     } else {
       /* may happen if no transports are available... */

Modified: GNUnet/src/applications/gap/Makefile.am
===================================================================
--- GNUnet/src/applications/gap/Makefile.am     2007-05-31 03:55:56 UTC (rev 
4874)
+++ GNUnet/src/applications/gap/Makefile.am     2007-05-31 04:35:55 UTC (rev 
4875)
@@ -21,7 +21,7 @@
 
 
 check_PROGRAMS = \
-  gaptest gaptest2
+  gaptest gaptest2 gaptest3
 
 TESTS = $(check_PROGRAMS)
 
@@ -49,5 +49,18 @@
   $(top_builddir)/src/util/libgnunetutil.la 
 
 
+gaptest3_SOURCES = \
+  gaptest3.c 
+gaptest3_LDADD = \
+  $(top_builddir)/src/applications/identity/libgnunetidentity_api.la \
+  $(top_builddir)/src/applications/testing/libgnunettesting_api.la \
+  $(top_builddir)/src/applications/stats/libgnunetstats_api.la \
+  $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
+  $(top_builddir)/src/util/config_impl/libgnunetutil_config.la  \
+  $(top_builddir)/src/util/crypto/libgnunetutil_crypto.la  \
+  $(top_builddir)/src/util/network_client/libgnunetutil_network_client.la  \
+  $(top_builddir)/src/util/libgnunetutil.la 
+
+
 EXTRA_DIST = \
   check.conf

Modified: GNUnet/src/applications/gap/gaptest.c
===================================================================
--- GNUnet/src/applications/gap/gaptest.c       2007-05-31 03:55:56 UTC (rev 
4874)
+++ GNUnet/src/applications/gap/gaptest.c       2007-05-31 04:35:55 UTC (rev 
4875)
@@ -283,7 +283,7 @@
   GC_set_configuration_value_string(cfg,
                                    ectx,
                                    "NETWORK",
-                                   "HOSTNAME",
+                                   "HOST",
                                    "localhost:12087");
   CHECK(OK == searchFile(&uri));
   CHECK(OK == downloadFile(12345, uri));
@@ -291,7 +291,7 @@
   GC_set_configuration_value_string(cfg,
                                    ectx,
                                    "NETWORK",
-                                   "HOSTNAME",
+                                   "HOST",
                                    "localhost:2087");
   CHECK(OK == unindexFile(12345));
 

Modified: GNUnet/src/applications/gap/gaptest2.c
===================================================================
--- GNUnet/src/applications/gap/gaptest2.c      2007-05-31 03:55:56 UTC (rev 
4874)
+++ GNUnet/src/applications/gap/gaptest2.c      2007-05-31 04:35:55 UTC (rev 
4875)
@@ -19,7 +19,7 @@
 */
 
 /**
- * @file applications/gap/gaptest.c
+ * @file applications/gap/gaptest2.c
  * @brief GAP routing testcase
  * @author Christian Grothoff
  */
@@ -79,7 +79,7 @@
                        cfg,
                        name,
                        YES, /* index */
-                       0, /* anon */
+                       1, /* anon */
                        0, /* prio */
                        get_time() + 10 * cronMINUTES, /* expire */
                        NULL, /* progress */
@@ -149,7 +149,7 @@
   ret = ECRS_search(ectx,
                    cfg,
                    *uri,
-                   0,
+                   1,
                    15 * cronSECONDS,
                    &searchCB,
                    &myURI,
@@ -186,7 +186,7 @@
                              cfg,
                              uri,
                              tmpName,
-                             0,
+                             1,
                              NULL,
                              NULL,
                              &testTerminate,
@@ -258,7 +258,7 @@
 #if START_PEERS
   peers = gnunet_testing_start_daemons("tcp",
                                       "advertising topology fs stats",
-                                      "/tmp/gnunet-gap-test",
+                                      "/tmp/gnunet-gap-test2",
                                       2087,
                                       5000,
                                       8);
@@ -293,7 +293,7 @@
   GC_set_configuration_value_string(cfg,
                                    ectx,
                                    "NETWORK",
-                                   "HOSTNAME",
+                                   "HOST",
                                    "localhost:32087");
   CHECK(OK == searchFile(&uri));
   CHECK(OK == downloadFile(12345, uri));
@@ -301,7 +301,7 @@
   GC_set_configuration_value_string(cfg,
                                    ectx,
                                    "NETWORK",
-                                   "HOSTNAME",
+                                   "HOST",
                                    "localhost:2087");
   CHECK(OK == unindexFile(12345));
 

Added: GNUnet/src/applications/gap/gaptest3.c
===================================================================
--- GNUnet/src/applications/gap/gaptest3.c                              (rev 0)
+++ GNUnet/src/applications/gap/gaptest3.c      2007-05-31 04:35:55 UTC (rev 
4875)
@@ -0,0 +1,302 @@
+/*
+     This file is part of GNUnet.
+     (C) 2005, 2006, 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., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file applications/gap/gaptest3.c
+ * @brief GAP economy testcase
+ * @author Christian Grothoff
+ */
+
+#include "platform.h"
+#include "gnunet_protocols.h"
+#include "gnunet_ecrs_lib.h"
+#include "gnunet_testing_lib.h"
+#include "gnunet_identity_lib.h"
+#include "gnunet_stats_lib.h"
+#include "gnunet_util_crypto.h"
+#include "gnunet_util_config_impl.h"
+#include "gnunet_util_network_client.h"
+#include "gnunet_stats_lib.h"
+
+
+
+#define PEER_COUNT 10
+
+#define START_PEERS 1
+
+#define SIZE 1024*1024*100
+
+static struct GE_Context * ectx;
+
+static struct GC_Configuration * cfg;
+
+static int testTerminate(void * unused) {
+  return OK;
+}
+
+static char * makeName(unsigned int i) {
+  char * fn;
+
+  fn = MALLOC(strlen("/tmp/gnunet-gaptest/GAPTEST") + 14);
+  SNPRINTF(fn,
+          strlen("/tmp/gnunet-gaptest/GAPTEST") + 14,
+          "/tmp/gnunet-gaptest/GAPTEST%u",
+          i);
+  disk_directory_create_for_file(NULL, fn);
+  return fn;
+}
+
+static struct ECRS_URI * uploadFile(unsigned int size) {
+  int ret;
+  char * name;
+  int fd;
+  char * buf;
+  struct ECRS_URI * uri;
+  int i;
+
+  name = makeName(size);
+  fd = disk_file_open(ectx,
+                     name,
+                     O_WRONLY|O_CREAT, S_IWUSR|S_IRUSR);
+  buf = MALLOC_LARGE(size);
+  memset(buf, size + size / 253, size);
+  for (i=0;i<(int) (size - 42 - sizeof(HashCode512));i+=sizeof(HashCode512))
+    hash(&buf[i+sizeof(HashCode512)],
+        42,
+        (HashCode512*) &buf[i]);
+  WRITE(fd, buf, size);
+  FREE(buf);
+  disk_file_close(ectx, name, fd);
+  ret = ECRS_uploadFile(ectx,
+                       cfg,
+                       name,
+                       YES, /* index */
+                       1, /* anon */
+                       0, /* prio */
+                       get_time() + 10 * cronMINUTES, /* expire */
+                       NULL, /* progress */
+                       NULL,
+                       &testTerminate,
+                       NULL,
+                       &uri);  
+  FREE(name);
+  if (ret != SYSERR) 
+    return uri;
+  return NULL;  
+}
+
+static int downloadFile(unsigned int size,
+                       const struct ECRS_URI * uri) {
+  int ret;
+  char * tmpName;
+  int fd;
+  char * buf;
+  char * in;
+  int i;
+  char * tmp;
+
+  tmp = ECRS_uriToString(uri);
+  GE_LOG(ectx,
+        GE_DEBUG | GE_REQUEST | GE_USER,
+        "Starting download of `%s'\n",
+        tmp);
+  FREE(tmp);
+  tmpName = makeName(0);
+  ret = SYSERR;
+  if (OK == ECRS_downloadFile(ectx,
+                             cfg,
+                             uri,
+                             tmpName,
+                             1,
+                             NULL,
+                             NULL,
+                             &testTerminate,
+                             NULL)) {
+
+    fd = disk_file_open(ectx,
+                       tmpName,
+                       O_RDONLY);
+    buf = MALLOC(size);
+    in = MALLOC(size);
+    memset(buf, size + size / 253, size);
+    for (i=0;i<(int) (size - 42 - sizeof(HashCode512));i+=sizeof(HashCode512))
+      hash(&buf[i+sizeof(HashCode512)],
+          42,
+          (HashCode512*) &buf[i]);
+    if (size != READ(fd, in, size))
+      ret = SYSERR;
+    else if (0 == memcmp(buf,
+                        in,
+                        size))
+      ret = OK;
+    FREE(buf);
+    FREE(in);
+    disk_file_close(ectx, tmpName, fd);
+  }
+  UNLINK(tmpName);
+  FREE(tmpName);
+  return ret;
+}
+
+#define CHECK(a) if (!(a)) { ret = 1; GE_BREAK(ectx, 0); goto FAILURE; }
+
+static PeerIdentity goodPeers[PEER_COUNT];
+static unsigned int goodPeerPos;
+
+static int infoCallback(void * data,
+                       const PeerIdentity * identity,
+                       const char * address,
+                       unsigned int trust,
+                       unsigned int bpmFromPeer) {
+  int i;
+  int good;
+  EncName enc;
+  
+  good = 0;
+  for (i=0;i<goodPeerPos;i++)
+    if (0 == memcmp(&goodPeers[i],
+                   identity,
+                   sizeof(PeerIdentity)))
+      good = 1;
+  hash2enc(&identity->hashPubKey,
+          &enc);
+  if (good) 
+    printf("Good peer `%s' has trust %u and bandwidth %u\n", 
+          (const char*) &enc,
+          trust,
+          bpmFromPeer);
+  else
+    printf("Poor peer `%s' has trust %u and bandwidth %u\n",
+          (const char*) &enc,
+          trust,
+          bpmFromPeer);
+  return OK;
+}
+
+/**
+ * Testcase to test gap routing (2 peers only).
+ * @return 0: ok, -1: error
+ */
+int main(int argc, char ** argv) {
+  struct DaemonContext * peers;
+  int ret;
+  struct ECRS_URI * uri;
+  int i;
+  char buf[128];
+  P2P_hello_MESSAGE * hello;
+  struct ClientServerConnection * sock;
+  cron_t start;
+  EncName enc;
+ 
+  ret = 0;
+  cfg = GC_create_C_impl();
+  if (-1 == GC_parse_configuration(cfg,
+                                  "check.conf")) {
+    GC_free(cfg);
+    return -1;
+  }
+#if START_PEERS
+  peers = gnunet_testing_start_daemons("tcp",
+                                      "advertising topology fs stats",
+                                      "/tmp/gnunet-gap-test3",
+                                      2087,
+                                      10,
+                                      PEER_COUNT);
+  if (peers == NULL) {
+    fprintf(stderr,
+           "Failed to start the gnunetd daemons!\n");
+    GC_free(cfg);
+    return -1;
+  }
+#endif
+  /* connect as star-topology */
+  for (i=1;i<PEER_COUNT;i++) {
+    if (OK != gnunet_testing_connect_daemons(2087,
+                                            2087 + 10*i)) {
+      gnunet_testing_stop_daemons(peers);
+      fprintf(stderr,
+             "Failed to connect the peers!\n");
+      GC_free(cfg);
+      return -1;
+    }
+  }
+
+  uri = NULL;
+  goodPeerPos = 0;
+  for (i=1;i<PEER_COUNT;i+=2) {
+    SNPRINTF(buf,
+            128,
+            "localhost:%u",
+            2087 + i * 10);   
+    GC_set_configuration_value_string(cfg,
+                                     ectx,
+                                     "NETWORK",
+                                     "HOST",
+                                     buf);
+    sock = client_connection_create(NULL,
+                                   cfg);
+    if (OK != gnunet_identity_get_self(sock,
+                                      &hello)) {
+      connection_destroy(sock);
+      GE_BREAK(NULL, 0);
+      break;
+    }
+    connection_destroy(sock);
+    if (uri != NULL)
+      ECRS_freeUri(uri);
+    hash2enc(&hello->senderIdentity.hashPubKey,
+            &enc);
+    printf("Uploading to peer `%s'\n", 
+          (const char*)&enc);
+    uri = uploadFile(SIZE);
+    CHECK(NULL != uri);
+
+    goodPeers[goodPeerPos++] = hello->senderIdentity;
+    FREE(hello);
+
+  }
+  GC_set_configuration_value_string(cfg,
+                                   ectx,
+                                   "NETWORK",
+                                   "HOST",
+                                   "localhost:2087");
+  printf("Downloading...\n");
+  start = get_time();
+  CHECK(OK == downloadFile(SIZE, uri));
+  printf("Download complete - %f kbps.\n",
+        SIZE/1024 * 1.0 * cronSECONDS / (1 + get_time() - start));
+  /* verify trust values have developed as expected */
+
+  sock = client_connection_create(NULL,
+                                 cfg);
+  gnunet_identity_request_peer_infos(sock,
+                                    &infoCallback,
+                                    NULL);
+  connection_destroy(sock);
+
+ FAILURE:
+#if START_PEERS
+  gnunet_testing_stop_daemons(peers);
+#endif
+  GC_free(cfg);
+  return ret;
+}
+
+/* end of gaptest3.c */


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

Added: GNUnet/src/applications/testing/README
===================================================================
--- GNUnet/src/applications/testing/README                              (rev 0)
+++ GNUnet/src/applications/testing/README      2007-05-31 04:35:55 UTC (rev 
4875)
@@ -0,0 +1,5 @@
+This is really just a helper library.
+
+It could equally well live in util/,
+but since it is only used for testing
+of application's, it is here for now.
\ No newline at end of file

Modified: GNUnet/src/include/gnunet_ecrs_lib.h
===================================================================
--- GNUnet/src/include/gnunet_ecrs_lib.h        2007-05-31 03:55:56 UTC (rev 
4874)
+++ GNUnet/src/include/gnunet_ecrs_lib.h        2007-05-31 04:35:55 UTC (rev 
4875)
@@ -307,14 +307,6 @@
                        PeerIdentity * peer);
 
 /**
- * (re)construct the HELLO message of the peer offerin the data
- *
- * @return NULL if this is not a location URI
- */
-P2P_hello_MESSAGE *
-ECRS_getHelloFromUri(const struct ECRS_URI * uri);
-
-/**
  * Obtain the URI of the content itself.
  *
  * @return NULL if argument is not a location URI
@@ -346,7 +338,8 @@
  */
 struct ECRS_URI *
 ECRS_uriFromLocation(const struct ECRS_URI * baseUri,
-                    const P2P_hello_MESSAGE * hello,
+                    const PublicKey * peer,
+                    TIME_T expirationTime,
                     ECRS_SignFunction signer,
                     void * signer_cls);
 
@@ -463,7 +456,8 @@
  * in the meta-data and construct one large keyword URI
  * that lists all keywords that can be found in the meta-data).
  */
-struct ECRS_URI * ECRS_metaDataToUri(const struct ECRS_MetaData * md);
+struct ECRS_URI * 
+ECRS_metaDataToUri(const struct ECRS_MetaData * md);
 
 
 typedef struct {





reply via email to

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