Opened 3 months ago

Last modified 3 months ago

#28815 new defect

Refactor similar compression buffer code in dircache.c

Reported by: teor Owned by:
Priority: Medium Milestone: Tor: unspecified
Component: Core Tor/Tor Version:
Severity: Normal Keywords: technical-debt, tor-dir, tor-bwauth
Cc: Actual Points:
Parent ID: #21377 Points: 1
Reviewer: Sponsor:

Description

After #21377, we will have 3 copies of similar compression buffer code in dircache.c.

Copying code is a bad idea, because:

  • people make mistakes when they copy, and
  • when people make changes, they sometimes miss the copies.

Instead, we should write a function that correctly adds compressed or uncompressed data to the connection, based on conn, compress_method, uncompressed_body_len, lifetime, estimated_len, and the data that needs to be added to the buffer.

Perhaps the dirserv_spool_* functions could help here.

Then we can call the new function from handle_get_next_bandwidth():
https://github.com/torproject/tor/blob/b03091842bc4590e11e3ac026daae8ed6d8f7554/src/feature/dircache/dircache.c#L1463-L1468

handle_get_status_vote():
https://github.com/torproject/tor/blob/8020d6fb05d9477e77c6ca554dc1288873f6115c/src/feature/dircache/dircache.c#L1034-L1048

and handle_get_keys():
https://github.com/torproject/tor/blob/8020d6fb05d9477e77c6ca554dc1288873f6115c/src/feature/dircache/dircache.c#L1292-L1310

Child Tickets

Change History (1)

comment:1 Changed 3 months ago by teor

Parent ID: #21377

Let's think about fixing this technical debt before merging #21377.

Note: See TracTickets for help on using tickets.