Fix the peer manager's median calculation.

The previous version was producing random crashes due to race conditions
between inserting new values and reading _sorted.  The implementation is
now changed to calculate the median on changes and cache the value.
While this hasn't introduced any locking, the reading routine median()
can now no longer see an inconsistent state.  If at the same time an
update happens, it can only either see the old or the new value, which
is both fine.
Merge pull request #75 from domob1812/fix-median

Fix the peer manager's median calculation.
Super - thanks for fixing this - I never had the issue myself though - could be due to number of peers ?