structure memory optimizations.
[silc.git] / lib / silccore / silcpacket.h
index 669a4e89d756b38bc4b73e27d0d134bb085af8a3..7912362811eed97c2bb208a6bc36c44ddea334cf 100644 (file)
@@ -164,18 +164,20 @@ typedef unsigned char SilcPacketFlags;
  *
  *    Short description of the fields following:
  *
- *    SilcBuffer buffer
- *
- *      The data buffer.
- *
- *    SilcPacketType type
+ *    SilcUInt16 truelen
  *
- *      Type of the packet. Types are defined below.
+ *      True length of the packet.  This may be set by the caller before
+ *      calling any of the silc_packet_* routines.  If not provided the
+ *      library will calculate the values.
  *
  *    SilcPacketFlags flags
  *
  *      Packet flags. Flags are defined above.
  *
+ *    SilcPacketType type
+ *
+ *      Type of the packet. Types are defined below.
+ *
  *    unsigned char *src_id
  *    SilcUInt8 src_id_len
  *    unsigned char src_id_type
@@ -190,15 +192,19 @@ typedef unsigned char SilcPacketFlags;
  *      Destination ID, its length and type. On packet reception retuned
  *      ID's are always the hash values of the ID's from the packet.
  *
- *    SilcUInt16 truelen
  *    SilcUInt8 padlen
  *
- *      The true lenght of the packet and the padded length of the packet.
- *      These may be set by the caller before calling any of the 
- *      silc_packet_* routines. If not provided the library will calculate
- *      the values.
+ *      The padded length of the packet.  This may be set by the caller
+ *      before calling any of the silc_packet_* routines. If not provided
+ *      the library will calculate the values.
+ *
+ *    unsigned int long_pad
+ * 
+ *      If set to TRUE the packet will include the maximum padding allowed
+ *      in SILC packet, which is 128 bytes.  If FALSE only the amount of
+ *      padding needed will be applied.
  *
- *    int users;
+ *    unsigned int users;
  *
  *      Reference counter for this context. The context is freed only 
  *      after the reference counter hits zero. The counter is added
@@ -209,28 +215,29 @@ typedef unsigned char SilcPacketFlags;
  *
  *      Packet sequence number.
  *
+ *    SilcBuffer buffer
+ *
+ *      The actual packet data.
+ *
  ***/
 typedef struct {
-  SilcBuffer buffer;
-
   SilcUInt16 truelen;
   SilcPacketFlags flags;
   SilcPacketType type;
-  SilcUInt8 padlen;
 
   unsigned char *src_id;
+  unsigned char *dst_id;
   SilcUInt8 src_id_len;
   SilcUInt8 src_id_type;
-
-  unsigned char *dst_id;
   SilcUInt8 dst_id_len;
   SilcUInt8 dst_id_type;
 
-  int users;
-  bool long_pad;               /* Set to TRUE to use maximum padding
-                                  in packet (up to 256 bytes). */
+  SilcUInt8 padlen;
+  unsigned int long_pad : 1;   /* Set when maximum padding in packet */
+  unsigned int users : 23;     /* Reference counter */
 
   SilcUInt32 sequence;
+  SilcBuffer buffer;
 } SilcPacketContext;
 
 /****s* silccore/SilcPacketAPI/SilcPacketParserContext
@@ -449,7 +456,9 @@ void silc_packet_encrypt(SilcCipher cipher, SilcHmac hmac, SilcUInt32 sequence,
  *    `assembled_packet' pointer sent by the caller.  The `assembled_packet'
  *    is a reference to the socket connection's outgoing buffer.  The
  *    returned packet can be encrypted, and then sent to network by calling
- *    silc_packet_send function.
+ *    silc_packet_send function.  The `assembled_packet' may be freely
+ *    modified (like encrypted etc.) but it must not be freed, since it is
+ *    reference from `sock' outgoing buffer, and it is const.
  *
  ***/
 bool silc_packet_assemble(SilcPacketContext *packet, SilcRng rng,
@@ -481,7 +490,9 @@ bool silc_packet_assemble(SilcPacketContext *packet, SilcRng rng,
  *    This returns the prepared data area into the `packet' pointer provided
  *    caller, which can be used then to add data to it, and later encrypt
  *    it.  The `packet' includes reference to the socket connection's
- *    outgoing buffer.
+ *    outgoing buffer.  The `packet' may be freely modified (like 
+ *    encrypted etc.) but it must not be freed, since it is reference from 
+ *    `sock' outgoing buffer, and it is const.
  *
  ***/
 bool silc_packet_send_prepare(SilcSocketConnection sock,