Peer identity changes

This contains everything from #20, #22 and #23, merged into one.  I've made this depend on #31.