gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r4079 - in GNUnet: . src/applications/fs/ecrs src/include


From: grothoff
Subject: [GNUnet-SVN] r4079 - in GNUnet: . src/applications/fs/ecrs src/include
Date: Wed, 27 Dec 2006 10:55:19 -0800 (PST)

Author: grothoff
Date: 2006-12-27 10:55:14 -0800 (Wed, 27 Dec 2006)
New Revision: 4079

Modified:
   GNUnet/configure.ac
   GNUnet/src/applications/fs/ecrs/ecrs.h
   GNUnet/src/applications/fs/ecrs/uri.c
   GNUnet/src/include/gnunet_ecrs_lib.h
   GNUnet/todo
Log:
towards location URIs

Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2006-12-27 17:56:05 UTC (rev 4078)
+++ GNUnet/configure.ac 2006-12-27 18:55:14 UTC (rev 4079)
@@ -583,6 +583,7 @@
 src/setup/text/Makefile
 src/server/Makefile
 src/transports/Makefile
+src/transports/upnp/Makefile
 src/util/Makefile
 src/util/boot/Makefile
 src/util/config/Makefile

Modified: GNUnet/src/applications/fs/ecrs/ecrs.h
===================================================================
--- GNUnet/src/applications/fs/ecrs/ecrs.h      2006-12-27 17:56:05 UTC (rev 
4078)
+++ GNUnet/src/applications/fs/ecrs/ecrs.h      2006-12-27 18:55:14 UTC (rev 
4079)
@@ -46,11 +46,58 @@
 #define BLOCK_ALIGN_SIZE (DBLOCK_SIZE)
 
 typedef struct Location {
-  PeerIdentity peer;
-  HashCode512 query;
-  HashCode512 key;
-  unsigned int type;
-  unsigned long long size;
+  /**
+   * Information about the shared file.
+   */
+  FileIdentifier chk;
+
+  /**
+   * Public key of the peer sharing the file.
+   */
+  PublicKey peer;
+
+  /**
+   * Time when the HELLO *and* this location URI
+   * expire (they expire together!).
+   */
+  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).  
+   */
+  Signature contentSignature;
+
 } Location;
 
 enum uri_types { chk, sks, ksk, loc };

Modified: GNUnet/src/applications/fs/ecrs/uri.c
===================================================================
--- GNUnet/src/applications/fs/ecrs/uri.c       2006-12-27 17:56:05 UTC (rev 
4078)
+++ GNUnet/src/applications/fs/ecrs/uri.c       2006-12-27 18:55:14 UTC (rev 
4079)
@@ -67,22 +67,24 @@
  * </li><li>
  *
  * The last category identifies a datum on a specific machine.  The
- * format is "gnunet://ecrs/loc/PEER/QUERY.TYPE.KEY.SIZE".  MACHINE is
- * the EncName of the peer storing the datum, TYPE is the (block) type
- * of the datum and SIZE is the number of bytes.  KEY is used to decrypt
- * the data whereas QUERY is the request that should be transmitted to
- * the PEER.
+ * format is "gnunet://ecrs/loc/PEER/INFO/HEX1.HEX2.SIZE".  PEER is
+ * the EncName of the peer storing the datum, INFO contains HELLO
+ * information about peer and signatures for the URI content and the
+ * HELLO itself; HEX1, HEX2 and SIZE correspond to a 'chk' URI.
  *
  * </li></ul>
  *
  * The encoding for hexadecimal values is defined in the hashing.c
  * module (EncName) in the gnunet-util library and discussed there.
  * <p>
- *
+ * 
+ * TODO:
+ * - conversion of LOC URIs from and to strings!
  */
 
 #include "platform.h"
 #include "ecrs.h"
+#include "gnunet_protocols.h"
 #include "gnunet_ecrs_lib.h"
 
 /**
@@ -403,7 +405,8 @@
         uri->data.ksk.keywordCount,
         0);
   }
-
+  if (uri->type == loc)
+    FREENONNULL(uri->data.loc.address);
   FREE(uri);
 }
 
@@ -483,8 +486,7 @@
 unsigned int ECRS_countKeywordsOfUri(const struct ECRS_URI * uri) {
   if (uri->type != ksk)
     return 0;
-  else
-    return uri->data.ksk.keywordCount;
+  return uri->data.ksk.keywordCount;
 }
 
 /**
@@ -533,7 +535,7 @@
   case chk:
     return ntohll(uri->data.chk.file_length);
   case loc:
-    return ntohll(uri->data.loc.size);
+    return ntohll(uri->data.loc.chk.file_length);
   default:
     GE_ASSERT(NULL, 0);
   }
@@ -722,8 +724,7 @@
                    &uri2->data.chk,
                    sizeof(FileIdentifier)))
       return YES;
-    else
-      return NO;
+    return NO;
   case sks:
     if (equalsHashCode512(&uri1->data.sks.namespace,
                          &uri2->data.sks.namespace) &&
@@ -731,8 +732,7 @@
                          &uri2->data.sks.identifier) )
        
       return YES;
-    else
-      return NO;
+    return NO;
   case ksk:
     if (uri1->data.ksk.keywordCount !=
        uri2->data.ksk.keywordCount)
@@ -750,10 +750,147 @@
        return NO;                      
     }
     return YES;
+  case loc:
+    if (memcmp(&uri1->data.loc,
+              &uri2->data.loc,
+              sizeof(FileIdentifier) +
+              sizeof(PublicKey) + 
+              sizeof(TIME_T) +
+              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;
   }
 }
 
+/**
+ * Obtain the identity of the peer offering the data
+ * @return -1 if this is not a location URI, otherwise OK
+ */
+int ECRS_getPeerFromUri(const struct ECRS_URI * uri,
+                       PeerIdentity * peer) {
+  if (uri->type != loc)
+    return -1;
+  hash(&uri->data.loc.peer,
+       sizeof(PublicKey),
+       &peer->hashPubKey);
+  return OK;
+}
 
+/**
+ * (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) {
+  P2P_hello_MESSAGE * hello;
+
+  if (uri->type != loc)
+    return NULL;
+  hello = MALLOC(sizeof(P2P_hello_MESSAGE) + uri->data.loc.sas);
+  hello->header.size = htons(sizeof(P2P_hello_MESSAGE) + uri->data.loc.sas);
+  hello->header.type = htons(p2p_PROTO_hello);
+  hello->MTU = htonl(uri->data.loc.mtu);
+  hello->senderAddressSize = htons(uri->data.loc.sas);
+  hello->protocol = htons(uri->data.loc.proto);
+  hello->expirationTime = htonl(uri->data.loc.expirationTime);
+  hello->publicKey = uri->data.loc.peer;
+  hash(&hello->publicKey,
+       sizeof(PublicKey),
+       &hello->senderIdentity.hashPubKey);
+  hello->signature = uri->data.loc.helloSignature;
+  memcpy(&hello[1],
+        uri->data.loc.address,
+        uri->data.loc.sas);
+  return hello;
+}
+
+/**
+ * Obtain the URI of the content itself.
+ *
+ * @return NULL if argument is not a location URI
+ */
+struct ECRS_URI *
+ECRS_getContentUri(const struct ECRS_URI * uri) {
+  struct ECRS_URI * ret;
+
+  if (uri->type != loc)
+    return NULL;
+   ret = MALLOC(sizeof(struct ECRS_URI));
+  ret->type = chk;
+  ret->data.chk = uri->data.loc.chk;
+  return ret;
+}
+
+/**
+ * Construct a location URI.
+ *
+ * @param baseURI content offered by the sender
+ * @param sender identity of the peer with the content
+ * @param expirationTime how long will the content be offered?
+ * @param proto transport protocol to reach the peer
+ * @param sas sender address size (for HELLO)
+ * @param address sas bytes of address information
+ * @param signer function to call for obtaining 
+ *        RSA signatures for "sender".
+ * @return the location URI
+ */
+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,
+                    char * address,
+                    ECRS_SignFunction signer) {
+  struct ECRS_URI * uri;
+  P2P_hello_MESSAGE * hello;
+  
+
+  if (baseUri->type != chk)
+    return NULL;
+
+  uri = MALLOC(sizeof(struct ECRS_URI));
+  uri->data.loc.chk = baseUri->data.chk;
+  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);
+  signer(&hello->senderIdentity,
+        P2P_hello_MESSAGE_size(hello)
+        - sizeof(Signature)
+        - sizeof(PublicKey)
+        - sizeof(MESSAGE_HEADER), 
+        &uri->data.loc.helloSignature);
+  signer(&uri->data.loc.chk,
+        sizeof(FileIdentifier) + 
+        sizeof(PublicKey) +
+        sizeof(TIME_T),
+        &uri->data.loc.contentSignature);
+  return uri;
+}
+
+
 /* end of uri.c */

Modified: GNUnet/src/include/gnunet_ecrs_lib.h
===================================================================
--- GNUnet/src/include/gnunet_ecrs_lib.h        2006-12-27 17:56:05 UTC (rev 
4078)
+++ GNUnet/src/include/gnunet_ecrs_lib.h        2006-12-27 18:55:14 UTC (rev 
4079)
@@ -28,6 +28,7 @@
 #define GNUNET_ECRS_LIB_H
 
 #include "gnunet_util.h"
+#include "gnunet_core.h"
 #include <extractor.h>
 
 #ifdef __cplusplus
@@ -50,9 +51,10 @@
  * 3.2.x: with collections
  * 4.0.x: with expiration, variable meta-data, kblocks
  * 4.1.x: with new error and configuration handling
- * 5.x.x: who knows? :-)
+ * 5.0.x: with location URIs
+ * 6.x.x: who knows? :-)
  */
-#define AFS_VERSION "4.1.1"
+#define AFS_VERSION "5.0.0"
 
 #define GNUNET_DIRECTORY_MIME  "application/gnunet-directory"
 #define GNUNET_DIRECTORY_MAGIC "\211GND\r\n\032\n"
@@ -296,6 +298,61 @@
                            void * cls);
 
 /**
+ * Obtain the identity of the peer offering the data
+ * @return -1 if this is not a location URI, otherwise OK
+ */
+int ECRS_getPeerFromUri(const struct ECRS_URI * uri,
+                       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
+ */
+struct ECRS_URI *
+ECRS_getContentUri(const struct ECRS_URI * uri);
+
+/**
+ * Function that produces a signature for
+ * a particular piece of content.
+ */
+typedef int (*ECRS_SignFunction)(const void * data,
+                                unsigned short size,
+                                Signature * result);
+
+/**
+ * Construct a location URI.
+ *
+ * @param baseURI content offered by the sender
+ * @param sender identity of the peer with the content
+ * @param expirationTime how long will the content be offered?
+ * @param proto transport protocol to reach the peer
+ * @param sas sender address size (for HELLO)
+ * @param address sas bytes of address information
+ * @param signer function to call for obtaining 
+ *        RSA signatures for "sender".
+ * @return the location URI
+ */
+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,
+                    char * address,
+                    ECRS_SignFunction signer);
+
+
+/**
  * Duplicate URI.
  */
 struct ECRS_URI * ECRS_dupUri(const struct ECRS_URI * uri);
@@ -345,7 +402,6 @@
                         unsigned int num_keywords,
                         const char ** keywords);
 
-
 /**
  * Test if two URIs are equal.
  */
@@ -396,10 +452,12 @@
 unsigned long long ECRS_fileSize(const struct ECRS_URI * uri);
 
 /**
- * Is this a location URI? (DHT specific!)
+ * Is this a location URI?
  */
 int ECRS_isLocationUri(const struct ECRS_URI * uri);
 
+
+
 /**
  * Construct a keyword-URI from meta-data (take all entries
  * in the meta-data and construct one large keyword URI

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2006-12-27 17:56:05 UTC (rev 4078)
+++ GNUnet/todo 2006-12-27 18:55:14 UTC (rev 4079)
@@ -32,8 +32,8 @@
 - new features:
   * XFS / support for location URIs [CG] 
     + dht/routing: handle routing loops [RC]
+    + ECRS-URI: toString/fromString for loc URIs [RC]
     + dht/gap integration [RC]
-    + ecrs/location URIs [RC]
     + fsui/location URI support [RC]
     + dht/routing: GET retries (optimization)
     + dstore bloomfilter (optimization)
@@ -61,7 +61,9 @@
 - insert meta-data under hash (md5? sha1? sha-512? GNUnet-URI?)
   as keyword (to allow getting meta-data from URI only)
 - Chat support basics [RC]
-- better NAT traversal (STUN/STUNT inspired?)
+- better NAT traversal:
+  * UPnP
+  * NAT-PMP
 - old/new features:
   * SMTP transport (libesmtp)
   * SMTP logger





reply via email to

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