#include <Message.hpp>
Inheritance diagram for Ionflux::Tools::Message:
Public Member Functions | |
Message () | |
Constructor. | |
virtual | ~Message () |
Destructor. | |
virtual void | clearData () |
Clear data. | |
virtual void | clearAll () |
Clear everything. | |
virtual void | serialize (std::string &buffer) |
Serialize. | |
virtual bool | append (const std::string &bytes) |
Append bytes. | |
virtual void | dump (const std::string &bytes) |
Dump bytes. | |
virtual void | setMagicWord (const std::string &newMagicWord) |
Set magic word. | |
virtual void | setProtocolVersion (int newProtocolVersion) |
Set protocol version number. | |
virtual void | setAcceptableProtocolVersion (int newProtocolVersionLower, int newProtocolVersionUpper) |
Set acceptable protocol version number range. | |
virtual void | setUID (int newUID) |
Set UID. | |
virtual void | setType (int newType) |
Set message type. | |
virtual void | setFlags (unsigned int newFlags) |
Set flags. | |
virtual void | setUsername (const std::string &newUsername) |
Set username. | |
virtual void | setUserSecret (const std::string &newUserSecret) |
Set user secret. | |
virtual void | setSessionSecret (const std::string &newSessionSecret) |
Set session secret. | |
virtual void | setTarget (MessageDump *newTarget) |
Set target. | |
virtual void | setMaxSize (unsigned int newMaxSize) |
Set maximum message size. | |
virtual std::string | getMagicWord () |
Get magic word. | |
virtual int | getProtocolVersion () |
Get protocol version. | |
virtual int | getUID () |
Get UID. | |
virtual int | getType () |
Get message type. | |
virtual unsigned int | getFlags () |
Get flags. | |
virtual unsigned int | getSize () |
Get size. | |
virtual std::string | getUsername () |
Get username. | |
virtual void | getUserSecret (std::string &userSecretBuffer) |
Get user secret. | |
virtual void | getSessionSecret (std::string &sessionSecretBuffer) |
Get session secret. | |
virtual unsigned int | getNumBytesMissing () |
Get number of missing bytes. | |
virtual unsigned int | getMaxSize () |
Get maximum message size. | |
Static Public Attributes | |
static const std::string | DEFAULT_MAGIC_WORD = "IFTM" |
Default magic word. | |
static const int | DEFAULT_PROTOCOL_VERSION = 0 |
Default protocol version. | |
static const int | UID_NOT_SET = -1 |
UID: Not set. | |
static const int | TYPE_NOT_SET = -1 |
Type: Not set. | |
static const int | FLAG_COMPRESS = 1 |
Flag: Compress message. | |
static const int | HEADER_SIZE = 40 |
Message header size (excluding the magic word). | |
static const unsigned int | DEFAULT_MAX_SIZE = 10485760L |
Default maximum message size. | |
Protected Member Functions | |
virtual bool | unpack () |
Unpack message. | |
Protected Attributes | |
std::string | magicWord |
Magic word. | |
int | protocolVersion |
Protocol version. | |
int | protocolVersionLower |
Acceptable protocol version range: lower boundary. | |
int | protocolVersionUpper |
Acceptable protocol version range: upper boundary. | |
int | uid |
Message UID. | |
int | type |
Message type. | |
unsigned int | flags |
Message flags. | |
unsigned int | size |
Size of serialized message. | |
std::string | checksum |
Checksum buffer. | |
std::string | username |
Username (used for authentication). | |
std::string | userSecret |
User secret (used for authentication). | |
std::string | sessionSecret |
Session secret (used for authentication). | |
std::string | serialized |
Serialization buffer. | |
MessageDump * | target |
Target for completed messages. | |
unsigned int | maxSize |
Maximum size. |
A message which can encapsulate and serialize arbitrary data, to be sent over a network supporting byte streams or packets. Facilities are provided for integrity verification, compression and simple message authentication.
To create a serialized message, initialize the message as necessary, then call Message::serialize().
To create messages out of a stream of serialized messages, set a handler with Message::setTarget(), then pass bytes from the stream to Message::dump(). The handler will be called whenever a complete message has arrived and has been parsed successfully.
Simple authentication on a per-message basis will be performed if you set the username, user secret and session secret to non-empty values. All of these fields are optional; however, for authentication to succeed, the fields must be set to the same values for the sender and receiver of a message.
|
Constructor. Construct new Message object. |
|
Destructor. Destruct Message object. |
|
Append bytes. Pass a string of bytes to be processed as part of a serialized message.
|
|
Clear everything. Clears all internal state, including otherwise persistent properties.
|
|
Clear data. Clears internal data of this message. Persistent properties, such as the magic word, protocol version and user/session data will not be reset.
|
|
Dump bytes. Pass a string of bytes to be processed as part of a serialized message.
|
|
Get flags.
|
|
Get magic word.
|
|
Get maximum message size.
|
|
Get number of missing bytes. Get the number of serialized bytes required to complete the message. Use dump() to append additional bytes to the message. If the message is complete or invalid, this function returns 0.
|
|
Get protocol version.
|
|
Get session secret. Copies the session secret to a specified buffer.
|
|
Get size.
|
|
Get message type.
|
|
Get UID.
|
|
Get username.
|
|
Get user secret. Copies the user secret to a specified buffer.
|
|
Serialize. Serialize the message. The result will be ready to be sent over a network and may be re-assembled into a message object using dump().
|
|
Set acceptable protocol version number range. Sets the upper and lower limit of acceptable protocol version numbers for creating messages from a stream of serialized messages. If messages arrive that have version numbers outside the specified range, they will be ignored. Messages with acceptable version numbers will be parsed and passed to the handler on completion.
|
|
Set flags. Set additional flags to be sent along with the message. It is possible to combine several flags using the "|" (OR) operator. Note: Set Message::FLAG_COMPRESS to compress message data using bzip2.
|
|
Set magic word. Sets the magic word. This should be a short string (2-4 bytes) specific to your protocol. It will be used to determine ad-hoc whether incoming data might be part of a valid message.
|
|
Set maximum message size. Set the maximum allowed size for a single message, in bytes.
|
|
Set protocol version number. Sets the protocol version number. Incoming data will be accepted only if the protocol version number is contained within the range of acceptable protocol version numbers.
|
|
Set session secret. Set the session secret to be used for message authentication. Note: As the name implies, you should not reuse this secret across sessions or connections. The best candidate for a session secret is a random string of a fixed length, generated on a new connection and passed to the peer in one of the first few messages.
|
|
Set target. Set the target that should be noified on completion of a message.
|
|
Set message type. Set the numerical type ID of the message. This makes sense only if your protocol distingusihes several different message types. You may also use this for error message codes.
|
|
Set UID. Set the UID of his message. This should be a number unique to a session or connection.
|
|
Set username. Set the username to be used for message authentication.
|
|
Set user secret. Set the user secret to be used for message authentication.
|
|
Unpack message. Unpack a message from the data stored in the serialization buffer.
|
|
Checksum buffer.
|
|
Default magic word.
|
|
Default maximum message size.
|
|
Default protocol version.
|
|
Flag: Compress message.
|
|
Message flags.
|
|
Message header size (excluding the magic word).
|
|
Magic word.
|
|
Maximum size.
|
|
Protocol version.
|
|
Acceptable protocol version range: lower boundary.
|
|
Acceptable protocol version range: upper boundary.
|
|
Serialization buffer.
|
|
Session secret (used for authentication).
|
|
Size of serialized message.
|
|
Target for completed messages.
|
|
Message type.
|
|
Type: Not set.
|
|
Message UID.
|
|
UID: Not set.
|
|
Username (used for authentication).
|
|
User secret (used for authentication).
|