Network Design and Routing in Peer-to-Peer and Mobile Ad Hoc Networks