mercurial/wireprotov2server.py
changeset 40023 10cf8b116dd8
parent 40021 c537144fdbef
child 40025 b099e6032f38
equal deleted inserted replaced
40022:33eb670e2834 40023:10cf8b116dd8
   515 
   515 
   516     if streamclone.allowservergeneration(repo):
   516     if streamclone.allowservergeneration(repo):
   517         caps['rawrepoformats'] = sorted(repo.requirements &
   517         caps['rawrepoformats'] = sorted(repo.requirements &
   518                                         repo.supportedformats)
   518                                         repo.supportedformats)
   519 
   519 
       
   520     targets = getadvertisedredirecttargets(repo, proto)
       
   521     if targets:
       
   522         caps[b'redirect'] = {
       
   523             b'targets': [],
       
   524             b'hashes': [b'sha256', b'sha1'],
       
   525         }
       
   526 
       
   527         for target in targets:
       
   528             entry = {
       
   529                 b'name': target['name'],
       
   530                 b'protocol': target['protocol'],
       
   531                 b'uris': target['uris'],
       
   532             }
       
   533 
       
   534             for key in ('snirequired', 'tlsversions'):
       
   535                 if key in target:
       
   536                     entry[key] = target[key]
       
   537 
       
   538             caps[b'redirect'][b'targets'].append(entry)
       
   539 
   520     return proto.addcapabilities(repo, caps)
   540     return proto.addcapabilities(repo, caps)
       
   541 
       
   542 def getadvertisedredirecttargets(repo, proto):
       
   543     """Obtain a list of content redirect targets.
       
   544 
       
   545     Returns a list containing potential redirect targets that will be
       
   546     advertised in capabilities data. Each dict MUST have the following
       
   547     keys:
       
   548 
       
   549     name
       
   550        The name of this redirect target. This is the identifier clients use
       
   551        to refer to a target. It is transferred as part of every command
       
   552        request.
       
   553 
       
   554     protocol
       
   555        Network protocol used by this target. Typically this is the string
       
   556        in front of the ``://`` in a URL. e.g. ``https``.
       
   557 
       
   558     uris
       
   559        List of representative URIs for this target. Clients can use the
       
   560        URIs to test parsing for compatibility or for ordering preference
       
   561        for which target to use.
       
   562 
       
   563     The following optional keys are recognized:
       
   564 
       
   565     snirequired
       
   566        Bool indicating if Server Name Indication (SNI) is required to
       
   567        connect to this target.
       
   568 
       
   569     tlsversions
       
   570        List of bytes indicating which TLS versions are supported by this
       
   571        target.
       
   572 
       
   573     By default, clients reflect the target order advertised by servers
       
   574     and servers will use the first client-advertised target when picking
       
   575     a redirect target. So targets should be advertised in the order the
       
   576     server prefers they be used.
       
   577     """
       
   578     return []
   521 
   579 
   522 def wireprotocommand(name, args=None, permission='push', cachekeyfn=None):
   580 def wireprotocommand(name, args=None, permission='push', cachekeyfn=None):
   523     """Decorator to declare a wire protocol command.
   581     """Decorator to declare a wire protocol command.
   524 
   582 
   525     ``name`` is the name of the wire protocol command being provided.
   583     ``name`` is the name of the wire protocol command being provided.