Fundamentals of electromagnetic nanonetworks in the terahertz band