ATM protocol merge

@joshmh at this point this has enough unit test coverage for me to feel comfortable with merging it into `master`. Please review.

It passed an end-to-end test.

Still lacks integration tests and idempotent send tests (which I hope will replace the manual end-to-end test), but let's make that a different branch to avoid ending up with tons of code to review.