[tor-dev] [Stegotorus] Strange comparison in chop_circuit_t::send_targeted(conn, blocksize)

vmon vmonmoonshine at gmail.com
Fri Aug 10 15:11:33 UTC 2012


Hey Zack,

Please take a look at this comparison in
chop_circuit_t::send_targeted(conn, blocksize):

  if (avail > blocksize - lo)
    avail = blocksize - lo;
  else if (avail > SECTION_LEN)
    avail = SECTION_LEN;
  else if (upstream_eof && !sent_fin)
    // this block will carry the last byte of real data to be sent in
    // this direction; mark it as such
    op = op_FIN;

Assume SECTION_LEN = 65536 suppose 
avail = 67000 blocksize - lo = 66500 => avail = 66500
avail = 67000 blocksize - lo = 67500 => avail = 65536

it's like that if avail is very big then the it is OK if it's bigger than
SECTION_LEN but if it's moderately big then it shouldn't be bigger than
SECTION_LEN, which seems very arbitrary.

On the other hand if blocksize - lo < SECTION_LEN again it doesn't make sense,
because then it never reaches to (avail > SECTION_LEN).

So it's like if SECTION_LEN < blocksize - lo the behavior is random and if
it's SECTION_LEN > blocksize - lo is useless. 

Moreover, when blocksize - lo > avail > SECTION_LEN I'm getting
assertion error in the other overload of send_targeted.

Everything makes sense and the assertion failure goes away if I replace 
the code with this:

  if ((avail > blocksize - lo) || (avail > SECTION_LEN))
  { 
    avail = min(blocksize - lo, SECTION_LEN);
  }                
  else if (upstream_eof && !sent_fin)
    // this block will carry the last byte of real data to be sent in
    // this direction; mark it as such
    op = op_FIN;

Please tell me what you think and if the second chunk is the correct
replacement?

Bests,
vmon 


More information about the tor-dev mailing list