gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r4851 - in GNUnet/src: applications/advertising application


From: gnunet
Subject: [GNUnet-SVN] r4851 - in GNUnet/src: applications/advertising applications/identity include
Date: Mon, 28 May 2007 23:06:34 -0600 (MDT)

Author: grothoff
Date: 2007-05-28 23:06:34 -0600 (Mon, 28 May 2007)
New Revision: 4851

Modified:
   GNUnet/src/applications/advertising/advertising_test.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_util_core.h
Log:
extended identity API again for peer-info

Modified: GNUnet/src/applications/advertising/advertising_test.c
===================================================================
--- GNUnet/src/applications/advertising/advertising_test.c      2007-05-29 
04:24:49 UTC (rev 4850)
+++ GNUnet/src/applications/advertising/advertising_test.c      2007-05-29 
05:06:34 UTC (rev 4851)
@@ -33,7 +33,7 @@
 
 #define NUM_PEERS 12
 
-#define NUM_ROUNDS 30
+#define NUM_ROUNDS 3000
 
 static int countConnections(const char * name,
                            unsigned long long value,
@@ -90,11 +90,14 @@
                                             2087 + 10* ( (i+1) % NUM_PEERS))) {
       gnunet_testing_stop_daemons(peers);
       fprintf(stderr,
-             "Failed to connect the peers!\n");
+             "Failed to connect peers %d and %d!\n",
+             i,
+             (i+1) % NUM_PEERS);
       GC_free(cfg);
       return -1;    
     }
   }
+  PTHREAD_SLEEP(15 * cronSECONDS);
 
   /* check loops */
   for (k=0;k<NUM_ROUNDS;k++) {

Modified: GNUnet/src/applications/identity/clientapi.c
===================================================================
--- GNUnet/src/applications/identity/clientapi.c        2007-05-29 04:24:49 UTC 
(rev 4850)
+++ GNUnet/src/applications/identity/clientapi.c        2007-05-29 05:06:34 UTC 
(rev 4851)
@@ -165,5 +165,61 @@
   return result;
 }
 
+/**
+ * Request information about all known peers
+ *
+ * @return SYSERR if iteration was aborted, 
+ *         otherwise number of peers known
+ */
+int gnunet_identity_request_peer_infos(struct ClientServerConnection * sock,
+                                      GNUnetIdentityPeerInfoCallback callback,
+                                      void * cls) {
+  MESSAGE_HEADER req;
+  MESSAGE_HEADER * reply;
+  CS_identity_peer_info_MESSAGE * info;
+  unsigned int count;
 
+  req.size = htons(sizeof(MESSAGE_HEADER));
+  req.type = htons(CS_PROTO_identity_request_INFO);
+  if (SYSERR == connection_write(sock,
+                                &req))
+    return SYSERR;
+  count = 0;
+  while (OK == connection_read(sock,
+                              &reply)) {
+    if (ntohs(reply->size) < sizeof(MESSAGE_HEADER)) {
+      GE_BREAK(NULL, 0);
+      FREE(reply);
+      return SYSERR;
+    }
+    if (ntohs(reply->type) == CS_PROTO_RETURN_VALUE) {
+      FREE(reply);
+      return count;
+    }
+    count++;
+    if ( (ntohs(reply->type) != CS_PROTO_identity_INFO) ||
+        (ntohs(reply->size) <= sizeof(CS_identity_peer_info_MESSAGE)) ||
+        ( ((char*)reply)[ntohs(reply->size)-1] != '\0') ) {
+      GE_BREAK(NULL, 0);
+      FREE(reply);
+      return SYSERR;
+    }
+    if (callback != NULL) {
+      info = (CS_identity_peer_info_MESSAGE *) reply;
+      if (OK != callback(cls,
+                        &info->peer,
+                        (const char*) &info[1],
+                        ntohl(info->trust),
+                        ntohl(info->bpm))) {
+       FREE(reply);
+       return SYSERR;
+      }
+    }
+    FREE(reply);    
+  }
+  return SYSERR;
+}
+
+
+
 /* end of clientapi.c */

Modified: GNUnet/src/applications/identity/identity.c
===================================================================
--- GNUnet/src/applications/identity/identity.c 2007-05-29 04:24:49 UTC (rev 
4850)
+++ GNUnet/src/applications/identity/identity.c 2007-05-29 05:06:34 UTC (rev 
4851)
@@ -1203,7 +1203,60 @@
                               &reply.header);
 }
 
+static int hostInfoIterator(const PeerIdentity * identity,
+                           unsigned short protocol,
+                           int confirmed,
+                           void * data) {
+  struct ClientHandle * sock = data;
+  Transport_ServiceAPI * transport;
+  CS_identity_peer_info_MESSAGE * reply;
+  P2P_hello_MESSAGE * hello;
+  char * address;
+  int ret;
+  
+  if (confirmed == NO)
+    return OK;
+  hello = identity2Helo(identity,
+                       protocol,
+                       YES);
+  if (hello == NULL)
+    return OK;
+  transport = coreAPI->requestService("transport");
+  address = transport->helloToString(hello,
+                                    YES);
+  coreAPI->releaseService(transport);
+  if (address == NULL)
+    address = STRDUP("");
+  if (strlen(address)+1 >= MAX_BUFFER_SIZE - 
sizeof(CS_identity_peer_info_MESSAGE) ) {
+    FREE(address);
+    address = STRDUP("invalid");
+  }
+  reply = MALLOC(sizeof(CS_identity_peer_info_MESSAGE) + strlen(address) + 1);
+  reply->header.size = htons(sizeof(CS_identity_peer_info_MESSAGE) + 
strlen(address) + 1);
+  reply->header.type = htons(CS_PROTO_identity_INFO);
+  reply->peer = *identity;
+  reply->trust = htonl(getHostTrust(identity));
+  reply->bpm = htonl(coreAPI->queryBPMfromPeer(identity));
+  memcpy(&reply[1],
+        address,
+        strlen(address) + 1);
+  FREE(address);
+  ret = coreAPI->sendToClient(sock,
+                             &reply->header);
+  FREE(reply); 
+  return ret;
+}
 
+static int identityRequestInfoHandler(struct ClientHandle * sock,
+                                     const MESSAGE_HEADER * message) {
+  forEachHost(get_time(),
+             &hostInfoIterator,
+             sock);
+  return coreAPI->sendValueToClient(sock,
+                                   OK);
+}
+
+
 /**
  * Provide the Identity service.
  *
@@ -1303,6 +1356,8 @@
                                 &identityRequestHelloHandler);
   coreAPI->registerClientHandler(CS_PROTO_identity_request_SIGN,
                                 &identityRequestSignatureHandler);
+  coreAPI->registerClientHandler(CS_PROTO_identity_request_INFO,
+                                &identityRequestInfoHandler);
   return &id;
 }
 
@@ -1322,6 +1377,8 @@
                                   &identityRequestHelloHandler);
   coreAPI->unregisterClientHandler(CS_PROTO_identity_request_SIGN,
                                   &identityRequestSignatureHandler);
+  coreAPI->unregisterClientHandler(CS_PROTO_identity_request_INFO,
+                                  &identityRequestInfoHandler);
   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-29 04:24:49 UTC (rev 
4850)
+++ GNUnet/src/applications/identity/identity.h 2007-05-29 05:06:34 UTC (rev 
4851)
@@ -35,7 +35,6 @@
   Signature sig;
 } CS_identity_signature_MESSAGE;
 
-
 /**
  * Format of the connection request.
  */
@@ -45,5 +44,23 @@
   PeerIdentity other;
 } CS_identity_connect_MESSAGE;
 
+/**
+ * Format of the peer information response.
+ *
+ * Note that the struct is followed by a zero-terminated,
+ * variable-size string with the peer's address as given by the
+ * transport.
+ */
+typedef struct {
+  MESSAGE_HEADER header;
 
+  PeerIdentity peer;
+
+  unsigned int trust;
+
+  unsigned int bpm;
+} CS_identity_peer_info_MESSAGE;
+
+
+
 #endif

Modified: GNUnet/src/include/gnunet_identity_lib.h
===================================================================
--- GNUnet/src/include/gnunet_identity_lib.h    2007-05-29 04:24:49 UTC (rev 
4850)
+++ GNUnet/src/include/gnunet_identity_lib.h    2007-05-29 05:06:34 UTC (rev 
4851)
@@ -74,6 +74,38 @@
 int gnunet_identity_request_connect(struct ClientServerConnection * sock,
                                    const PeerIdentity * peer);
 
+
+/**
+ * Callback called to give information about all known peers
+ *
+ * @param trust amount of trust that this peer has earned
+ *        with us
+ * @param address address of the peer (as given by the
+ *        transport; likely to be an IP+PORT, but could
+ *        be anything!)
+ * @param bpmFromPeer 0 if peer is not connected, otherwise 
+ *        number of bytes per minute that we currently allow
+ *        this peer to sent to us
+ * @param identity the id of the node
+ * @return OK to continue to iterate, SYSERR to abort
+ */
+typedef int (*GNUnetIdentityPeerInfoCallback)(void * data,
+                                             const PeerIdentity * identity,
+                                             const char * address,
+                                             unsigned int trust,
+                                             unsigned int bpmFromPeer);
+
+/**
+ * Request information about all known peers
+ *
+ * @return SYSERR if iteration was aborted, 
+ *         otherwise number of peers known
+ */
+int gnunet_identity_request_peer_infos(struct ClientServerConnection * sock,
+                                      GNUnetIdentityPeerInfoCallback callback,
+                                      void * cls);
+
+
 #if 0 /* keep Emacsens' auto-indent happy */
 {
 #endif

Modified: GNUnet/src/include/gnunet_protocols.h
===================================================================
--- GNUnet/src/include/gnunet_protocols.h       2007-05-29 04:24:49 UTC (rev 
4850)
+++ GNUnet/src/include/gnunet_protocols.h       2007-05-29 05:06:34 UTC (rev 
4851)
@@ -193,12 +193,23 @@
 /* *********** messages for identity module ************* */
 
 /**
- * Client asks the daemon to try to connect to
- * a particular peer.
+ * Client asks daemon for information about
+ * all known peers
  */
-#define CS_PROTO_identity_CONNECT 27
+#define CS_PROTO_identity_request_INFO 25
 
 /**
+ * Deamon responds with information about a peer.
+ */
+#define CS_PROTO_identity_INFO 26
+
+/**
+ * Client asks the Daemon about how to contact
+ * it.
+ */
+#define CS_PROTO_identity_request_HELLO 27
+
+/**
  * Client informs the Daemon about how to contact
  * a particular peer -- or daemon informs client
  * about how other peers should contact it.
@@ -208,19 +219,20 @@
 /**
  * Client asks the Daemon to sign a message.
  */
-#define CS_PROTO_identity_SIGNATURE 29
+#define CS_PROTO_identity_request_SIGN 29
 
 /**
- * Client asks the Daemon about how to contact
- * it.
+ * Daemon sends client a signature
  */
-#define CS_PROTO_identity_request_HELLO 30
+#define CS_PROTO_identity_SIGNATURE 30
 
 /**
- * Client asks the Daemon to sign a message.
+ * Client asks the daemon to try to connect to
+ * a particular peer.
  */
-#define CS_PROTO_identity_request_SIGN 31
+#define CS_PROTO_identity_CONNECT 31
 
+
 /* *********** messages for traffic module ************* */
 
 /**

Modified: GNUnet/src/include/gnunet_util_core.h
===================================================================
--- GNUnet/src/include/gnunet_util_core.h       2007-05-29 04:24:49 UTC (rev 
4850)
+++ GNUnet/src/include/gnunet_util_core.h       2007-05-29 05:06:34 UTC (rev 
4851)
@@ -90,6 +90,8 @@
 #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 */





reply via email to

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