Upstream: simplified some code that accesses peers.

No functional changes.