For the autonomous and selfish features of peers, there are many issues existed in P2P network, such as dynamics of networks, heterogeneity of peers, free-riders, tragedy of commons and malicious behaviors. The topology optimization solutions based on trust are effective methods to solve these problems. However, the trust evaluations in related works only focus on the service trust, or consider both the service trust and the routing trust, but the routing trust evaluation algorithm can not stimulate peers to forward query messages. On this basis, a routing trust evaluation algorithm based on profit sharing is proposed. In the algorithm, according to the contributions of routing recommendation peers, the service demanders share the transaction profit with them in order that the routing recommendation peers can get the routing trust of their neighbors by forwarding query messages. Then, a routing trust aware topology optimization protocol is put forward, which considers both service trust and routing trust. Simulations and analysis show that, the routing trust aware topology optimization protocol can not only promote honest peers to the center of the network, exclude malicious peers and free-riders to the edge of the network, but also improve the query efficiency for honest peers.