Working with the Bitcoin network protocol
This is a good start point to understand better the code related to peers discovery and management: https://github.com/bitcoin/bitcoin/blob/master/src/net.cpp 
I can't help you directly writing such a code for you but Bitcoin p2p is very similar to bittorrent one or similar. The greatness in Bitcoin is properly the fact that it has such (crypto)currency functionalities, so why should you use the Bitcoin protocol to create a p2p app which has no interest of using the main feature of the original code? 
I think there are different code bases more suitable for your research.