| 87 | } |
| 88 | |
| 89 | func (t *testRPCStream) Send(req *altspb.HandshakerReq) error { |
| 90 | var resp *altspb.HandshakerResp |
| 91 | if !t.first { |
| 92 | // Generate the bytes to be returned by Recv() for the initial |
| 93 | // handshaking. |
| 94 | t.first = true |
| 95 | if t.isClient { |
| 96 | resp = &altspb.HandshakerResp{ |
| 97 | OutFrames: testutil.MakeFrame("ClientInit"), |
| 98 | // Simulate consuming ServerInit. |
| 99 | BytesConsumed: 14, |
| 100 | } |
| 101 | } else { |
| 102 | resp = &altspb.HandshakerResp{ |
| 103 | OutFrames: testutil.MakeFrame("ServerInit"), |
| 104 | // Simulate consuming ClientInit. |
| 105 | BytesConsumed: 14, |
| 106 | } |
| 107 | } |
| 108 | } else { |
| 109 | switch req := req.ReqOneof.(type) { |
| 110 | case *altspb.HandshakerReq_Next: |
| 111 | // Compare the network_latency_ms field to the minimum expected network |
| 112 | // latency. |
| 113 | if nl := time.Duration(req.Next.NetworkLatencyMs) * time.Millisecond; nl < t.minExpectedNetworkLatency { |
| 114 | return fmt.Errorf("networkLatency (%v) is smaller than expected min network latency (%v)", nl, t.minExpectedNetworkLatency) |
| 115 | } |
| 116 | default: |
| 117 | return fmt.Errorf("handshake request has unexpected type: %v", req) |
| 118 | } |
| 119 | |
| 120 | // Add delay to test concurrent calls. |
| 121 | cleanup := stat.Update() |
| 122 | defer cleanup() |
| 123 | time.Sleep(t.delay) |
| 124 | |
| 125 | // Generate the response to be returned by Recv() for the |
| 126 | // follow-up handshaking. |
| 127 | result := &altspb.HandshakerResult{ |
| 128 | RecordProtocol: testRecordProtocol, |
| 129 | KeyData: testKey, |
| 130 | } |
| 131 | resp = &altspb.HandshakerResp{ |
| 132 | Result: result, |
| 133 | // Simulate consuming ClientFinished or ServerFinished. |
| 134 | BytesConsumed: 18, |
| 135 | } |
| 136 | } |
| 137 | t.recvBuf = resp |
| 138 | return nil |
| 139 | } |
| 140 | |
| 141 | func (t *testRPCStream) CloseSend() error { |
| 142 | return nil |