template and pseudocode for handshake matching