Centralise computation of connection targets.

Moves computing connection targets into the connection itself, reducing
duplication and allowing for clearer testing.