[dcc2] Reducing the size of the DCC2 negotiation message

Hydra hydra at hydrairc.com
Mon May 10 15:09:02 EDT 2004


> Then instead of having to do 
> "TransportSecurity=TLS1,SSL3,Blowfish" you just do 
> "TransportSecurity=1,2,3" that clearly reduces the size of 
> the message.

If it was me creating tokens, I would create ALL token names and ALL text
based token parameters as 4 bytes long. 

EG. "TSEC=TLS1,SSL3,BLFS"

There's a good reason for doing this, it makes comparing strings as simple
as comparing two 32bit LONGs.

Then you can do neat things like this:

#define TOKEN ('A' | 'B' << 8 | 'C' << 16 | 'D' << 24)

int _tmain()
{
  char *incomingtoken = "ABCD";

  unsigned long token = ((unsigned long *)incomingtoken)[0];

  bool Match = (token == TOKEN);

  return 0;
}

Thus, you can check for tokens and token parameters using much less cpu time
and no loops!

Obviously, this is a C language specific reason for doing this, but the
creators of the FTP protocol obviously understand things like this as all
FTP commands are 4 bytes long too.

It also makes it much easier to write parameter and token parsing code like
this too.

In the above example you could actually miss out all the commas to make the
token's parameter even shorter.

EG. "TSEC=TLS1SSL3BLFS"

Although I think I'd prefer the just for readability's sake.

Fixed field lengths are great sometimes.

Enjoy,

Hydra




More information about the dcc2 mailing list