Development

This section describes the Chomper code base for developers interested in contributing to Chomper.

Overview

Chomper is a wrapper around a Python proxy library called mitmproxy. When the chomper executable is called with arguments rule-name and block-time, the Python interpreter in calls ./chomper/block.py to enact a block.

./chomper/block.py first checks to see if a block is in effect by reading ./data/block_settings.json.

  1. If a block is not in effect, 1. Set a new block (using chomper.block.enact_block). 2. Create a new set of block settings (using chomper.block.create_block_dict). 3. Schedule a task on root’s Crontab to remove the block in block-time minutes by calling ./chomper/reset.py. 4. Provide a message informing users that a new block has been enacted, and tell them when the block will end.
  2. If a block is in effect, 1. Reinstate the old block. 2. Provide a message informing users that the old block is still in effect, and tell them when the block will end.

chomper.block.enact_block

This function enacts new blocks. It does the following:

  1. Remove any existing rules on iptables’ NAT chain.
  2. Kill any currently running mitmdump or mitmproxy processes.
  3. Forward all outgoing HTTP/HTTPS traffic from ports 80/443 to port 8080.
  4. Start a mitmdump process listening on port 8080 as a daemon inside a detached screen process.