255 stdin.flush() |
256 stdin.flush() |
256 except IOError: |
257 except IOError: |
257 badresponse() |
258 badresponse() |
258 |
259 |
259 # Assume version 1 of wire protocol by default. |
260 # Assume version 1 of wire protocol by default. |
260 protoname = wireprotoserver.SSHV1 |
261 protoname = wireprototypes.SSHV1 |
261 reupgraded = re.compile(b'^upgraded %s (.*)$' % re.escape(token)) |
262 reupgraded = re.compile(b'^upgraded %s (.*)$' % re.escape(token)) |
262 |
263 |
263 lines = ['', 'dummy'] |
264 lines = ['', 'dummy'] |
264 max_noise = 500 |
265 max_noise = 500 |
265 while lines[-1] and max_noise: |
266 while lines[-1] and max_noise: |
294 |
295 |
295 caps = set() |
296 caps = set() |
296 |
297 |
297 # For version 1, we should see a ``capabilities`` line in response to the |
298 # For version 1, we should see a ``capabilities`` line in response to the |
298 # ``hello`` command. |
299 # ``hello`` command. |
299 if protoname == wireprotoserver.SSHV1: |
300 if protoname == wireprototypes.SSHV1: |
300 for l in reversed(lines): |
301 for l in reversed(lines): |
301 # Look for response to ``hello`` command. Scan from the back so |
302 # Look for response to ``hello`` command. Scan from the back so |
302 # we don't misinterpret banner output as the command reply. |
303 # we don't misinterpret banner output as the command reply. |
303 if l.startswith('capabilities:'): |
304 if l.startswith('capabilities:'): |
304 caps.update(l[:-1].split(':')[1].split()) |
305 caps.update(l[:-1].split(':')[1].split()) |
553 protoname, caps = _performhandshake(ui, stdin, stdout, stderr) |
554 protoname, caps = _performhandshake(ui, stdin, stdout, stderr) |
554 except Exception: |
555 except Exception: |
555 _cleanuppipes(ui, stdout, stdin, stderr) |
556 _cleanuppipes(ui, stdout, stdin, stderr) |
556 raise |
557 raise |
557 |
558 |
558 if protoname == wireprotoserver.SSHV1: |
559 if protoname == wireprototypes.SSHV1: |
559 return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps, |
560 return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps, |
560 autoreadstderr=autoreadstderr) |
561 autoreadstderr=autoreadstderr) |
561 elif protoname == wireprotoserver.SSHV2: |
562 elif protoname == wireprototypes.SSHV2: |
562 return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps, |
563 return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps, |
563 autoreadstderr=autoreadstderr) |
564 autoreadstderr=autoreadstderr) |
564 else: |
565 else: |
565 _cleanuppipes(ui, stdout, stdin, stderr) |
566 _cleanuppipes(ui, stdout, stdin, stderr) |
566 raise error.RepoError(_('unknown version of SSH protocol: %s') % |
567 raise error.RepoError(_('unknown version of SSH protocol: %s') % |