refactor to extract peer interface
add test cases for peer