fix(peer.go) Make sure we use the leader's term to create AppendEntriesRequest.
We do not stop the heartbeats before increases the term of the leader. It is possible that the even after
the state check, the leader stepsdown and use the new term to send out a AppendEntries request. We fixed this by recording the term when it is the leader(if it is not the leader at that time, flush() will return in the if statement).
merge with master
add conditions for state for loops
drop unused field in log
Merge branch 'dev' of github.com:xiangli-cmu/raft
Merge branch 'cleanup_loops' of github.com:xiangli-cmu/raft