The mechanism of detonation attenuation by a porous medium and its subsequent re-initiation