s6.5.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2019 The gRPC Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package http2interop
  15. import (
  16. "fmt"
  17. "time"
  18. )
  19. // Section 6.5 says the minimum SETTINGS_MAX_FRAME_SIZE is 16,384
  20. func testSmallMaxFrameSize(ctx *HTTP2InteropCtx) error {
  21. conn, err := connect(ctx)
  22. if err != nil {
  23. return err
  24. }
  25. defer conn.Close()
  26. conn.SetDeadline(time.Now().Add(defaultTimeout))
  27. sf := &SettingsFrame{
  28. Params: []SettingsParameter{{
  29. Identifier: SettingsMaxFrameSize,
  30. Value: 1<<14 - 1, // 1 less than the smallest maximum
  31. }},
  32. }
  33. if err := http2Connect(conn, sf); err != nil {
  34. return err
  35. }
  36. if _, err := expectGoAwaySoon(conn); err != nil {
  37. return err
  38. }
  39. return nil
  40. }
  41. // Section 6.5.3 says all settings frames must be acked.
  42. func testAllSettingsFramesAcked(ctx *HTTP2InteropCtx) error {
  43. conn, err := connect(ctx)
  44. if err != nil {
  45. return err
  46. }
  47. defer conn.Close()
  48. conn.SetDeadline(time.Now().Add(defaultTimeout))
  49. sf := &SettingsFrame{}
  50. if err := http2Connect(conn, sf); err != nil {
  51. return err
  52. }
  53. // The spec says "The values in the SETTINGS frame MUST be processed in the order they
  54. // appear. [...] Once all values have been processed, the recipient MUST immediately
  55. // emit a SETTINGS frame with the ACK flag set." From my understanding, processing all
  56. // of no values warrants an ack per frame.
  57. for i := 0; i < 10; i++ {
  58. if err := streamFrame(conn, sf); err != nil {
  59. return err
  60. }
  61. }
  62. var settingsFramesReceived = 0
  63. // The server by default sends a settings frame as part of the handshake, and another
  64. // after the receipt of the initial settings frame as part of our connection preface.
  65. // This means we expected 1 + 1 + 10 = 12 settings frames in return, with all but the
  66. // first having the ack bit.
  67. for settingsFramesReceived < 12 {
  68. f, err := parseFrame(conn)
  69. if err != nil {
  70. return err
  71. }
  72. // Other frames come down the wire too, including window update. Just ignore those.
  73. if f, ok := f.(*SettingsFrame); ok {
  74. settingsFramesReceived += 1
  75. if settingsFramesReceived == 1 {
  76. if f.Header.Flags&SETTINGS_FLAG_ACK > 0 {
  77. return fmt.Errorf("settings frame should not have used ack: %v", f)
  78. }
  79. continue
  80. }
  81. if f.Header.Flags&SETTINGS_FLAG_ACK == 0 {
  82. return fmt.Errorf("settings frame should have used ack: %v", f)
  83. }
  84. if len(f.Params) != 0 {
  85. return fmt.Errorf("settings ack cannot have params: %v", f)
  86. }
  87. }
  88. }
  89. return nil
  90. }