gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] branch master updated (97e954af9 -> b97fab0cb)


From: gnunet
Subject: [gnunet] branch master updated (97e954af9 -> b97fab0cb)
Date: Fri, 21 Jul 2023 05:47:06 +0200

This is an automated email from the git hooks/post-receive script.

marshall pushed a change to branch master
in repository gnunet.

    from 97e954af9 Merge remote-tracking branch 'origin/master'
     new 9d466fff1 transport: add experimental/quiche guards
     new 965ad1a06 transport (quic): receive pid in initial packet
     new 6d6d6cffb transport (quic): give msg to transport service
     new b97fab0cb transport (quic): prepare to send pid

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/include/.gitignore                   |   1 +
 src/transport/gnunet-communicator-quic.c | 179 +++++++++++++++++++++++--------
 2 files changed, 133 insertions(+), 47 deletions(-)

diff --git a/src/include/.gitignore b/src/include/.gitignore
index 75c6af4b6..dba282e99 100644
--- a/src/include/.gitignore
+++ b/src/include/.gitignore
@@ -5,3 +5,4 @@ gnunet_dht_block_types.h
 gnunet_signatures.h
 !gnunet_config.h.in
 gnunet_config.h
+gnunet_mysql_compat.h
\ No newline at end of file
diff --git a/src/transport/gnunet-communicator-quic.c 
b/src/transport/gnunet-communicator-quic.c
index bbd3682f1..fd36f2fe4 100644
--- a/src/transport/gnunet-communicator-quic.c
+++ b/src/transport/gnunet-communicator-quic.c
@@ -26,6 +26,13 @@
         QUICHE_MAX_CONN_ID_LEN
 #define CID_LEN sizeof(uint8_t) * QUICHE_MAX_CONN_ID_LEN
 #define TOKEN_LEN sizeof(uint8_t) * MAX_TOKEN_LEN
+/* Generic, bidirectional, client-initiated quic stream id */
+#define STREAMID_BI 4
+/**
+ * How long do we believe our addresses to remain up (before
+ * the other peer should revalidate).
+ */
+#define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_UNIT_HOURS
 /**
  * Map of DCID (uint8_t) -> quic_conn for quickly retrieving connections to 
other peers.
  */
@@ -45,6 +52,16 @@ static uint16_t my_port;
 static unsigned long long rekey_max_bytes;
 static quiche_config *config = NULL;
 
+/**
+ * Our peer identity
+*/
+struct GNUNET_PeerIdentity my_identity;
+
+/**
+ * Our private key.
+ */
+static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
+
 /**
  * Information we track per peer we have recently been in contact with.
  *
@@ -180,28 +197,35 @@ struct QUIC_header
 };
 
 /**
- * Given a quiche connection and buffer, recv data from streams and store into 
buffer
+ * TODOS:
+ *  1. Mandate timeouts
+ *  2. Setup stats handler properly
+*/
+
+/**
+ * Given a PeerAddress, receive data from streams after doing connection logic.
  * ASSUMES: connection is established to peer
 */
 static void
-recv_from_streams (quiche_conn *conn, char *stream_buf, size_t buf_size)
+recv_from_streams (struct PeerAddress *peer)
 {
+  char stream_buf[UINT16_MAX];
+  size_t buf_size = UINT16_MAX;
+  char *buf_ptr = stream_buf;
+  struct GNUNET_MessageHeader *hdr;
+
   uint64_t s = 0;
   quiche_stream_iter *readable;
   bool fin;
   ssize_t recv_len;
-  static const char *resp = "byez\n";
 
-  readable = quiche_conn_readable (conn);
-  /**
-   * TODO: check for PeerIdentity
-  */
+  readable = quiche_conn_readable (peer->conn->conn);
   while (quiche_stream_iter_next (readable, &s))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,  "stream %" PRIu64 " is readable\n",
                 s);
     fin = false;
-    recv_len = quiche_conn_stream_recv (conn, s,
+    recv_len = quiche_conn_stream_recv (peer->conn->conn, s,
                                         (uint8_t *) stream_buf, buf_size,
                                         &fin);
     if (recv_len < 0)
@@ -209,14 +233,33 @@ recv_from_streams (quiche_conn *conn, char *stream_buf, 
size_t buf_size)
       break;
     }
     /**
-     * Received and processed plaintext from peer: send to core/transport 
service
-     * TODO: send msg to core, remove response below
+     * Initial packet should contain peerid
     */
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "msg received: %s\n", stream_buf);
+    if (GNUNET_NO == peer->id_recvd)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "receiving peer identity\n");
+      struct GNUNET_PeerIdentity *pid = (struct
+                                         GNUNET_PeerIdentity *) stream_buf;
+      peer->target = *pid;
+      peer->id_recvd = GNUNET_YES;
+      buf_ptr += sizeof(struct GNUNET_PeerIdentity);
+      recv_len -= sizeof(struct GNUNET_PeerIdentity);
+    }
+    hdr = (struct GNUNET_MessageHeader *) buf_ptr;
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "passing %lu bytes to core\n",
+                recv_len);
+    GNUNET_TRANSPORT_communicator_receive (ch, &peer->target, hdr,
+                                           ADDRESS_VALIDITY_PERIOD, NULL, 
NULL);
     if (fin)
     {
-      quiche_conn_stream_send (conn, s, (uint8_t *) resp,
-                               5, true);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "fin received, closing connection\n");
+      if (0 > quiche_conn_close (peer->conn->conn, true, 0, NULL, 0))
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "quiche failed to close connection to peer\n");
+      }
     }
   }
   quiche_stream_iter_free (readable);
@@ -376,9 +419,7 @@ reschedule_peer_timeout (struct PeerAddress *peer)
 static void
 peer_destroy (struct PeerAddress *peer)
 {
-
   peer->peer_destroy_called = GNUNET_YES;
-
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Disconnecting peer for peer `%s'\n",
               GNUNET_i2s (&peer->target));
@@ -404,6 +445,27 @@ peer_destroy (struct PeerAddress *peer)
 }
 
 
+/**
+ * Iterator over all peers to clean up.
+ *
+ * @param cls NULL
+ * @param target unused
+ * @param value the queue to destroy
+ * @return #GNUNET_OK to continue to iterate
+ */
+static int
+get_peer_delete_it (void *cls,
+                    const struct GNUNET_PeerIdentity *target,
+                    void *value)
+{
+  struct PeerAddress *peer = value;
+  (void) cls;
+  (void) target;
+  peer_destroy (peer);
+  return GNUNET_OK;
+}
+
+
 /**
  * Signature of functions implementing the sending functionality of a
  * message queue.
@@ -442,6 +504,8 @@ mq_send_d (struct GNUNET_MQ_Handle *mq,
   }
   reschedule_peer_timeout (peer);
 
+  // quiche_conn_stream_send (peer->conn->conn, s, (uint8_t *) resp,
+  //                              5, true);
   // if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock,
   //                                         dgram,
   //                                         sizeof(dgram),
@@ -855,12 +919,14 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity 
*peer_id, const
   struct sockaddr *in;
   socklen_t in_len;
   uint8_t scid[LOCAL_CONN_ID_LEN];
+  size_t send_len;
 
   struct quic_conn *q_conn;
   char *bindto;
   socklen_t local_in_len;
   struct sockaddr *local_addr;
 
+
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (cfg,
                                              COMMUNICATOR_CONFIG_SECTION,
@@ -889,6 +955,9 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity 
*peer_id, const
   peer->address_len = in_len;
   peer->target = *peer_id;
   peer->nt = GNUNET_NT_scanner_get_type (is, in, in_len);
+  /**
+   * TODO: use addr_map
+  */
   (void) GNUNET_CONTAINER_multipeermap_put (
     peers,
     &peer->target,
@@ -921,16 +990,18 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity 
*peer_id, const
                                  local_addr,
                                  local_in_len, peer->address, 
peer->address_len,
                                  config);
-
-
   peer->conn = q_conn;
+  /**
+   * Send our pid
+  */
+  // quiche_conn_send (peer->conn->conn, );
   /**
    * Insert connection into hashmap
   */
-  struct GNUNET_HashCode key;
-  GNUNET_CRYPTO_hash (q_conn->cid, LOCAL_CONN_ID_LEN, &key);
-  GNUNET_CONTAINER_multihashmap_put (conn_map, &key, q_conn,
-                                     
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+  // struct GNUNET_HashCode key;
+  // GNUNET_CRYPTO_hash (q_conn->cid, LOCAL_CONN_ID_LEN, &key);
+  // GNUNET_CONTAINER_multihashmap_put (conn_map, &key, q_conn,
+  //                                    
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
   setup_peer_mq (peer);
   if (NULL == timeout_task)
     timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL);
@@ -949,10 +1020,20 @@ do_shutdown (void *cls)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "do_shutdown\n");
-
-  GNUNET_CONTAINER_multihashmap_destroy (conn_map);
+  GNUNET_CONTAINER_multipeermap_iterate (peers, &get_peer_delete_it, NULL);
+  GNUNET_CONTAINER_multipeermap_destroy (peers);
+  /**
+   * TODO: remove peers, just use addr_map
+  */
+  // GNUNET_CONTAINER_multihashmap_iterate (addr_map, &get_peer_delete_it, 
NULL);
+  // GNUNET_CONTAINER_multihashmap_destroy (addr_map);
   quiche_config_free (config);
 
+  if (NULL != timeout_task)
+  {
+    GNUNET_SCHEDULER_cancel (timeout_task);
+    timeout_task = NULL;
+  }
   if (NULL != read_task)
   {
     GNUNET_SCHEDULER_cancel (read_task);
@@ -974,6 +1055,11 @@ do_shutdown (void *cls)
     GNUNET_TRANSPORT_application_done (ah);
     ah = NULL;
   }
+  if (NULL != my_private_key)
+  {
+    GNUNET_free (my_private_key);
+    my_private_key = NULL;
+  }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "do_shutdown finished\n");
 }
@@ -990,19 +1076,13 @@ sock_read (void *cls)
   ssize_t rcvd;
   (void) cls;
 
-  // struct quic_conn *conn;
-  // struct GNUNET_HashCode conn_key;
   ssize_t process_pkt;
-
   struct QUIC_header quic_header;
   uint8_t new_cid[LOCAL_CONN_ID_LEN];
 
   struct PeerAddress *peer;
   struct GNUNET_HashCode addr_key;
 
-  /**
-   * May be unnecessary if quiche_header_info writes to len fields
-  */
   quic_header.scid_len = sizeof(quic_header.scid);
   quic_header.dcid_len = sizeof(quic_header.dcid);
   quic_header.odcid_len = sizeof(quic_header.odcid);
@@ -1087,12 +1167,6 @@ sock_read (void *cls)
     return;
   }
 
-  /* look for connection in hashtable */
-  /* each connection to the peer should have a unique incoming DCID */
-  /* check against a conn SCID */
-  // GNUNET_CRYPTO_hash (quic_header.dcid, sizeof(quic_header.dcid), 
&conn_key);
-  // conn = GNUNET_CONTAINER_multihashmap_get (conn_map, &conn_key);
-
   /**
    * New QUIC connection with peer
   */
@@ -1208,14 +1282,13 @@ sock_read (void *cls)
   if (quiche_conn_is_established (peer->conn->conn))
   {
     // Check for data on all available streams
-    char stream_buf[UINT16_MAX];
-    recv_from_streams (peer->conn->conn, stream_buf, UINT16_MAX);
+    recv_from_streams (peer);
   }
   /**
    * TODO: Should we use a list instead of hashmap?
    * Overhead for hashing function, O(1) retrieval vs O(n) iteration with n=30?
    *
-   * TODO: Is iteration necessary as in the server example?
+   * TODO: Is iteration necessary as in the quiche server example?
   */
   quiche_stats stats;
   quiche_path_stats path_stats;
@@ -1354,6 +1427,27 @@ run (void *cls,
     my_port = 0;
   }
   GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
+  /**
+   * Setup QUICHE configuration
+  */
+  config = quiche_config_new (QUICHE_PROTOCOL_VERSION);
+  quiche_config_verify_peer (config, false);
+  // conn_map = GNUNET_CONTAINER_multihashmap_create (2, GNUNET_NO);
+  addr_map = GNUNET_CONTAINER_multihashmap_create (2, GNUNET_NO);
+  /**
+   * Get our public key for initial packet
+  */
+  my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
+  if (NULL == my_private_key)
+  {
+    GNUNET_log (
+      GNUNET_ERROR_TYPE_ERROR,
+      _ (
+        "Transport service is lacking key configuration settings. 
Exiting.\n"));
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
   /* start reading */
   read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
                                              udp_sock,
@@ -1395,15 +1489,6 @@ run (void *cls,
 int
 main (int argc, char *const *argv)
 {
-  /**
-   * Setup QUICHE configuration
-  */
-  config = quiche_config_new (QUICHE_PROTOCOL_VERSION);
-
-  quiche_config_verify_peer (config, false);
-  conn_map = GNUNET_CONTAINER_multihashmap_create (2, GNUNET_NO);
-  addr_map = GNUNET_CONTAINER_multihashmap_create (2, GNUNET_NO);
-
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_OPTION_END
   };

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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