gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r4803 - in GNUnet: . src/applications src/applications/fs/f


From: gnunet
Subject: [GNUnet-SVN] r4803 - in GNUnet: . src/applications src/applications/fs/fsui src/applications/identity src/include src/server src/util/error
Date: Sat, 26 May 2007 22:43:23 -0600 (MDT)

Author: grothoff
Date: 2007-05-26 22:43:23 -0600 (Sat, 26 May 2007)
New Revision: 4803

Modified:
   GNUnet/src/applications/Makefile.am
   GNUnet/src/applications/fs/fsui/Makefile.am
   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/gnunet_identity_lib.h
   GNUnet/src/include/gnunet_protocols.h
   GNUnet/src/include/gnunet_transport_service.h
   GNUnet/src/server/tcpserver.c
   GNUnet/src/util/error/error.c
   GNUnet/todo
Log:
finished first run of hacking up XFS support -- still needs to be actually 
tested

Modified: GNUnet/src/applications/Makefile.am
===================================================================
--- GNUnet/src/applications/Makefile.am 2007-05-27 02:00:56 UTC (rev 4802)
+++ GNUnet/src/applications/Makefile.am 2007-05-27 04:43:23 UTC (rev 4803)
@@ -21,11 +21,11 @@
  rpc \
  fragmentation \
  getoption \
+ identity \
  fs \
  state \
  stats \
  gap \
- identity \
  pingpong \
  session \
  $(MYSQL_DIR) \

Modified: GNUnet/src/applications/fs/fsui/Makefile.am
===================================================================
--- GNUnet/src/applications/fs/fsui/Makefile.am 2007-05-27 02:00:56 UTC (rev 
4802)
+++ GNUnet/src/applications/fs/fsui/Makefile.am 2007-05-27 04:43:23 UTC (rev 
4803)
@@ -15,6 +15,7 @@
   upload.c
 libgnunetfsui_la_LIBADD = \
  -lextractor \
+ $(top_builddir)/src/applications/identity/libgnunetidentity_api.la \
  $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
  $(top_builddir)/src/applications/fs/namespace/libgnunetnamespace.la \
  $(top_builddir)/src/applications/fs/uritrack/libgnuneturitrack.la \

Modified: GNUnet/src/applications/fs/fsui/upload.c
===================================================================
--- GNUnet/src/applications/fs/fsui/upload.c    2007-05-27 02:00:56 UTC (rev 
4802)
+++ GNUnet/src/applications/fs/fsui/upload.c    2007-05-27 04:43:23 UTC (rev 
4803)
@@ -27,9 +27,11 @@
 
 #include "platform.h"
 #include "gnunet_util_error_loggers.h"
+#include "gnunet_util_network_client.h"
 #include "gnunet_ecrs_lib.h"
 #include "gnunet_uritrack_lib.h"
 #include "gnunet_fsui_lib.h"
+#include "gnunet_identity_lib.h"
 #include "fsui.h"
 #include <extractor.h>
 
@@ -253,11 +255,13 @@
   char * filename;
   char * pfn;
   struct ECRS_URI * uri;
+  struct ECRS_URI * loc;
   size_t tpos;
   char * error;
   struct GE_Memory * mem;
   struct GE_Context * ee;
 
+
   ectx = utc->shared->ctx->ectx;
   GE_ASSERT(ectx, utc->filename != NULL);
   cpos = utc->child;
@@ -357,15 +361,59 @@
                     EXTRACTOR_FILENAME,
                     pfn);
   FREE(pfn);
-  if (utc->shared->global_keywords != NULL)
+  if ( (utc->shared->anonymityLevel == 0) &&
+       (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;
+    
+    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)) {
+      loc = ECRS_uriFromLocation(utc->uri,
+                                &my_publicKey,
+                                expirationTime,
+                                proto,
+                                sas,
+                                mtu,
+                                address,
+                                (ECRS_SignFunction) 
&gnunet_identity_sign_function,
+                                sock);
+      if ( (sas > 0) &&
+          (address != NULL) )
+       FREE(address);
+    } else {
+      GE_BREAK(ectx, 0);
+      loc = ECRS_dupUri(utc->uri);
+    }
+    connection_destroy(sock);
+  } else {
+    /* no location URI, use standard URI 
+       (copied here to allow free later) */
+    loc = ECRS_dupUri(utc->uri);
+  }
+  if (utc->shared->global_keywords != NULL) 
     ECRS_addToKeyspace(ectx,
                       utc->shared->ctx->cfg,
                       utc->shared->global_keywords,
                       utc->shared->anonymityLevel,
                       utc->shared->priority,
                       utc->shared->expiration,
-                      utc->uri,
-                      utc->meta);      
+                      loc,
+                      utc->meta);        
   if (utc->keywords != NULL)
     ECRS_addToKeyspace(ectx,
                       utc->shared->ctx->cfg,
@@ -373,7 +421,7 @@
                       utc->shared->anonymityLevel,
                       utc->shared->priority,
                       utc->shared->expiration,
-                      utc->uri,
+                      loc,
                       utc->meta);      
   if (utc->shared->individualKeywords == YES) {
     uri = ECRS_metaDataToUri(utc->meta);
@@ -383,10 +431,12 @@
                       utc->shared->anonymityLevel,
                       utc->shared->priority,
                       utc->shared->expiration,
-                      utc->uri,
+                      loc,
                       utc->meta);      
     ECRS_freeUri(uri);
   }
+  ECRS_freeUri(loc);   
+  loc = NULL;
   while (OK == ECRS_delFromMetaData(utc->meta,
                                    EXTRACTOR_SPLIT,
                                    NULL)) ;

Modified: GNUnet/src/applications/identity/clientapi.c
===================================================================
--- GNUnet/src/applications/identity/clientapi.c        2007-05-27 02:00:56 UTC 
(rev 4802)
+++ GNUnet/src/applications/identity/clientapi.c        2007-05-27 04:43:23 UTC 
(rev 4803)
@@ -46,23 +46,23 @@
   CS_identity_hello_MESSAGE * msg;
 
   msg = MALLOC(sizeof(CS_identity_hello_MESSAGE) + sas);
-  msg->header.type = htons(CS_PROTO_identity_HELLO);
-  msg->header.size = htons(sizeof(CS_identity_hello_MESSAGE) + sas);
-  msg->signature = *signature;
-  msg->publicKey = *key;
+  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->senderIdentity.hashPubKey);
-  msg->expirationTime = expirationTime;
-  msg->MTU = mtu;
-  msg->senderAddressSize = sas;
-  msg->protocol = proto;
+       &msg->m.senderIdentity.hashPubKey);
+  msg->m.expirationTime = expirationTime;
+  msg->m.MTU = mtu;
+  msg->m.senderAddressSize = sas;
+  msg->m.protocol = proto;
   memcpy(&msg[1],
         address,
         sas);
   /* FIXME: check that signature is valid! */
   if (SYSERR == connection_write(sock,
-                                &msg->header)) {
+                                &msg->m.header)) {
     FREE(msg);
     return SYSERR;
   }
@@ -71,4 +71,93 @@
 }
 
 
+/**
+ * Function to request the peer to sign something
+ * with the private key of the peer.
+ */
+int gnunet_identity_sign_function(struct ClientServerConnection * sock,
+                                 unsigned short size,
+                                 const void * data,
+                                 Signature * result) {
+  MESSAGE_HEADER * req;
+  CS_identity_signature_MESSAGE * reply;
+  
+  req = MALLOC(sizeof(MESSAGE_HEADER) + size);
+  req->size = htons(sizeof(MESSAGE_HEADER) + size);
+  req->type = htons(CS_PROTO_identity_request_SIGN);
+  memcpy(&req[1],
+        data,
+        size);
+  if (SYSERR == connection_write(sock,
+                                req)) {
+    FREE(req);
+    return SYSERR;
+  }
+  FREE(req);
+  if (OK != connection_read(sock,
+                           (MESSAGE_HEADER**)&reply)) {
+    connection_close_temporarily(sock);
+    return SYSERR;
+  }
+  if ( (ntohs(reply->header.size) != sizeof(CS_identity_signature_MESSAGE)) ||
+       (ntohs(reply->header.type) != CS_PROTO_identity_SIGNATURE) ) {
+    FREE(reply);
+    return SYSERR;
+  }
+  *result = reply->sig;
+  FREE(reply);
+  return OK;
+}
+
+/**
+ * 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) {
+  MESSAGE_HEADER req;
+  CS_identity_hello_MESSAGE * reply;
+
+  req.size = htons(sizeof(MESSAGE_HEADER));
+  req.type = htons(CS_PROTO_identity_request_HELLO);
+  if (SYSERR == connection_write(sock,
+                                &req)) 
+    return SYSERR;  
+  if (OK != connection_read(sock,
+                           (MESSAGE_HEADER**)&reply)) {
+    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)) ) {
+    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);
+  return OK;
+}
+
+
+
+
 /* end of clientapi.c */

Modified: GNUnet/src/applications/identity/identity.c
===================================================================
--- GNUnet/src/applications/identity/identity.c 2007-05-27 02:00:56 UTC (rev 
4802)
+++ GNUnet/src/applications/identity/identity.c 2007-05-27 04:43:23 UTC (rev 
4803)
@@ -36,6 +36,7 @@
 #include "gnunet_protocols.h"
 #include "gnunet_directories.h"
 #include "gnunet_identity_service.h"
+#include "gnunet_transport_service.h"
 #include "identity.h"
 #include "hostkey.h"
 
@@ -1107,20 +1108,85 @@
 
   if (sizeof(CS_identity_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->header.size));
-  memcpy(hello, msg, ntohs(msg->header.size));
+  hello = MALLOC(ntohs(msg->m.header.size));
+  memcpy(hello, msg, ntohs(msg->m.header.size));
   hello->header.type = htons(p2p_PROTO_hello);
   coreAPI->injectMessage(NULL,
                         (const char*) hello,
-                        ntohs(msg->header.size),
+                        ntohs(msg->m.header.size),
                         NO,
                         NULL);
   FREE(hello);
   return OK;
 }
 
+static int identityRequestHelloHandler(struct ClientHandle * sock,
+                                      const MESSAGE_HEADER * message) {
+  /* transport types in order of preference
+     for location URIs (by best guess at what
+     people are most likely to actually run) */
+  static unsigned short types[] = { 
+    TCP_PROTOCOL_NUMBER,
+    UDP_PROTOCOL_NUMBER,
+    HTTP_PROTOCOL_NUMBER,
+    TCP6_PROTOCOL_NUMBER,
+    UDP6_PROTOCOL_NUMBER,
+    SMTP_PROTOCOL_NUMBER,
+    NAT_PROTOCOL_NUMBER,
+    0,
+  };
+  Transport_ServiceAPI * tapi;
+  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;
+     however, we can request it briefly here */
+  tapi = coreAPI->requestService("transport");
+  if (tapi == NULL)
+    return SYSERR;
+  hello = NULL;
+  pos = 0;
+  while ( (hello == NULL) &&
+         (types[pos] != 0) ) 
+    hello = tapi->createhello(types[pos++]);
+  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);
+  ret = coreAPI->sendToClient(sock,
+                             &reply->m.header);
+  FREE(reply);
+  return ret;
+}
+
+static int identityRequestSignatureHandler(struct ClientHandle * sock,
+                                          const MESSAGE_HEADER * message) {
+  CS_identity_signature_MESSAGE reply;
+  
+  if (ntohs(message->size) <= sizeof(MESSAGE_HEADER))
+    return SYSERR;
+  reply.header.size = htons(sizeof(CS_identity_signature_MESSAGE));
+  reply.header.type = htons(CS_PROTO_identity_SIGNATURE);
+  if (OK != signData(&message[1],
+                    ntohs(message->size) - sizeof(MESSAGE_HEADER),
+                    &reply.sig))
+    return SYSERR;
+  return coreAPI->sendToClient(sock,
+                              &reply.header);
+}
+
+
 /**
  * Provide the Identity service.
  *
@@ -1214,6 +1280,10 @@
               NULL);
   coreAPI->registerClientHandler(CS_PROTO_identity_HELLO,
                                 &identityHelloHandler);
+  coreAPI->registerClientHandler(CS_PROTO_identity_request_HELLO,
+                                &identityRequestHelloHandler);
+  coreAPI->registerClientHandler(CS_PROTO_identity_request_SIGN,
+                                &identityRequestSignatureHandler);
   return &id;
 }
 
@@ -1227,6 +1297,10 @@
 
   coreAPI->unregisterClientHandler(CS_PROTO_identity_HELLO,
                                   &identityHelloHandler);
+  coreAPI->unregisterClientHandler(CS_PROTO_identity_request_HELLO,
+                                  &identityRequestHelloHandler);
+  coreAPI->unregisterClientHandler(CS_PROTO_identity_request_SIGN,
+                                  &identityRequestSignatureHandler);
   for (i=0;i<MAX_TEMP_HOSTS;i++) {
     entry = &tempHosts[i];
     for (j=0;j<entry->heloCount;j++)

Modified: GNUnet/src/applications/identity/identity.h
===================================================================
--- GNUnet/src/applications/identity/identity.h 2007-05-27 02:00:56 UTC (rev 
4802)
+++ GNUnet/src/applications/identity/identity.h 2007-05-27 04:43:23 UTC (rev 
4803)
@@ -24,57 +24,32 @@
 #ifndef IDENTITY_H
 #define IDENTITY_H
 
+#include "gnunet_core.h"
+
 /**
  * Format of the message to inform gnunetd about a 
- * HELLO from the client-side.  
- *
- * @see P2P_hello_MESSAGE!
+ * 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.
  */
 typedef struct {
-  MESSAGE_HEADER header;
 
-  /**
-   * The signature
-   */
-  Signature signature;
+  P2P_hello_MESSAGE m;
 
-  /**
-   * The public key
-   */
-  PublicKey publicKey;
+} CS_identity_hello_MESSAGE;
 
-  /**
-   * 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;
+/**
+ * Format of the signature response.
+ */
+typedef struct {
+  MESSAGE_HEADER header;
 
-  /**
-   * advertised MTU for sending (replies can have a different
-   * MTU!)
-   */
-  unsigned int MTU;
+  Signature sig;
+} CS_identity_signature_MESSAGE;
 
-  /**
-   * 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;
-
-
-} CS_identity_hello_MESSAGE;
-
-
 #endif

Modified: GNUnet/src/include/gnunet_identity_lib.h
===================================================================
--- GNUnet/src/include/gnunet_identity_lib.h    2007-05-27 02:00:56 UTC (rev 
4802)
+++ GNUnet/src/include/gnunet_identity_lib.h    2007-05-27 04:43:23 UTC (rev 
4803)
@@ -53,6 +53,32 @@
                             const char * address,
                             const Signature * signature);
 
+/**
+ * Function to request the peer to sign something
+ * with the private key of the peer.
+ */
+int gnunet_identity_sign_function(struct ClientServerConnection * sock,
+                                 unsigned short size,
+                                 const void * data,
+                                 Signature * result);
+
+/**
+ * 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);
+
+
+
 #if 0 /* keep Emacsens' auto-indent happy */
 {
 #endif

Modified: GNUnet/src/include/gnunet_protocols.h
===================================================================
--- GNUnet/src/include/gnunet_protocols.h       2007-05-27 02:00:56 UTC (rev 
4802)
+++ GNUnet/src/include/gnunet_protocols.h       2007-05-27 04:43:23 UTC (rev 
4803)
@@ -135,11 +135,6 @@
  */
 #define CS_PROTO_RETURN_ERROR 4
 
-/**
- * Client informs the Daemon about how to contact
- * a particular peer.
- */
-#define CS_PROTO_identity_HELLO 5
 
 /* ********** CS FS application messages ********** */
 
@@ -194,6 +189,32 @@
  */
 #define CS_PROTO_gap_INIT_INDEX 16
 
+
+/* *********** messages for identity module ************* */
+
+/**
+ * Client informs the Daemon about how to contact
+ * a particular peer -- or daemon informs client
+ * about how other peers should contact it.
+ */
+#define CS_PROTO_identity_HELLO 28
+
+/**
+ * Client asks the Daemon to sign a message.
+ */
+#define CS_PROTO_identity_SIGNATURE 29
+
+/**
+ * Client asks the Daemon about how to contact
+ * it.
+ */
+#define CS_PROTO_identity_request_HELLO 30
+
+/**
+ * Client asks the Daemon to sign a message.
+ */
+#define CS_PROTO_identity_request_SIGN 31
+
 /* *********** messages for traffic module ************* */
 
 /**

Modified: GNUnet/src/include/gnunet_transport_service.h
===================================================================
--- GNUnet/src/include/gnunet_transport_service.h       2007-05-27 02:00:56 UTC 
(rev 4802)
+++ GNUnet/src/include/gnunet_transport_service.h       2007-05-27 04:43:23 UTC 
(rev 4803)
@@ -184,7 +184,7 @@
    * @return the number of bytes written to buff, -1 on error
    */
   int (*getAdvertisedhellos)(unsigned int maxLen,
-                           char * buff);
+                            char * buff);
 
   /**
    * Test if the transport would even try to send

Modified: GNUnet/src/server/tcpserver.c
===================================================================
--- GNUnet/src/server/tcpserver.c       2007-05-27 02:00:56 UTC (rev 4802)
+++ GNUnet/src/server/tcpserver.c       2007-05-27 04:43:23 UTC (rev 4803)
@@ -334,7 +334,9 @@
                           NULL,
                           0 /* no memory quota */);
   if (selector == NULL) {
-    CLOSE(listenerFD);
+    CLOSE(listenerFD); /* maybe closed already
+                         depending on how select_create
+                         failed... */
     return SYSERR;
   }
   return OK;

Modified: GNUnet/src/util/error/error.c
===================================================================
--- GNUnet/src/util/error/error.c       2007-05-27 02:00:56 UTC (rev 4802)
+++ GNUnet/src/util/error/error.c       2007-05-27 04:43:23 UTC (rev 4803)
@@ -100,6 +100,8 @@
   size = VSNPRINTF(NULL, 0, message, va) + 1;
   va_end(va);
   buf = malloc(size);
+  if (buf == NULL)
+    return; /* oops */
   va_start(va, message);
   VSNPRINTF(buf, size, message, va);
   va_end(va);

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2007-05-27 02:00:56 UTC (rev 4802)
+++ GNUnet/todo 2007-05-27 04:43:23 UTC (rev 4803)
@@ -13,11 +13,7 @@
 
 0.7.2 [5'07]:
 - new features:
-  * XFS / support for location URIs [CG] 
-    + location URI generation (for search routing) [RC]
-      => ECRS needs to generate location URIs for *indexed* non-anonymous 
content!
-      - extend identity API to allow creation of (certain) signatures by 
clients!
-      - generate and publish location URI
+  * XFS / support for location URIs -- TEST!!! [CG] 
   * HTTP transport (libcurl, libmicrohttpd)
 - testcases (fix, add):
   * identity/clientapi.c: add (sanity) check for valid signature!





reply via email to

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