changed peer into a state machine