From: Sree Harsha Totakura Date: Wed, 16 Jan 2013 11:35:45 +0000 (+0000) Subject: - doc X-Git-Tag: initial-import-from-subversion-38251~10182 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=a98bf7b88926295d9c0c823a60c0cf7b8a981871;p=oweals%2Fgnunet.git - doc - moved write_cont callback towarding beginning of GNUNET_STREAM_WriteHandle - rename stream_protocol.h to stream.h --- diff --git a/src/include/gnunet_stream_lib.h b/src/include/gnunet_stream_lib.h index 0acede1ac..056695ba3 100644 --- a/src/include/gnunet_stream_lib.h +++ b/src/include/gnunet_stream_lib.h @@ -301,7 +301,7 @@ struct GNUNET_STREAM_ReadHandle; /** * Tries to write the given data to the stream. The maximum size of data that - * can be written as part of a write operation is (64 * (64000 - sizeof (struct + * can be written per a write operation is ~ 4MB (64 * (64000 - sizeof (struct * GNUNET_STREAM_DataMessage))). If size is greater than this it is not an API * violation, however only the said number of maximum bytes will be written. * diff --git a/src/stream/Makefile.am b/src/stream/Makefile.am index 77f2d6d59..099469711 100644 --- a/src/stream/Makefile.am +++ b/src/stream/Makefile.am @@ -12,7 +12,7 @@ endif lib_LTLIBRARIES = libgnunetstream.la libgnunetstream_la_SOURCES = \ - stream_api.c stream_protocol.h + stream_api.c stream.h libgnunetstream_la_LIBADD = \ $(top_builddir)/src/mesh/libgnunetmesh.la \ $(top_builddir)/src/lockmanager/libgnunetlockmanager.la \ diff --git a/src/stream/stream.h b/src/stream/stream.h new file mode 100644 index 000000000..9b92a28ee --- /dev/null +++ b/src/stream/stream.h @@ -0,0 +1,190 @@ +/* + This file is part of GNUnet. + (C) 2012 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file stream/stream.h + * @brief P2P protocol for the stream connections + * @author Sree Harsha Totakura + */ + +#ifndef STREAM_H +#define STREAM_H + +#ifdef __cplusplus +extern "C" +{ +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + +#include "gnunet_util_lib.h" + +GNUNET_NETWORK_STRUCT_BEGIN + + +/** + * The stream message header + * All messages of STREAM should commonly have this as header + */ +struct GNUNET_STREAM_MessageHeader +{ + /** + * The GNUNET message header, types are from GNUNET_MESSAGE_TYPE_STREAM_*-range. + */ + struct GNUNET_MessageHeader header; +}; + + +/** + * The Data message, should be prefixed with stream header with its type set to + * GNUNET_STREAM_Data + */ +struct GNUNET_STREAM_DataMessage +{ + + /** + * Type is GNUNET_MESSAGE_TYPE_STREAM_DATA + */ + struct GNUNET_STREAM_MessageHeader header; + + /** + * Sequence number; starts with a random value. (Just in case + * someone breaks mesh and is able to try to do a Sequence + * Prediction Attack on us.) + */ + uint32_t sequence_number GNUNET_PACKED; + + /** + * number of milliseconds to the soft deadline for sending acknowledgement + * measured from the time this message is received. It is optimal for the + * communication to send the ack within the soft deadline + */ + struct GNUNET_TIME_RelativeNBO ack_deadline; + + /** + * Offset of the packet in the overall stream, modulo 2^32; allows + * the receiver to calculate where in the destination buffer the + * message should be placed. In network byte order. + */ + uint32_t offset GNUNET_PACKED; + + /** + * The data should be appended here + */ +}; + + +/** + * Number of bits in GNUNET_STREAM_AckBitmap + */ +#define GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH 64 + +/** + * The Selective Acknowledgement Bitmap + */ +typedef uint64_t GNUNET_STREAM_AckBitmap; + + +/** + * The Acknowledgment Message to confirm receipt of DATA. + */ +struct GNUNET_STREAM_AckMessage +{ + + /** + * Type is GNUNET_MESSAGE_TYPE_STREAM_ACK + */ + struct GNUNET_STREAM_MessageHeader header; + + /** + * The sequence number of the next Data Message receiver is + * anticipating. Data messages less than this number are received by receiver + */ + uint32_t base_sequence_number GNUNET_PACKED; + + /** + * The Selective Acknowledgement Bitmap. Computed relative to the base_seq + * (bit n corresponds to the Data message with sequence number base_seq+n) + */ + GNUNET_STREAM_AckBitmap bitmap GNUNET_PACKED; + + /** + * Available buffer space past the last acknowledged buffer (for flow control), + * in bytes. + */ + uint32_t receive_window_remaining GNUNET_PACKED; +}; + + +/** + * Message for Acknowledging HELLO + */ +struct GNUNET_STREAM_HelloAckMessage +{ + /** + * The stream message header + */ + struct GNUNET_STREAM_MessageHeader header; + + /** + * The selected sequence number. Following data tranmissions from the sender + * start with this sequence + */ + uint32_t sequence_number GNUNET_PACKED; + + /** + * The size(in bytes) of the receive window on the peer sending this message + * + * FIXME: Remove if not needed + */ + uint32_t receiver_window_size GNUNET_PACKED; +}; + + +/** + * The Transmit close message(used to signal transmission is closed) + * FIXME: dead struct? + */ +struct GNUNET_STREAM_TransmitCloseMessage +{ + /** + * The stream message header + */ + struct GNUNET_STREAM_MessageHeader header; + + /** + * The last sequence number of the packet after which the transmission has + * ended + */ + uint32_t final_sequence_number GNUNET_PACKED; +}; + +GNUNET_NETWORK_STRUCT_END + + +#if 0 /** keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif /* STREAM.H */ diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index 4b86bece0..20df4aaf5 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c @@ -40,7 +40,7 @@ #include "gnunet_lockmanager_service.h" #include "gnunet_statistics_service.h" #include "gnunet_stream_lib.h" -#include "stream_protocol.h" +#include "stream.h" /** * Generic logging shorthand @@ -461,11 +461,6 @@ struct GNUNET_STREAM_WriteHandle */ struct GNUNET_STREAM_Socket *socket; - /** - * The packet_buffers associated with this Handle - */ - struct GNUNET_STREAM_DataMessage *messages[GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH]; - /** * The write continuation callback */ @@ -476,6 +471,11 @@ struct GNUNET_STREAM_WriteHandle */ void *write_cont_cls; + /** + * The packet_buffers associated with this Handle + */ + struct GNUNET_STREAM_DataMessage *messages[GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH]; + /** * The bitmap of this IOHandle; Corresponding bit for a message is set when * it has been acknowledged by the receiver @@ -3488,7 +3488,7 @@ GNUNET_STREAM_listen_close (struct GNUNET_STREAM_ListenSocket *lsocket) /** * Tries to write the given data to the stream. The maximum size of data that - * can be written as part of a write operation is (64 * (64000 - sizeof (struct + * can be written per a write operation is ~ 4MB (64 * (64000 - sizeof (struct * GNUNET_STREAM_DataMessage))). If size is greater than this it is not an API * violation, however only the said number of maximum bytes will be written. * diff --git a/src/stream/stream_protocol.h b/src/stream/stream_protocol.h deleted file mode 100644 index ca14d16ed..000000000 --- a/src/stream/stream_protocol.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - This file is part of GNUnet. - (C) 2012 Christian Grothoff (and other contributing authors) - - GNUnet is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 3, or (at your - option) any later version. - - GNUnet is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. -*/ - -/** - * @file stream/stream_protocol.h - * @brief P2P protocol for the stream connections - * @author Sree Harsha Totakura - */ - -#ifndef STREAM_PROTOCOL_H -#define STREAM_PROTOCOL_H - -#ifdef __cplusplus -extern "C" -{ -#if 0 /* keep Emacsens' auto-indent happy */ -} -#endif -#endif - -#include "gnunet_util_lib.h" - -GNUNET_NETWORK_STRUCT_BEGIN - - -/** - * The stream message header - * All messages of STREAM should commonly have this as header - */ -struct GNUNET_STREAM_MessageHeader -{ - /** - * The GNUNET message header, types are from GNUNET_MESSAGE_TYPE_STREAM_*-range. - */ - struct GNUNET_MessageHeader header; -}; - - -/** - * The Data message, should be prefixed with stream header with its type set to - * GNUNET_STREAM_Data - */ -struct GNUNET_STREAM_DataMessage -{ - - /** - * Type is GNUNET_MESSAGE_TYPE_STREAM_DATA - */ - struct GNUNET_STREAM_MessageHeader header; - - /** - * Sequence number; starts with a random value. (Just in case - * someone breaks mesh and is able to try to do a Sequence - * Prediction Attack on us.) - */ - uint32_t sequence_number GNUNET_PACKED; - - /** - * number of milliseconds to the soft deadline for sending acknowledgement - * measured from the time this message is received. It is optimal for the - * communication to send the ack within the soft deadline - */ - struct GNUNET_TIME_RelativeNBO ack_deadline; - - /** - * Offset of the packet in the overall stream, modulo 2^32; allows - * the receiver to calculate where in the destination buffer the - * message should be placed. In network byte order. - */ - uint32_t offset GNUNET_PACKED; - - /** - * The data should be appended here - */ -}; - - -/** - * Number of bits in GNUNET_STREAM_AckBitmap - */ -#define GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH 64 - -/** - * The Selective Acknowledgement Bitmap - */ -typedef uint64_t GNUNET_STREAM_AckBitmap; - - -/** - * The Acknowledgment Message to confirm receipt of DATA. - */ -struct GNUNET_STREAM_AckMessage -{ - - /** - * Type is GNUNET_MESSAGE_TYPE_STREAM_ACK - */ - struct GNUNET_STREAM_MessageHeader header; - - /** - * The sequence number of the next Data Message receiver is - * anticipating. Data messages less than this number are received by receiver - */ - uint32_t base_sequence_number GNUNET_PACKED; - - /** - * The Selective Acknowledgement Bitmap. Computed relative to the base_seq - * (bit n corresponds to the Data message with sequence number base_seq+n) - */ - GNUNET_STREAM_AckBitmap bitmap GNUNET_PACKED; - - /** - * Available buffer space past the last acknowledged buffer (for flow control), - * in bytes. - */ - uint32_t receive_window_remaining GNUNET_PACKED; -}; - - -/** - * Message for Acknowledging HELLO - */ -struct GNUNET_STREAM_HelloAckMessage -{ - /** - * The stream message header - */ - struct GNUNET_STREAM_MessageHeader header; - - /** - * The selected sequence number. Following data tranmissions from the sender - * start with this sequence - */ - uint32_t sequence_number GNUNET_PACKED; - - /** - * The size(in bytes) of the receive window on the peer sending this message - * - * FIXME: Remove if not needed - */ - uint32_t receiver_window_size GNUNET_PACKED; -}; - - -/** - * The Transmit close message(used to signal transmission is closed) - * FIXME: dead struct? - */ -struct GNUNET_STREAM_TransmitCloseMessage -{ - /** - * The stream message header - */ - struct GNUNET_STREAM_MessageHeader header; - - /** - * The last sequence number of the packet after which the transmission has - * ended - */ - uint32_t final_sequence_number GNUNET_PACKED; -}; - -GNUNET_NETWORK_STRUCT_END - - -#if 0 /** keep Emacsens' auto-indent happy */ -{ -#endif -#ifdef __cplusplus -} -#endif - -#endif /* STREAM_PROTOCOL_H */