Generative model for reciprocity and community detection in networks