Refactor p2p middlewares in a separate folder.