Finished code of peer discovery