J
James Kanze
On Feb 26, 9:30 pm, (e-mail address removed) wrote:[...]On Feb 25, 2:27 pm, k-e-n <[email protected]> wrote:Interestingly, the major use of total message lengths I'veObviously another thing you can add is the total message
length, again at a fixed location near the beginning of the
message.
Do you always use total message lengths? I'm of the
opinion that if communication is happening behind a single
firewall, the total message lengths can be omitted. That
assumes an organization can trust it's employees. For the
most part I think that is a safe assumption, but there are
some exceptions.
seen is between processes communicating over a pipe. It's
mainly an optimization measure, but it can make a
significant difference, and it can make the code easier to
write as well.
I'm not sure why you describe it as an "optimization measure."
It seems to me that not calculating/sending/receiving a total
msg length is simpler if the context permits.
If you're communicating over a pipe, the channel doesn't break
the stream up into messages for you. If you have a fixed length
header with the length, you can read a message in two reads, one
for the header, and one for the rest of the message. Without
the length, you may have to read byte by byte, depending on how
you determine the end of the message. (And you must be able to
determine it, because if you attempt to read beyond the end,
you'll block until the next message.)
What I got out of the thread on clc++m about denial of service
and serialization is that using a total msg length is
important from a security perspective.
I'm not sure why. I can see that someone sending overly long
messages can cause problems, but putting the message length in
the message doesn't prevent that.
You know from the msgid and version number that the message has one
high-level element - a variable length array.
One or more high-level elements. The message might contain
several variable length arrays (and other data as well). (Note
that strings are often transmitted as a variable length array of
char. So any message which contains several strings is likely
to fall into this category.)
And the length of the array is prepended to the array data as
part of the payload.
So if the interface doesn't know about the record structure of
the data (e.g. a pipe or a file), then you have to read through
the length of the first array, then read the array, then read up
through the length of the second array, etc.
I guess there is header-like info embedded in the payload the
way I think about it. It could be made part of a header but
I'm don't think there is anything to be gained from that.
It depends on the overall context. Even if the communications
protocol supports the definition of records, it might be useful
to allow layering; the lower level components don't know the
high level structure, and use the length field. (This is how
TCP works, for example.)
If some messages don't have variable length data there is a
little bit of unnecessary overhead in having a element count.
If all messages have the same fixed size, it's definitely
unnecessary.