Unify router_pick_directory_server_impl and router_pick_trusteddirserver_impl

router_pick_directory_server_impl and router_pick_trusteddirserver_impl are very similar.

I wonder if we could refactor them into a single function? (Even if we have to use a macro to do it.)