Show More
@@ -12,6 +12,7 b' from .thirdparty import (' | |||||
12 | cbor, |
|
12 | cbor, | |
13 | ) |
|
13 | ) | |
14 | from . import ( |
|
14 | from . import ( | |
|
15 | encoding, | |||
15 | error, |
|
16 | error, | |
16 | util, |
|
17 | util, | |
17 | wireprotoframing, |
|
18 | wireprotoframing, | |
@@ -127,7 +128,13 b' class clienthandler(object):' | |||||
127 | response.cbor = True |
|
128 | response.cbor = True | |
128 |
|
129 | |||
129 | if meta['eos']: |
|
130 | if meta['eos']: | |
130 | self._futures[frame.requestid].set_result(response) |
|
131 | # If the command has a decoder, resolve the future to the | |
|
132 | # decoded value. Otherwise resolve to the rich response object. | |||
|
133 | decoder = COMMAND_DECODERS.get(response.command) | |||
|
134 | ||||
|
135 | result = decoder(response) if decoder else response | |||
|
136 | ||||
|
137 | self._futures[frame.requestid].set_result(result) | |||
131 |
|
138 | |||
132 | del self._requests[frame.requestid] |
|
139 | del self._requests[frame.requestid] | |
133 | del self._futures[frame.requestid] |
|
140 | del self._futures[frame.requestid] | |
@@ -135,3 +142,38 b' class clienthandler(object):' | |||||
135 | else: |
|
142 | else: | |
136 | raise error.ProgrammingError( |
|
143 | raise error.ProgrammingError( | |
137 | 'unhandled action from clientreactor: %s' % action) |
|
144 | 'unhandled action from clientreactor: %s' % action) | |
|
145 | ||||
|
146 | def decodebranchmap(resp): | |||
|
147 | # Response should be a single CBOR map of branch name to array of nodes. | |||
|
148 | bm = next(resp.cborobjects()) | |||
|
149 | ||||
|
150 | return {encoding.tolocal(k): v for k, v in bm.items()} | |||
|
151 | ||||
|
152 | def decodeheads(resp): | |||
|
153 | # Array of node bytestrings. | |||
|
154 | return next(resp.cborobjects()) | |||
|
155 | ||||
|
156 | def decodeknown(resp): | |||
|
157 | # Bytestring where each byte is a 0 or 1. | |||
|
158 | raw = next(resp.cborobjects()) | |||
|
159 | ||||
|
160 | return [True if c == '1' else False for c in raw] | |||
|
161 | ||||
|
162 | def decodelistkeys(resp): | |||
|
163 | # Map with bytestring keys and values. | |||
|
164 | return next(resp.cborobjects()) | |||
|
165 | ||||
|
166 | def decodelookup(resp): | |||
|
167 | return next(resp.cborobjects()) | |||
|
168 | ||||
|
169 | def decodepushkey(resp): | |||
|
170 | return next(resp.cborobjects()) | |||
|
171 | ||||
|
172 | COMMAND_DECODERS = { | |||
|
173 | 'branchmap': decodebranchmap, | |||
|
174 | 'heads': decodeheads, | |||
|
175 | 'known': decodeknown, | |||
|
176 | 'listkeys': decodelistkeys, | |||
|
177 | 'lookup': decodelookup, | |||
|
178 | 'pushkey': decodepushkey, | |||
|
179 | } |
@@ -67,6 +67,6 b' No arguments returns something reasonabl' | |||||
67 | received frame(size=112; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) |
|
67 | received frame(size=112; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) | |
68 | s> 0\r\n |
|
68 | s> 0\r\n | |
69 | s> \r\n |
|
69 | s> \r\n | |
70 |
response: |
|
70 | response: {b'branch1': [b'\xb5\xfa\xac\xdf\xd2c7h\xcb1R3l\xc0\x953\x81&f\x88'], b'branch2': [b'"Aa\xc7X\x9a\xa4\x8f\xa8:H\xfe\xff^\x95\xb5j\xe3\'\xfc'], b'default': [b'&\x80Z\xba\x1e`\n\x82\xe96a\x14\x9f#\x13\x86j"\x1a{', b'\xbe\x0e\xf7<\x17\xad\xe3\xfc\x89\xdcAp\x1e\xb9\xfc:\x91\xb5\x82\x82']} | |
71 |
|
71 | |||
72 | $ cat error.log |
|
72 | $ cat error.log |
@@ -58,7 +58,7 b' All non-secret heads returned by default' | |||||
58 | received frame(size=64; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) |
|
58 | received frame(size=64; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) | |
59 | s> 0\r\n |
|
59 | s> 0\r\n | |
60 | s> \r\n |
|
60 | s> \r\n | |
61 |
response: |
|
61 | response: [b'\x1dok\x91\xd4J\xab\xa6\xd5\xe5\x80\xbc0\xa9\x94\x850\xdb\xe0\x0b', b'\xaeI.6\xb0\xc83\x9f\xfa\xf3(\xd0\x0b\x85\xb4R]\xe1\x16^', b')Dm-\xc5A\x9c_\x97Dz\x8b\xc0b\xe4\xcc2\x8b\xf2A'] | |
62 |
|
62 | |||
63 | Requesting just the public heads works |
|
63 | Requesting just the public heads works | |
64 |
|
64 | |||
@@ -91,6 +91,6 b' Requesting just the public heads works' | |||||
91 | received frame(size=22; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) |
|
91 | received frame(size=22; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) | |
92 | s> 0\r\n |
|
92 | s> 0\r\n | |
93 | s> \r\n |
|
93 | s> \r\n | |
94 |
response: |
|
94 | response: [b'x\xd2\xdc\xa46\xb2\xf5\xb1\x88\xac&~)\xb8\x1e\x07&m8\xfc'] | |
95 |
|
95 | |||
96 | $ cat error.log |
|
96 | $ cat error.log |
@@ -50,7 +50,7 b' No arguments returns something reasonabl' | |||||
50 | received frame(size=1; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) |
|
50 | received frame(size=1; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) | |
51 | s> 0\r\n |
|
51 | s> 0\r\n | |
52 | s> \r\n |
|
52 | s> \r\n | |
53 |
response: [ |
|
53 | response: [] | |
54 |
|
54 | |||
55 | Single known node works |
|
55 | Single known node works | |
56 |
|
56 | |||
@@ -83,7 +83,7 b' Single known node works' | |||||
83 | received frame(size=2; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) |
|
83 | received frame(size=2; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) | |
84 | s> 0\r\n |
|
84 | s> 0\r\n | |
85 | s> \r\n |
|
85 | s> \r\n | |
86 |
response: [ |
|
86 | response: [True] | |
87 |
|
87 | |||
88 | Multiple nodes works |
|
88 | Multiple nodes works | |
89 |
|
89 | |||
@@ -116,6 +116,6 b' Multiple nodes works' | |||||
116 | received frame(size=4; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) |
|
116 | received frame(size=4; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) | |
117 | s> 0\r\n |
|
117 | s> 0\r\n | |
118 | s> \r\n |
|
118 | s> \r\n | |
119 | response: [b'101'] |
|
119 | response: [True, False, True] | |
120 |
|
120 | |||
121 | $ cat error.log |
|
121 | $ cat error.log |
@@ -54,7 +54,7 b' Request for namespaces works' | |||||
54 | received frame(size=32; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) |
|
54 | received frame(size=32; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) | |
55 | s> 0\r\n |
|
55 | s> 0\r\n | |
56 | s> \r\n |
|
56 | s> \r\n | |
57 |
response: |
|
57 | response: {b'bookmarks': b'', b'namespaces': b'', b'phases': b''} | |
58 |
|
58 | |||
59 | Request for phases works |
|
59 | Request for phases works | |
60 |
|
60 | |||
@@ -87,7 +87,7 b' Request for phases works' | |||||
87 | received frame(size=61; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) |
|
87 | received frame(size=61; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) | |
88 | s> 0\r\n |
|
88 | s> 0\r\n | |
89 | s> \r\n |
|
89 | s> \r\n | |
90 |
response: |
|
90 | response: {b'be0ef73c17ade3fc89dc41701eb9fc3a91b58282': b'1', b'publishing': b'True'} | |
91 |
|
91 | |||
92 | Request for bookmarks works |
|
92 | Request for bookmarks works | |
93 |
|
93 | |||
@@ -120,6 +120,6 b' Request for bookmarks works' | |||||
120 | received frame(size=45; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) |
|
120 | received frame(size=45; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) | |
121 | s> 0\r\n |
|
121 | s> 0\r\n | |
122 | s> \r\n |
|
122 | s> \r\n | |
123 |
response: |
|
123 | response: {b'@': b'26805aba1e600a82e93661149f2313866a221a7b'} | |
124 |
|
124 | |||
125 | $ cat error.log |
|
125 | $ cat error.log |
@@ -50,6 +50,6 b' lookup for known node works' | |||||
50 | received frame(size=*; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) (glob) |
|
50 | received frame(size=*; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) (glob) | |
51 | s> 0\r\n |
|
51 | s> 0\r\n | |
52 | s> \r\n |
|
52 | s> \r\n | |
53 |
response: |
|
53 | response: b'Bk\xad\xa5\xc6u\x98\xcae\x03mW\xd9\xe4\xb6K\x0c\x1c\xe7\xa0' | |
54 |
|
54 | |||
55 |
$ |
|
55 | $ cat error.log |
@@ -53,7 +53,7 b' pushkey for a bookmark works' | |||||
53 | received frame(size=*; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) (glob) |
|
53 | received frame(size=*; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) (glob) | |
54 | s> 0\r\n |
|
54 | s> 0\r\n | |
55 | s> \r\n |
|
55 | s> \r\n | |
56 |
response: |
|
56 | response: True | |
57 |
|
57 | |||
58 |
$ |
|
58 | $ sendhttpv2peer << EOF | |
59 | > command listkeys |
|
59 | > command listkeys | |
@@ -84,6 +84,6 b' pushkey for a bookmark works' | |||||
84 | received frame(size=45; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) |
|
84 | received frame(size=45; request=1; stream=2; streamflags=stream-begin; type=bytes-response; flags=eos|cbor) | |
85 | s> 0\r\n |
|
85 | s> 0\r\n | |
86 | s> \r\n |
|
86 | s> \r\n | |
87 |
response: |
|
87 | response: {b'@': b'426bada5c67598ca65036d57d9e4b64b0c1ce7a0'} | |
88 |
|
88 | |||
89 | $ cat error.log |
|
89 | $ cat error.log |
General Comments 0
You need to be logged in to leave comments.
Login now