I always wondered how Tor knows all the nodes in the connection path when the Tor Browser connects to a server. I though that the idea behind the onion routing was to hide nodes from each other, so that node A might know node B, but not node C? How does the Tor Browser than know all of the (three) nodes - from me to the exit node and the final server, like in the following screenshot?
The relays do not know the full path through the network.
The client (your local instance of Tor) chooses the path. This means that the client (you) knows the full path, but any single relay in the circuit does not know the full path.
As to how how it displays it, it retrieves the information from the control port using the
GETINFO request for
circuit-status. Since this command returns additional information, like the SOCKS username and password used, and Tor Button sets the SOCKS username and password credentials use for any given site, it can tell which circuit is assocaited with each site and thus display the circuit information.