Show More
@@ -114,55 +114,6 def bundle1allowed(repo, action): | |||||
114 |
|
114 | |||
115 | return ui.configbool('server', 'bundle1') |
|
115 | return ui.configbool('server', 'bundle1') | |
116 |
|
116 | |||
117 | def supportedcompengines(ui, role): |
|
|||
118 | """Obtain the list of supported compression engines for a request.""" |
|
|||
119 | assert role in (util.CLIENTROLE, util.SERVERROLE) |
|
|||
120 |
|
||||
121 | compengines = util.compengines.supportedwireengines(role) |
|
|||
122 |
|
||||
123 | # Allow config to override default list and ordering. |
|
|||
124 | if role == util.SERVERROLE: |
|
|||
125 | configengines = ui.configlist('server', 'compressionengines') |
|
|||
126 | config = 'server.compressionengines' |
|
|||
127 | else: |
|
|||
128 | # This is currently implemented mainly to facilitate testing. In most |
|
|||
129 | # cases, the server should be in charge of choosing a compression engine |
|
|||
130 | # because a server has the most to lose from a sub-optimal choice. (e.g. |
|
|||
131 | # CPU DoS due to an expensive engine or a network DoS due to poor |
|
|||
132 | # compression ratio). |
|
|||
133 | configengines = ui.configlist('experimental', |
|
|||
134 | 'clientcompressionengines') |
|
|||
135 | config = 'experimental.clientcompressionengines' |
|
|||
136 |
|
||||
137 | # No explicit config. Filter out the ones that aren't supposed to be |
|
|||
138 | # advertised and return default ordering. |
|
|||
139 | if not configengines: |
|
|||
140 | attr = 'serverpriority' if role == util.SERVERROLE else 'clientpriority' |
|
|||
141 | return [e for e in compengines |
|
|||
142 | if getattr(e.wireprotosupport(), attr) > 0] |
|
|||
143 |
|
||||
144 | # If compression engines are listed in the config, assume there is a good |
|
|||
145 | # reason for it (like server operators wanting to achieve specific |
|
|||
146 | # performance characteristics). So fail fast if the config references |
|
|||
147 | # unusable compression engines. |
|
|||
148 | validnames = set(e.name() for e in compengines) |
|
|||
149 | invalidnames = set(e for e in configengines if e not in validnames) |
|
|||
150 | if invalidnames: |
|
|||
151 | raise error.Abort(_('invalid compression engine defined in %s: %s') % |
|
|||
152 | (config, ', '.join(sorted(invalidnames)))) |
|
|||
153 |
|
||||
154 | compengines = [e for e in compengines if e.name() in configengines] |
|
|||
155 | compengines = sorted(compengines, |
|
|||
156 | key=lambda e: configengines.index(e.name())) |
|
|||
157 |
|
||||
158 | if not compengines: |
|
|||
159 | raise error.Abort(_('%s config option does not specify any known ' |
|
|||
160 | 'compression engines') % config, |
|
|||
161 | hint=_('usable compression engines: %s') % |
|
|||
162 | ', '.sorted(validnames)) |
|
|||
163 |
|
||||
164 | return compengines |
|
|||
165 |
|
||||
166 | # For version 1 transports. |
|
117 | # For version 1 transports. | |
167 | commands = wireprototypes.commanddict() |
|
118 | commands = wireprototypes.commanddict() | |
168 |
|
119 |
@@ -149,7 +149,8 class httpv1protocolhandler(object): | |||||
149 | # FUTURE advertise minrx and mintx after consulting config option |
|
149 | # FUTURE advertise minrx and mintx after consulting config option | |
150 | caps.append('httpmediatype=0.1rx,0.1tx,0.2tx') |
|
150 | caps.append('httpmediatype=0.1rx,0.1tx,0.2tx') | |
151 |
|
151 | |||
152 |
compengines = wireproto.supportedcompengines(repo.ui, |
|
152 | compengines = wireprototypes.supportedcompengines(repo.ui, | |
|
153 | util.SERVERROLE) | |||
153 | if compengines: |
|
154 | if compengines: | |
154 | comptypes = ','.join(urlreq.quote(e.wireprotosupport().name) |
|
155 | comptypes = ','.join(urlreq.quote(e.wireprotosupport().name) | |
155 | for e in compengines) |
|
156 | for e in compengines) | |
@@ -329,7 +330,7 def _httpresponsetype(ui, proto, prefer_ | |||||
329 |
|
330 | |||
330 | # Now find an agreed upon compression format. |
|
331 | # Now find an agreed upon compression format. | |
331 | compformats = wireproto.clientcompressionsupport(proto) |
|
332 | compformats = wireproto.clientcompressionsupport(proto) | |
332 | for engine in wireproto.supportedcompengines(ui, util.SERVERROLE): |
|
333 | for engine in wireprototypes.supportedcompengines(ui, util.SERVERROLE): | |
333 | if engine.wireprotosupport().name in compformats: |
|
334 | if engine.wireprotosupport().name in compformats: | |
334 | opts = {} |
|
335 | opts = {} | |
335 | level = ui.configint('server', '%slevel' % engine.name()) |
|
336 | level = ui.configint('server', '%slevel' % engine.name()) |
@@ -12,6 +12,11 from .node import ( | |||||
12 | from .thirdparty.zope import ( |
|
12 | from .thirdparty.zope import ( | |
13 | interface as zi, |
|
13 | interface as zi, | |
14 | ) |
|
14 | ) | |
|
15 | from .i18n import _ | |||
|
16 | from . import ( | |||
|
17 | error, | |||
|
18 | util, | |||
|
19 | ) | |||
15 |
|
20 | |||
16 | # Names of the SSH protocol implementations. |
|
21 | # Names of the SSH protocol implementations. | |
17 | SSHV1 = 'ssh-v1' |
|
22 | SSHV1 = 'ssh-v1' | |
@@ -319,3 +324,52 class commanddict(dict): | |||||
319 | return False |
|
324 | return False | |
320 |
|
325 | |||
321 | return True |
|
326 | return True | |
|
327 | ||||
|
328 | def supportedcompengines(ui, role): | |||
|
329 | """Obtain the list of supported compression engines for a request.""" | |||
|
330 | assert role in (util.CLIENTROLE, util.SERVERROLE) | |||
|
331 | ||||
|
332 | compengines = util.compengines.supportedwireengines(role) | |||
|
333 | ||||
|
334 | # Allow config to override default list and ordering. | |||
|
335 | if role == util.SERVERROLE: | |||
|
336 | configengines = ui.configlist('server', 'compressionengines') | |||
|
337 | config = 'server.compressionengines' | |||
|
338 | else: | |||
|
339 | # This is currently implemented mainly to facilitate testing. In most | |||
|
340 | # cases, the server should be in charge of choosing a compression engine | |||
|
341 | # because a server has the most to lose from a sub-optimal choice. (e.g. | |||
|
342 | # CPU DoS due to an expensive engine or a network DoS due to poor | |||
|
343 | # compression ratio). | |||
|
344 | configengines = ui.configlist('experimental', | |||
|
345 | 'clientcompressionengines') | |||
|
346 | config = 'experimental.clientcompressionengines' | |||
|
347 | ||||
|
348 | # No explicit config. Filter out the ones that aren't supposed to be | |||
|
349 | # advertised and return default ordering. | |||
|
350 | if not configengines: | |||
|
351 | attr = 'serverpriority' if role == util.SERVERROLE else 'clientpriority' | |||
|
352 | return [e for e in compengines | |||
|
353 | if getattr(e.wireprotosupport(), attr) > 0] | |||
|
354 | ||||
|
355 | # If compression engines are listed in the config, assume there is a good | |||
|
356 | # reason for it (like server operators wanting to achieve specific | |||
|
357 | # performance characteristics). So fail fast if the config references | |||
|
358 | # unusable compression engines. | |||
|
359 | validnames = set(e.name() for e in compengines) | |||
|
360 | invalidnames = set(e for e in configengines if e not in validnames) | |||
|
361 | if invalidnames: | |||
|
362 | raise error.Abort(_('invalid compression engine defined in %s: %s') % | |||
|
363 | (config, ', '.join(sorted(invalidnames)))) | |||
|
364 | ||||
|
365 | compengines = [e for e in compengines if e.name() in configengines] | |||
|
366 | compengines = sorted(compengines, | |||
|
367 | key=lambda e: configengines.index(e.name())) | |||
|
368 | ||||
|
369 | if not compengines: | |||
|
370 | raise error.Abort(_('%s config option does not specify any known ' | |||
|
371 | 'compression engines') % config, | |||
|
372 | hint=_('usable compression engines: %s') % | |||
|
373 | ', '.sorted(validnames)) | |||
|
374 | ||||
|
375 | return compengines |
@@ -393,7 +393,7 def _capabilitiesv2(repo, proto): | |||||
393 | transports. |
|
393 | transports. | |
394 | """ |
|
394 | """ | |
395 | compression = [] |
|
395 | compression = [] | |
396 | for engine in wireproto.supportedcompengines(repo.ui, util.SERVERROLE): |
|
396 | for engine in wireprototypes.supportedcompengines(repo.ui, util.SERVERROLE): | |
397 | compression.append({ |
|
397 | compression.append({ | |
398 | b'name': engine.wireprotosupport().name, |
|
398 | b'name': engine.wireprotosupport().name, | |
399 | }) |
|
399 | }) |
General Comments 0
You need to be logged in to leave comments.
Login now