gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r20639 - gnunet/src/stream


From: gnunet
Subject: [GNUnet-SVN] r20639 - gnunet/src/stream
Date: Wed, 21 Mar 2012 08:06:27 +0100

Author: harsha
Date: 2012-03-21 08:06:26 +0100 (Wed, 21 Mar 2012)
New Revision: 20639

Modified:
   gnunet/src/stream/stream_api.c
   gnunet/src/stream/test_stream_local.c
Log:
fixed listen callback to happen after reaching ESTABLISHED state

Modified: gnunet/src/stream/stream_api.c
===================================================================
--- gnunet/src/stream/stream_api.c      2012-03-21 06:56:07 UTC (rev 20638)
+++ gnunet/src/stream/stream_api.c      2012-03-21 07:06:26 UTC (rev 20639)
@@ -231,6 +231,12 @@
   void *receive_buffer;
 
   /**
+   * The listen socket from which this socket is derived. Should be NULL if it
+   * is not a derived socket
+   */
+  struct GNUNET_STREAM_ListenSocket *lsocket;
+
+  /**
    * Task identifier for the read io timeout task
    */
   GNUNET_SCHEDULER_TaskIdentifier read_io_timeout_task;
@@ -266,11 +272,6 @@
   unsigned int retries;
 
   /**
-   * Is this socket derived from listen socket?
-   */
-  unsigned int derived;
-  
-  /**
    * The peer identity of the peer at the other end of the stream
    */
   GNUNET_PEER_Id other_peer;
@@ -1118,13 +1119,33 @@
 set_state_established (void *cls,
                        struct GNUNET_STREAM_Socket *socket)
 {
+  struct GNUNET_PeerIdentity initiator_pid;
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
               "%x: Attaining ESTABLISHED state\n",
               socket->our_id);
   socket->write_offset = 0;
   socket->read_offset = 0;
   socket->state = STATE_ESTABLISHED;
-  if (socket->open_cb)
+  /* FIXME: What if listen_cb is NULL */
+  if (NULL != socket->lsocket)
+    {
+      GNUNET_PEER_resolve (socket->other_peer, &initiator_pid);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "%x: Calling listen callback\n",
+                  socket->our_id);
+      if (GNUNET_SYSERR == 
+          socket->lsocket->listen_cb (socket->lsocket->listen_cb_cls,
+                                      socket,
+                                      &initiator_pid))
+        {
+          socket->state = STATE_CLOSED;
+          /* FIXME: We should close in a decent way */
+          GNUNET_MESH_tunnel_destroy (socket->tunnel); /* Destroy the tunnel */
+          GNUNET_free (socket);
+        }
+    }
+  else if (socket->open_cb)
     socket->open_cb (socket->open_cls, socket);
 }
 
@@ -1869,6 +1890,8 @@
             GNUNET_SCHEDULER_NO_TASK;
         }
 
+      /* FIXME: Bits in the ack_bitmap are only to be set; Once set they cannot
+         be unset */
       socket->write_handle->ack_bitmap = GNUNET_ntohll (ack->bitmap);
       socket->receiver_window_available = 
         ntohl (ack->receive_window_remaining);
@@ -2122,7 +2145,7 @@
   socket->tunnel = tunnel;
   socket->session_id = 0;       /* FIXME */
   socket->state = STATE_INIT;
-  socket->derived = GNUNET_YES;
+  socket->lsocket = lsocket;
   socket->our_id = lsocket->our_id;
   
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2131,16 +2154,7 @@
               socket->other_peer);
   
   /* FIXME: Copy MESH handle from lsocket to socket */
-  /* FIXME: What if listen_cb is NULL */
-  if (GNUNET_SYSERR == lsocket->listen_cb (lsocket->listen_cb_cls,
-                                           socket,
-                                           initiator))
-    {
-      socket->state = STATE_CLOSED;
-      /* FIXME: Send CLOSE message and then free */
-      GNUNET_free (socket);
-      GNUNET_MESH_tunnel_destroy (tunnel); /* Destroy the tunnel */
-    }
+  
   return socket;
 }
 
@@ -2328,7 +2342,7 @@
     }
 
   /* Close mesh connection */
-  if (NULL != socket->mesh && GNUNET_YES != socket->derived)
+  if (NULL != socket->mesh && NULL == socket->lsocket)
     {
       GNUNET_MESH_disconnect (socket->mesh);
       socket->mesh = NULL;

Modified: gnunet/src/stream/test_stream_local.c
===================================================================
--- gnunet/src/stream/test_stream_local.c       2012-03-21 06:56:07 UTC (rev 
20638)
+++ gnunet/src/stream/test_stream_local.c       2012-03-21 07:06:26 UTC (rev 
20639)
@@ -204,9 +204,6 @@
   GNUNET_assert (size <= strlen (data));
   peer->bytes_wrote += size;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Writing completed\n");
-
   if (peer->bytes_wrote < strlen(data)) /* Have more data to send */
     {
       peer->io_write_handle =
@@ -221,6 +218,9 @@
     }
   else
     {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Writing completed\n");
+
       if (&peer1 == peer)   /* Peer1 has finished writing; should read now */
         {
           peer->io_read_handle =
@@ -359,8 +359,8 @@
  */
 static int
 stream_listen_cb (void *cls,
-           struct GNUNET_STREAM_Socket *socket,
-           const struct GNUNET_PeerIdentity *initiator)
+                  struct GNUNET_STREAM_Socket *socket,
+                  const struct GNUNET_PeerIdentity *initiator)
 {
   GNUNET_assert (NULL != socket);
   GNUNET_assert (NULL != initiator);
@@ -372,6 +372,7 @@
               GNUNET_i2s(initiator));
 
   peer2.socket = socket;
+  /* FIXME: reading should be done right now instead of a scheduled call */
   read_task = GNUNET_SCHEDULER_add_now (&stream_read, (void *) socket);
   return GNUNET_OK;
 }




reply via email to

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