jens@0: // jens@0: // BLIP_Internal.h jens@0: // MYNetwork jens@0: // jens@0: // Created by Jens Alfke on 5/10/08. jens@0: // Copyright 2008 Jens Alfke. All rights reserved. jens@0: // jens@0: jens@0: #import "BLIPConnection.h" jens@0: #import "BLIPRequest.h" jens@0: #import "BLIPProperties.h" jens@0: @class BLIPWriter; jens@0: jens@0: jens@0: /* Private declarations and APIs for BLIP implementation. Not for use by clients! */ jens@0: jens@0: jens@0: /* BLIP message types; encoded in each frame's header. */ jens@0: typedef enum { jens@0: kBLIP_MSG, // initiating message jens@0: kBLIP_RPY, // response to a MSG jens@0: kBLIP_ERR // error response to a MSG jens@0: } BLIPMessageType; jens@0: jens@0: /* Flag bits in a BLIP frame header */ jens@0: enum { jens@0: kBLIP_TypeMask = 0x000F, // bits reserved for storing message type jens@0: kBLIP_Compressed= 0x0010, // data is gzipped jens@0: kBLIP_Urgent = 0x0020, // please send sooner/faster jens@0: kBLIP_NoReply = 0x0040, // no RPY needed jens@0: kBLIP_MoreComing= 0x0080, // More frames coming (Applies only to individual frame) jens@18: kBLIP_Meta = 0x0100, // Special message type, handled internally (hello, bye, ...) jens@0: }; jens@0: typedef UInt16 BLIPMessageFlags; jens@0: jens@0: jens@0: /** Header of a BLIP frame as sent across the wire. All fields are big-endian. */ jens@0: typedef struct { jens@0: UInt32 magic; // magic number (kBLIPFrameHeaderMagicNumber) jens@0: UInt32 number; // serial number of MSG jens@0: BLIPMessageFlags flags; // encodes frame type, "more" flag, and other delivery options jens@0: UInt16 size; // total size of frame, _including_ this header jens@0: } BLIPFrameHeader; jens@0: jens@19: #define kBLIPFrameHeaderMagicNumber 0x9B34F206 jens@0: jens@18: #define kBLIPProfile_Hi @"Hi" // Used for Profile header in meta greeting message jens@18: #define kBLIPProfile_Bye @"Bye" // Used for Profile header in meta close-request message jens@18: jens@0: jens@0: @interface BLIPConnection () jens@0: - (void) _dispatchRequest: (BLIPRequest*)request; jens@0: - (void) _dispatchResponse: (BLIPResponse*)response; jens@0: @end jens@0: jens@0: jens@0: @interface BLIPMessage () jens@0: @property BOOL sent, propertiesAvailable, complete; jens@18: - (BLIPMessageFlags) _flags; jens@0: - (void) _setFlag: (BLIPMessageFlags)flag value: (BOOL)value; jens@0: - (void) _encode; jens@0: @end jens@0: jens@0: jens@0: @interface BLIPMessage () jens@0: - (id) _initWithConnection: (BLIPConnection*)connection jens@0: isMine: (BOOL)isMine jens@0: flags: (BLIPMessageFlags)flags jens@0: number: (UInt32)msgNo jens@0: body: (NSData*)body; jens@0: - (BOOL) _writeFrameTo: (BLIPWriter*)writer maxSize: (UInt16)maxSize; jens@0: @property (readonly) SInt32 _bytesWritten; jens@0: - (void) _assignedNumber: (UInt32)number; jens@0: - (BOOL) _receivedFrameWithHeader: (const BLIPFrameHeader*)header body: (NSData*)body; jens@0: - (void) _connectionClosed; jens@0: @end jens@0: jens@0: jens@0: @interface BLIPRequest () jens@0: - (id) _initWithConnection: (BLIPConnection*)connection jens@0: body: (NSData*)body jens@0: properties: (NSDictionary*)properties; jens@0: @end jens@0: jens@0: jens@0: @interface BLIPResponse () jens@0: - (id) _initWithRequest: (BLIPRequest*)request; jens@0: @end