Bladeren bron

go.crypto/ssh: Increase window size.

Increase window size for channels (session and tcpip) to 64 *
max packet size (32 KB), which is the same value that OpenSSH
uses. Also breaks out the relevant harcoded constants into named
constants in channel.go.

Fixes golang/go#6675.

R=golang-dev, dave, hanwen, agl
CC=golang-dev
https://golang.org/cl/18120043
Jakob Borg 12 jaren geleden
bovenliggende
commit
4758fe8ce4
4 gewijzigde bestanden met toevoegingen van 14 en 10 verwijderingen
  1. 6 0
      ssh/channel.go
  2. 4 6
      ssh/client.go
  3. 2 2
      ssh/session.go
  4. 2 2
      ssh/tcpip.go

+ 6 - 0
ssh/channel.go

@@ -22,6 +22,12 @@ const (
 
 	// minPacketLength defines the smallest valid packet
 	minPacketLength = 9
+
+	// channelMaxPacketSize defines the maximum packet size advertised in open messages
+	channelMaxPacketSize = 1 << 15 // RFC 4253 6.1, minimum 32 KiB
+
+	// channelWindowSize defines the window size advertised in open messages
+	channelWindowSize = 64 * channelMaxPacketSize // Like OpenSSH
 )
 
 // A Channel is an ordered, reliable, duplex stream that is multiplexed over an

+ 4 - 6
ssh/client.go

@@ -356,12 +356,10 @@ func (c *ClientConn) handleChanOpen(msg *channelOpenMsg) {
 		ch.maxPacket = msg.MaxPacketSize
 
 		m := channelOpenConfirmMsg{
-			PeersId:  ch.remoteId,
-			MyId:     ch.localId,
-			MyWindow: 1 << 14,
-
-			// As per RFC 4253 6.1, 32k is also the minimum.
-			MaxPacketSize: 1 << 15,
+			PeersId:       ch.remoteId,
+			MyId:          ch.localId,
+			MyWindow:      channelWindowSize,
+			MaxPacketSize: channelMaxPacketSize,
 		}
 
 		c.transport.writePacket(marshal(msgChannelOpenConfirm, m))

+ 2 - 2
ssh/session.go

@@ -567,8 +567,8 @@ func (c *ClientConn) NewSession() (*Session, error) {
 	if err := c.transport.writePacket(marshal(msgChannelOpen, channelOpenMsg{
 		ChanType:      "session",
 		PeersId:       ch.localId,
-		PeersWindow:   1 << 14,
-		MaxPacketSize: 1 << 15, // RFC 4253 6.1
+		PeersWindow:   channelWindowSize,
+		MaxPacketSize: channelMaxPacketSize,
 	})); err != nil {
 		c.chanList.remove(ch.localId)
 		return nil, err

+ 2 - 2
ssh/tcpip.go

@@ -299,8 +299,8 @@ func (c *ClientConn) dial(laddr string, lport int, raddr string, rport int) (*tc
 	if err := c.transport.writePacket(marshal(msgChannelOpen, channelOpenDirectMsg{
 		ChanType:      "direct-tcpip",
 		PeersId:       ch.localId,
-		PeersWindow:   1 << 14,
-		MaxPacketSize: 1 << 15, // RFC 4253 6.1
+		PeersWindow:   channelWindowSize,
+		MaxPacketSize: channelMaxPacketSize,
 		raddr:         raddr,
 		rport:         uint32(rport),
 		laddr:         laddr,