crypto_stream.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package gquic
  2. import (
  3. "io"
  4. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/quic/gquic-go/internal/flowcontrol"
  5. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/quic/gquic-go/internal/protocol"
  6. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/quic/gquic-go/internal/wire"
  7. )
  8. type cryptoStream interface {
  9. StreamID() protocol.StreamID
  10. io.Reader
  11. io.Writer
  12. handleStreamFrame(*wire.StreamFrame) error
  13. hasData() bool
  14. popStreamFrame(protocol.ByteCount) (*wire.StreamFrame, bool)
  15. closeForShutdown(error)
  16. setReadOffset(protocol.ByteCount)
  17. // methods needed for flow control
  18. getWindowUpdate() protocol.ByteCount
  19. handleMaxStreamDataFrame(*wire.MaxStreamDataFrame)
  20. }
  21. type cryptoStreamImpl struct {
  22. *stream
  23. }
  24. var _ cryptoStream = &cryptoStreamImpl{}
  25. func newCryptoStream(sender streamSender, flowController flowcontrol.StreamFlowController, version protocol.VersionNumber) cryptoStream {
  26. str := newStream(version.CryptoStreamID(), sender, flowController, version)
  27. return &cryptoStreamImpl{str}
  28. }
  29. // SetReadOffset sets the read offset.
  30. // It is only needed for the crypto stream.
  31. // It must not be called concurrently with any other stream methods, especially Read and Write.
  32. func (s *cryptoStreamImpl) setReadOffset(offset protocol.ByteCount) {
  33. s.receiveStream.readOffset = offset
  34. s.receiveStream.frameQueue.readPos = offset
  35. }