crypto_stream.go 1.2 KB

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