Refactor RDP proxy handling and update related tests
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package fabricproto
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUnsupportedSessionFrame = errors.New("unsupported fabric session frame")
|
||||
@@ -62,6 +65,7 @@ func (s *Session) HandleFrame(frame Frame) (SessionEvent, []Frame, error) {
|
||||
TrafficClass: frame.TrafficClass,
|
||||
StreamID: frame.StreamID,
|
||||
Sequence: frame.Sequence,
|
||||
Payload: DataAckPayload(frame.Payload),
|
||||
}}, nil
|
||||
case FrameAck:
|
||||
if err := s.Ack(frame.StreamID, frame.Sequence); err != nil {
|
||||
@@ -103,6 +107,11 @@ func (s *Session) HandleFrame(frame Frame) (SessionEvent, []Frame, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func DataAckPayload(payload []byte) []byte {
|
||||
sum := sha256.Sum256(payload)
|
||||
return sum[:]
|
||||
}
|
||||
|
||||
func (s *Session) handleDataFrame(frame Frame) (SessionEvent, error) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package fabricproto
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
@@ -36,6 +37,9 @@ func TestHandleFrameOpensStreamAndReceivesData(t *testing.T) {
|
||||
if len(responses) != 1 || responses[0].Type != FrameAck || responses[0].StreamID != 7 || responses[0].Sequence != 11 {
|
||||
t.Fatalf("responses = %+v, want ack for stream 7 seq 11", responses)
|
||||
}
|
||||
if !bytes.Equal(responses[0].Payload, DataAckPayload([]byte("rdp-input"))) {
|
||||
t.Fatalf("ack checksum = %x, want sha256 payload checksum", responses[0].Payload)
|
||||
}
|
||||
snapshot := session.Snapshot()
|
||||
if snapshot.FramesReceived != 1 || snapshot.Streams[7].Received != 1 {
|
||||
t.Fatalf("received metrics = %+v stream=%+v", snapshot, snapshot.Streams[7])
|
||||
|
||||
Reference in New Issue
Block a user