Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/wireprototypes.py @ 37060:2ec1fb9de638
wireproto: add request IDs to frames
One of my primary goals with the new wire protocol is to make
operations faster and enable both client and server-side
operations to scale to multiple CPU cores.
One of the ways we make server interactions faster is by reducing
the number of round trips to that server.
With the existing wire protocol, the "batch" command facilitates
executing multiple commands from a single request payload. The way
it works is the requests for multiple commands are serialized. The
server executes those commands sequentially then serializes all
their results. As an optimization for reducing round trips, this
is very effective. The technical implementation, however, is pretty
bad and suffers from a number of deficiencies. For example, it
creates a new place where authorization to run a command must be
checked. (The lack of this checking in older Mercurial releases
was CVE-2018-1000132.)
The principles behind the "batch" command are sound. However, the
execution is not. Therefore, I want to ditch "batch" in the
new wire protocol and have protocol level support for issuing
multiple requests in a single round trip.
This commit introduces support in the frame-based wire protocol to
facilitate this. We do this by adding a "request ID" to each frame.
If a server sees frames associated with different "request IDs," it
handles them as separate requests. All of this happening possibly
as part of the same message from client to server (the same request
body in the case of HTTP).
We /could/ model the exchange the way pipelined HTTP requests do,
where the server processes requests in order they are issued and
received. But this artifically constrains scalability. A better
model is to allow multi-requests to be executed concurrently and
for responses to be sent and handled concurrently. So the
specification explicitly allows this. There is some work to be done
around specifying dependencies between multi-requests. We take
the easy road for now and punt on this problem, declaring that
if order is important, clients must not issue the request until
responses to dependent requests have been received.
This commit focuses on the boilerplate of implementing the request
ID. The server reactor still can't manage multiple, in-flight
request IDs. This will be addressed in a subsequent commit.
Because the wire semantics have changed, we bump the version of the
media type.
Differential Revision: https://phab.mercurial-scm.org/D2869
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 14 Mar 2018 16:51:34 -0700 |
parents | 1cfef5693203 |
children | 27527d8cff5c |
rev | line source |
---|---|
36111
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 # Copyright 2018 Gregory Szorc <gregory.szorc@gmail.com> |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 # |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # This software may be used and distributed according to the terms of the |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 # GNU General Public License version 2 or any later version. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 from __future__ import absolute_import |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
36402
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
8 import abc |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
9 |
36565
3cd245945ef3
wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36402
diff
changeset
|
10 # Names of the SSH protocol implementations. |
3cd245945ef3
wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36402
diff
changeset
|
11 SSHV1 = 'ssh-v1' |
37049
1cfef5693203
wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36809
diff
changeset
|
12 # These are advertised over the wire. Increment the counters at the end |
36565
3cd245945ef3
wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36402
diff
changeset
|
13 # to reflect BC breakages. |
3cd245945ef3
wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36402
diff
changeset
|
14 SSHV2 = 'exp-ssh-v2-0001' |
37049
1cfef5693203
wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36809
diff
changeset
|
15 HTTPV2 = 'exp-http-v2-0001' |
36565
3cd245945ef3
wireprotoserver: move SSHV1 and SSHV2 constants to wireprototypes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36402
diff
changeset
|
16 |
36638
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
17 # All available wire protocol transports. |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
18 TRANSPORTS = { |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
19 SSHV1: { |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
20 'transport': 'ssh', |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
21 'version': 1, |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
22 }, |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
23 SSHV2: { |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
24 'transport': 'ssh', |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
25 'version': 2, |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
26 }, |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
27 'http-v1': { |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
28 'transport': 'http', |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
29 'version': 1, |
37049
1cfef5693203
wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36809
diff
changeset
|
30 }, |
1cfef5693203
wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36809
diff
changeset
|
31 HTTPV2: { |
1cfef5693203
wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36809
diff
changeset
|
32 'transport': 'http', |
1cfef5693203
wireproto: support /api/* URL space for exposing APIs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36809
diff
changeset
|
33 'version': 2, |
36638
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
34 } |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
35 } |
abc3b9801563
wireproto: allow wire protocol commands to declare transport support
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36565
diff
changeset
|
36 |
36112
2f7290555c96
wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36111
diff
changeset
|
37 class bytesresponse(object): |
2f7290555c96
wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36111
diff
changeset
|
38 """A wire protocol response consisting of raw bytes.""" |
2f7290555c96
wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36111
diff
changeset
|
39 def __init__(self, data): |
2f7290555c96
wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36111
diff
changeset
|
40 self.data = data |
2f7290555c96
wireproto: introduce type for raw byte responses (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36111
diff
changeset
|
41 |
36111
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 class ooberror(object): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 """wireproto reply: failure of a batch of operation |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 Something failed during a batch call. The error message is stored in |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 `self.message`. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 """ |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 def __init__(self, message): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 self.message = message |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 class pushres(object): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 """wireproto reply: success with simple integer return |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 The call was successful and returned an integer contained in `self.res`. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 """ |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 def __init__(self, res, output): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 self.res = res |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 self.output = output |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 class pusherr(object): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 """wireproto reply: failure |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 The call failed. The `self.res` attribute contains the error message. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 """ |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 def __init__(self, res, output): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 self.res = res |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 self.output = output |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 class streamres(object): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 """wireproto reply: binary stream |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
71 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 The call was successful and the result is a stream. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 Accepts a generator containing chunks of data to be sent to the client. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 ``prefer_uncompressed`` indicates that the data is expected to be |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 uncompressable and that the stream should therefore use the ``none`` |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 engine. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 """ |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 def __init__(self, gen=None, prefer_uncompressed=False): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 self.gen = gen |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 self.prefer_uncompressed = prefer_uncompressed |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 class streamreslegacy(object): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 """wireproto reply: uncompressed binary stream |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 The call was successful and the result is a stream. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 Accepts a generator containing chunks of data to be sent to the client. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
91 Like ``streamres``, but sends an uncompressed data for "version 1" clients |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
92 using the application/mercurial-0.1 media type. |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
93 """ |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
94 def __init__(self, gen=None): |
cd6ab329c5c7
wireprototypes: move wire protocol response types to new module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 self.gen = gen |
36402
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
96 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
97 class baseprotocolhandler(object): |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
98 """Abstract base class for wire protocol handlers. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
99 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
100 A wire protocol handler serves as an interface between protocol command |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
101 handlers and the wire protocol transport layer. Protocol handlers provide |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
102 methods to read command arguments, redirect stdio for the duration of |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
103 the request, handle response types, etc. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
104 """ |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
105 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
106 __metaclass__ = abc.ABCMeta |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
107 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
108 @abc.abstractproperty |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
109 def name(self): |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
110 """The name of the protocol implementation. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
111 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
112 Used for uniquely identifying the transport type. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
113 """ |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
114 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
115 @abc.abstractmethod |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
116 def getargs(self, args): |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
117 """return the value for arguments in <args> |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
118 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
119 returns a list of values (same order as <args>)""" |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
120 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
121 @abc.abstractmethod |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
122 def forwardpayload(self, fp): |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
123 """Read the raw payload and forward to a file. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
124 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
125 The payload is read in full before the function returns. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
126 """ |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
127 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
128 @abc.abstractmethod |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
129 def mayberedirectstdio(self): |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
130 """Context manager to possibly redirect stdio. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
131 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
132 The context manager yields a file-object like object that receives |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
133 stdout and stderr output when the context manager is active. Or it |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
134 yields ``None`` if no I/O redirection occurs. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
135 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
136 The intent of this context manager is to capture stdio output |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
137 so it may be sent in the response. Some transports support streaming |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
138 stdio to the client in real time. For these transports, stdio output |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
139 won't be captured. |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
140 """ |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
141 |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
142 @abc.abstractmethod |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
143 def client(self): |
0c231df1ffdc
wireprototypes: move baseprotocolhandler from wireprotoserver
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36112
diff
changeset
|
144 """Returns a string representation of this client (as bytes).""" |
36642
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
145 |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
146 @abc.abstractmethod |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
147 def addcapabilities(self, repo, caps): |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
148 """Adds advertised capabilities specific to this protocol. |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
149 |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
150 Receives the list of capabilities collected so far. |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
151 |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
152 Returns a list of capabilities. The passed in argument can be returned. |
6e585bca962e
wireproto: add transport specific capabilities in the transport
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36638
diff
changeset
|
153 """ |
36809
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
154 |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
155 @abc.abstractmethod |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
156 def checkperm(self, perm): |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
157 """Validate that the client has permissions to perform a request. |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
158 |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
159 The argument is the permission required to proceed. If the client |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
160 doesn't have that permission, the exception should raise or abort |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
161 in a protocol specific manner. |
66de4555cefd
wireproto: formalize permissions checking as part of protocol interface
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36642
diff
changeset
|
162 """ |