D2063: sshpeer: implement peer for version 2 of wire protocol

2018-02-07 Thread indygreg (Gregory Szorc)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG59e4a7781a36: sshpeer: implement peer for version 2 of wire 
protocol (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2063?vs=5257=5303

REVISION DETAIL
  https://phab.mercurial-scm.org/D2063

AFFECTED FILES
  mercurial/sshpeer.py
  tests/test-check-interfaces.py

CHANGE DETAILS

diff --git a/tests/test-check-interfaces.py b/tests/test-check-interfaces.py
--- a/tests/test-check-interfaces.py
+++ b/tests/test-check-interfaces.py
@@ -67,6 +67,8 @@
 checkobject(localrepo.localpeer(dummyrepo()))
 checkobject(sshpeer.sshv1peer(ui, 'ssh://localhost/foo', None, None, None,
   None, None))
+checkobject(sshpeer.sshv2peer(ui, 'ssh://localhost/foo', None, None, None,
+  None, None))
 checkobject(bundlerepo.bundlepeer(dummyrepo()))
 checkobject(statichttprepo.statichttppeer(dummyrepo()))
 checkobject(unionrepo.unionpeer(dummyrepo()))
diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -326,7 +326,7 @@
 if not caps:
 badresponse()
 
-return caps
+return protoname, caps
 
 class sshv1peer(wireproto.wirepeer):
 def __init__(self, ui, url, proc, stdin, stdout, stderr, caps):
@@ -497,6 +497,12 @@
 self._pipeo.flush()
 self._readerr()
 
+class sshv2peer(sshv1peer):
+"""A peer that speakers version 2 of the transport protocol."""
+# Currently version 2 is identical to version 1 post handshake.
+# And handshake is performed before the peer is instantiated. So
+# we need no custom code.
+
 def instance(ui, path, create):
 """Create an SSH peer.
 
@@ -532,9 +538,16 @@
   remotepath, sshenv)
 
 try:
-caps = _performhandshake(ui, stdin, stdout, stderr)
+protoname, caps = _performhandshake(ui, stdin, stdout, stderr)
 except Exception:
 _cleanuppipes(ui, stdout, stdin, stderr)
 raise
 
-return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps)
+if protoname == wireprotoserver.SSHV1:
+return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps)
+elif protoname == wireprotoserver.SSHV2:
+return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps)
+else:
+_cleanuppipes(ui, stdout, stdin, stderr)
+raise error.RepoError(_('unknown version of SSH protocol: %s') %
+  protoname)



To: indygreg, #hg-reviewers, durin42
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2063: sshpeer: implement peer for version 2 of wire protocol

2018-02-06 Thread indygreg (Gregory Szorc)
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Since the protocol is now negotiated before we construct a
  peer instance, we can return the negotiated protocol from the
  handshake function and instantiate an appropriate peer class
  for the protocol.
  
  Version 2 of the SSH protocol is currently identical to version
  1 post handshake. So our sshv2peer class just inherits from
  sshv1peer for the time being. This will obviously change
  over time.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2063

AFFECTED FILES
  mercurial/sshpeer.py
  tests/test-check-interfaces.py

CHANGE DETAILS

diff --git a/tests/test-check-interfaces.py b/tests/test-check-interfaces.py
--- a/tests/test-check-interfaces.py
+++ b/tests/test-check-interfaces.py
@@ -67,6 +67,8 @@
 checkobject(localrepo.localpeer(dummyrepo()))
 checkobject(sshpeer.sshv1peer(ui, 'ssh://localhost/foo', None, None, None,
   None, None))
+checkobject(sshpeer.sshv2peer(ui, 'ssh://localhost/foo', None, None, None,
+  None, None))
 checkobject(bundlerepo.bundlepeer(dummyrepo()))
 checkobject(statichttprepo.statichttppeer(dummyrepo()))
 checkobject(unionrepo.unionpeer(dummyrepo()))
diff --git a/mercurial/sshpeer.py b/mercurial/sshpeer.py
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -326,7 +326,7 @@
 if not caps:
 badresponse()
 
-return caps
+return protoname, caps
 
 class sshv1peer(wireproto.wirepeer):
 def __init__(self, ui, url, proc, stdin, stdout, stderr, caps):
@@ -497,6 +497,12 @@
 self._pipeo.flush()
 self._readerr()
 
+class sshv2peer(sshv1peer):
+"""A peer that speakers version 2 of the transport protocol."""
+# Currently version 2 is identical to version 1 post handshake.
+# And handshake is performed before the peer is instantiated. So
+# we need no custom code.
+
 def instance(ui, path, create):
 """Create an SSH peer.
 
@@ -532,9 +538,16 @@
   remotepath, sshenv)
 
 try:
-caps = _performhandshake(ui, stdin, stdout, stderr)
+protoname, caps = _performhandshake(ui, stdin, stdout, stderr)
 except Exception:
 _cleanuppipes(ui, stdout, stdin, stderr)
 raise
 
-return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps)
+if protoname == wireprotoserver.SSHV1:
+return sshv1peer(ui, path, proc, stdin, stdout, stderr, caps)
+elif protoname == wireprotoserver.SSHV2:
+return sshv2peer(ui, path, proc, stdin, stdout, stderr, caps)
+else:
+_cleanuppipes(ui, stdout, stdin, stderr)
+raise error.RepoError(_('unknown version of SSH protocol: %s') %
+  protoname)



To: indygreg, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel