##// END OF EJS Templates
wireproto: implement capabilities for wire protocol v2...
Gregory Szorc -
r37551:df498549 default
parent child Browse files
Show More
@@ -0,0 +1,40 b''
1 $ . $TESTDIR/wireprotohelpers.sh
2
3 $ hg init server
4 $ enablehttpv2 server
5 $ hg -R server serve -p $HGPORT -d --pid-file hg.pid -E error.log
6 $ cat hg.pid > $DAEMON_PIDS
7
8 capabilities request returns an array of capability strings
9
10 $ sendhttpv2peer << EOF
11 > command capabilities
12 > EOF
13 creating http peer for wire protocol version 2
14 sending capabilities command
15 s> POST /api/exp-http-v2-0001/ro/capabilities HTTP/1.1\r\n
16 s> Accept-Encoding: identity\r\n
17 s> accept: application/mercurial-exp-framing-0003\r\n
18 s> content-type: application/mercurial-exp-framing-0003\r\n
19 s> content-length: 27\r\n
20 s> host: $LOCALIP:$HGPORT\r\n (glob)
21 s> user-agent: Mercurial debugwireproto\r\n
22 s> \r\n
23 s> \x13\x00\x00\x01\x00\x01\x01\x11\xa1DnameLcapabilities
24 s> makefile('rb', None)
25 s> HTTP/1.1 200 OK\r\n
26 s> Server: testing stub value\r\n
27 s> Date: $HTTP_DATE$\r\n
28 s> Content-Type: application/mercurial-exp-framing-0003\r\n
29 s> Transfer-Encoding: chunked\r\n
30 s> \r\n
31 s> *\r\n (glob)
32 s> *\x00\x01\x00\x02\x01F (glob)
33 s> \xa2Hcommands\xabEheads\xa2Dargs\x81JpubliconlyKpermissions\x81DpullEknown\xa2Dargs\x81EnodesKpermissions\x81DpullFlookup\xa2Dargs\x81CkeyKpermissions\x81DpullGpushkey\xa2Dargs\x84CkeyInamespaceCnewColdKpermissions\x81DpushHlistkeys\xa2Dargs\x81InamespaceKpermissions\x81DpullHunbundle\xa2Dargs\x81EheadsKpermissions\x81DpushIbranchmap\xa2Dargs\x80Kpermissions\x81DpullIgetbundle\xa2Dargs\x81A*Kpermissions\x81DpullJstream_out\xa2Dargs\x80Kpermissions\x81DpullLcapabilities\xa2Dargs\x80Kpermissions\x81DpullLclonebundles\xa2Dargs\x80Kpermissions\x81DpullKcompression\x82\xa1DnameDzstd\xa1DnameDzlib
34 s> \r\n
35 received frame(size=*; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) (glob)
36 s> 0\r\n
37 s> \r\n
38 response: [{b'commands': {b'branchmap': {b'args': [], b'permissions': [b'pull']}, b'capabilities': {b'args': [], b'permissions': [b'pull']}, b'clonebundles': {b'args': [], b'permissions': [b'pull']}, b'getbundle': {b'args': [b'*'], b'permissions': [b'pull']}, b'heads': {b'args': [b'publiconly'], b'permissions': [b'pull']}, b'known': {b'args': [b'nodes'], b'permissions': [b'pull']}, b'listkeys': {b'args': [b'namespace'], b'permissions': [b'pull']}, b'lookup': {b'args': [b'key'], b'permissions': [b'pull']}, b'pushkey': {b'args': [b'key', b'namespace', b'new', b'old'], b'permissions': [b'push']}, b'stream_out': {b'args': [], b'permissions': [b'pull']}, b'unbundle': {b'args': [b'heads'], b'permissions': [b'push']}}, b'compression': [{b'name': b'zstd'}, {b'name': b'zlib'}]}]
39
40 $ cat error.log
@@ -1690,6 +1690,42 b' Receives no arguments.'
1690 The response is a map with bytestring keys defining the branch name.
1690 The response is a map with bytestring keys defining the branch name.
1691 Values are arrays of bytestring defining raw changeset nodes.
1691 Values are arrays of bytestring defining raw changeset nodes.
1692
1692
1693 capabilities
1694 ------------
1695
1696 Obtain the server's capabilities.
1697
1698 Receives no arguments.
1699
1700 This command is typically called only as part of the handshake during
1701 initial connection establishment.
1702
1703 The response is a map with bytestring keys defining server information.
1704
1705 The defined keys are:
1706
1707 commands
1708 A map defining available wire protocol commands on this server.
1709
1710 Keys in the map are the names of commands that can be invoked. Values
1711 are maps defining information about that command. The bytestring keys
1712 are:
1713
1714 args
1715 An array of argument names accepted by this command.
1716 permissions
1717 An array of permissions required to execute this command.
1718
1719 compression
1720 An array of maps defining available compression format support.
1721
1722 The array is sorted from most preferred to least preferred.
1723
1724 Each entry has the following bytestring keys:
1725
1726 name
1727 Name of the compression engine. e.g. ``zstd`` or ``zlib``.
1728
1693 heads
1729 heads
1694 -----
1730 -----
1695
1731
@@ -903,7 +903,8 b' def _capabilities(repo, proto):'
903
903
904 # If you are writing an extension and consider wrapping this function. Wrap
904 # If you are writing an extension and consider wrapping this function. Wrap
905 # `_capabilities` instead.
905 # `_capabilities` instead.
906 @wireprotocommand('capabilities', permission='pull')
906 @wireprotocommand('capabilities', permission='pull',
907 transportpolicy=POLICY_V1_ONLY)
907 def capabilities(repo, proto):
908 def capabilities(repo, proto):
908 caps = _capabilities(repo, proto)
909 caps = _capabilities(repo, proto)
909 return wireprototypes.bytesresponse(' '.join(sorted(caps)))
910 return wireprototypes.bytesresponse(' '.join(sorted(caps)))
@@ -1283,6 +1284,31 b' def unbundle(repo, proto, heads):'
1283
1284
1284 # Wire protocol version 2 commands only past this point.
1285 # Wire protocol version 2 commands only past this point.
1285
1286
1287 def _capabilitiesv2(repo, proto):
1288 """Obtain the set of capabilities for version 2 transports.
1289
1290 These capabilities are distinct from the capabilities for version 1
1291 transports.
1292 """
1293 compression = []
1294 for engine in supportedcompengines(repo.ui, util.SERVERROLE):
1295 compression.append({
1296 b'name': engine.wireprotosupport().name,
1297 })
1298
1299 caps = {
1300 'commands': {},
1301 'compression': compression,
1302 }
1303
1304 for command, entry in commandsv2.items():
1305 caps['commands'][command] = {
1306 'args': sorted(entry.args.split()) if entry.args else [],
1307 'permissions': [entry.permission],
1308 }
1309
1310 return proto.addcapabilities(repo, caps)
1311
1286 @wireprotocommand('branchmap', permission='pull',
1312 @wireprotocommand('branchmap', permission='pull',
1287 transportpolicy=POLICY_V2_ONLY)
1313 transportpolicy=POLICY_V2_ONLY)
1288 def branchmapv2(repo, proto):
1314 def branchmapv2(repo, proto):
@@ -1291,6 +1317,13 b' def branchmapv2(repo, proto):'
1291
1317
1292 return wireprototypes.cborresponse(branchmap)
1318 return wireprototypes.cborresponse(branchmap)
1293
1319
1320 @wireprotocommand('capabilities', permission='pull',
1321 transportpolicy=POLICY_V2_ONLY)
1322 def capabilitiesv2(repo, proto):
1323 caps = _capabilitiesv2(repo, proto)
1324
1325 return wireprototypes.cborresponse(caps)
1326
1294 @wireprotocommand('heads', args='publiconly', permission='pull',
1327 @wireprotocommand('heads', args='publiconly', permission='pull',
1295 transportpolicy=POLICY_V2_ONLY)
1328 transportpolicy=POLICY_V2_ONLY)
1296 def headsv2(repo, proto, publiconly=False):
1329 def headsv2(repo, proto, publiconly=False):
@@ -831,6 +831,9 b' class sshv2protocolhandler(sshv1protocol'
831 def name(self):
831 def name(self):
832 return wireprototypes.SSHV2
832 return wireprototypes.SSHV2
833
833
834 def addcapabilities(self, repo, caps):
835 return caps
836
834 def _runsshserver(ui, repo, fin, fout, ev):
837 def _runsshserver(ui, repo, fin, fout, ev):
835 # This function operates like a state machine of sorts. The following
838 # This function operates like a state machine of sorts. The following
836 # states are defined:
839 # states are defined:
@@ -1120,9 +1120,9 b' Command after upgrade to version 2 is pr'
1120 i> write(6) -> 6:
1120 i> write(6) -> 6:
1121 i> hello\n
1121 i> hello\n
1122 o> readline() -> 4:
1122 o> readline() -> 4:
1123 o> 403\n
1123 o> 397\n
1124 o> readline() -> 403:
1124 o> readline() -> 397:
1125 o> capabilities: batch branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset getbundle known lookup pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash\n
1125 o> capabilities: branchmap $USUAL_BUNDLE2_CAPS_SERVER$ changegroupsubset getbundle known lookup pushkey streamreqs=generaldelta,revlogv1 unbundle=HG10GZ,HG10BZ,HG10UN unbundlehash\n
1126
1126
1127 Multiple upgrades is not allowed
1127 Multiple upgrades is not allowed
1128
1128
General Comments 0
You need to be logged in to leave comments. Login now