To do coop without hassle you generally put a password on your game anyway - don't think you can get invaded then.
At least that's how it worked in the ds games
unfortunately you still do get invaded with players even with the password.
The password is to stop other people joining your party/group, but you will still get invaded by other player in your game that appears as enemies and will attack you, which is a pain.
I've not tried co-op in dark souls series of games.