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.

If locking is still considered better practice, I can, of course, add locks.  The new implementation of the median filter is more efficient in addition.