code: def canonical_peer( self, peer ):
          
          their_host, their_port = url_to_host_port( peer )
  
          if their_host in ['127.0.0.1', '::1']:
              their_host = 'localhost'
  
          return "%s:%s" % (their_host, their_port)
docs: Get the canonical peer name