##// END OF EJS Templates
wireprotoserver: split ssh protocol handler and server...
Gregory Szorc -
r36082:bf676267 default
parent child Browse files
Show More
@@ -354,19 +354,12 b' def _sshv1respondooberror(fout, ferr, rs'
354 fout.write(b'\n')
354 fout.write(b'\n')
355 fout.flush()
355 fout.flush()
356
356
357 class sshserver(baseprotocolhandler):
357 class sshv1protocolhandler(baseprotocolhandler):
358 def __init__(self, ui, repo):
358 """Handler for requests services via version 1 of SSH protocol."""
359 def __init__(self, ui, fin, fout):
359 self._ui = ui
360 self._ui = ui
360 self._repo = repo
361 self._fin = fin
361 self._fin = ui.fin
362 self._fout = fout
362 self._fout = ui.fout
363
364 hook.redirect(True)
365 ui.fout = repo.ui.fout = ui.ferr
366
367 # Prevent insertion/deletion of CRs
368 util.setbinary(self._fin)
369 util.setbinary(self._fout)
370
363
371 @property
364 @property
372 def name(self):
365 def name(self):
@@ -403,6 +396,26 b' class sshserver(baseprotocolhandler):'
403 def redirect(self):
396 def redirect(self):
404 pass
397 pass
405
398
399 def _client(self):
400 client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0]
401 return 'remote:ssh:' + client
402
403 class sshserver(object):
404 def __init__(self, ui, repo):
405 self._ui = ui
406 self._repo = repo
407 self._fin = ui.fin
408 self._fout = ui.fout
409
410 hook.redirect(True)
411 ui.fout = repo.ui.fout = ui.ferr
412
413 # Prevent insertion/deletion of CRs
414 util.setbinary(self._fin)
415 util.setbinary(self._fout)
416
417 self._proto = sshv1protocolhandler(self._ui, self._fin, self._fout)
418
406 def serve_forever(self):
419 def serve_forever(self):
407 while self.serve_one():
420 while self.serve_one():
408 pass
421 pass
@@ -410,8 +423,8 b' class sshserver(baseprotocolhandler):'
410
423
411 def serve_one(self):
424 def serve_one(self):
412 cmd = self._fin.readline()[:-1]
425 cmd = self._fin.readline()[:-1]
413 if cmd and wireproto.commands.commandavailable(cmd, self):
426 if cmd and wireproto.commands.commandavailable(cmd, self._proto):
414 rsp = wireproto.dispatch(self._repo, self, cmd)
427 rsp = wireproto.dispatch(self._repo, self._proto, cmd)
415
428
416 if isinstance(rsp, bytes):
429 if isinstance(rsp, bytes):
417 _sshv1respondbytes(self._fout, rsp)
430 _sshv1respondbytes(self._fout, rsp)
@@ -432,7 +445,3 b' class sshserver(baseprotocolhandler):'
432 elif cmd:
445 elif cmd:
433 _sshv1respondbytes(self._fout, b'')
446 _sshv1respondbytes(self._fout, b'')
434 return cmd != ''
447 return cmd != ''
435
436 def _client(self):
437 client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0]
438 return 'remote:ssh:' + client
@@ -48,7 +48,7 b' class prehelloserver(wireprotoserver.ssh'
48 wireprotoserver._sshv1respondbytes(self._fout, b'')
48 wireprotoserver._sshv1respondbytes(self._fout, b'')
49 l = self._fin.readline()
49 l = self._fin.readline()
50 assert l == b'between\n'
50 assert l == b'between\n'
51 rsp = wireproto.dispatch(self._repo, self, b'between')
51 rsp = wireproto.dispatch(self._repo, self._proto, b'between')
52 wireprotoserver._sshv1respondbytes(self._fout, rsp)
52 wireprotoserver._sshv1respondbytes(self._fout, rsp)
53
53
54 super(prehelloserver, self).serve_forever()
54 super(prehelloserver, self).serve_forever()
@@ -73,7 +73,7 b' class upgradev2server(wireprotoserver.ss'
73
73
74 # Send the upgrade response.
74 # Send the upgrade response.
75 self._fout.write(b'upgraded %s %s\n' % (token, name))
75 self._fout.write(b'upgraded %s %s\n' % (token, name))
76 servercaps = wireproto.capabilities(self._repo, self)
76 servercaps = wireproto.capabilities(self._repo, self._proto)
77 rsp = b'capabilities: %s' % servercaps
77 rsp = b'capabilities: %s' % servercaps
78 self._fout.write(b'%d\n' % len(rsp))
78 self._fout.write(b'%d\n' % len(rsp))
79 self._fout.write(rsp)
79 self._fout.write(rsp)
@@ -24,7 +24,7 b' class SSHServerGetArgsTests(unittest.Tes'
24 def assertparse(self, cmd, input, expected):
24 def assertparse(self, cmd, input, expected):
25 server = mockserver(input)
25 server = mockserver(input)
26 _func, spec = wireproto.commands[cmd]
26 _func, spec = wireproto.commands[cmd]
27 self.assertEqual(server.getargs(spec), expected)
27 self.assertEqual(server._proto.getargs(spec), expected)
28
28
29 def mockserver(inbytes):
29 def mockserver(inbytes):
30 ui = mockui(inbytes)
30 ui = mockui(inbytes)
General Comments 0
You need to be logged in to leave comments. Login now