forked from quic-go/quic-go
move all frames to separate package
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"golang.org/x/net/http2/hpack"
|
"golang.org/x/net/http2/hpack"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go"
|
"github.com/lucas-clemente/quic-go"
|
||||||
|
"github.com/lucas-clemente/quic-go/frames"
|
||||||
"github.com/lucas-clemente/quic-go/protocol"
|
"github.com/lucas-clemente/quic-go/protocol"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleStream(frame *quic.StreamFrame) []quic.Frame {
|
func handleStream(frame *frames.StreamFrame) []frames.Frame {
|
||||||
h2r := bytes.NewReader(frame.Data)
|
h2r := bytes.NewReader(frame.Data)
|
||||||
var reply bytes.Buffer
|
var reply bytes.Buffer
|
||||||
h2framer := http2.NewFramer(&reply, h2r)
|
h2framer := http2.NewFramer(&reply, h2r)
|
||||||
@@ -53,17 +54,17 @@ func handleStream(frame *quic.StreamFrame) []quic.Frame {
|
|||||||
EndHeaders: true,
|
EndHeaders: true,
|
||||||
BlockFragment: replyHeaders.Bytes(),
|
BlockFragment: replyHeaders.Bytes(),
|
||||||
})
|
})
|
||||||
headerStreamFrame := &quic.StreamFrame{
|
headerStreamFrame := &frames.StreamFrame{
|
||||||
StreamID: frame.StreamID,
|
StreamID: frame.StreamID,
|
||||||
Data: reply.Bytes(),
|
Data: reply.Bytes(),
|
||||||
FinBit: true,
|
FinBit: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
dataStreamFrame := &quic.StreamFrame{
|
dataStreamFrame := &frames.StreamFrame{
|
||||||
StreamID: h2frame.Header().StreamID,
|
StreamID: h2frame.Header().StreamID,
|
||||||
Data: []byte("Hello World!"),
|
Data: []byte("Hello World!"),
|
||||||
FinBit: true,
|
FinBit: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
return []quic.Frame{headerStreamFrame, dataStreamFrame}
|
return []frames.Frame{headerStreamFrame, dataStreamFrame}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package quic
|
package frames
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package quic
|
package frames
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package quic
|
package frames
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package quic
|
package frames
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package quic
|
package frames
|
||||||
|
|
||||||
import "bytes"
|
import "bytes"
|
||||||
|
|
||||||
13
frames/frames_suite_test.go
Normal file
13
frames/frames_suite_test.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package frames
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCrypto(t *testing.T) {
|
||||||
|
RegisterFailHandler(Fail)
|
||||||
|
RunSpecs(t, "Frames Suite")
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package quic
|
package frames
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package quic
|
package frames
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package quic
|
package frames
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package quic
|
package frames
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
17
session.go
17
session.go
@@ -6,12 +6,13 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/lucas-clemente/quic-go/frames"
|
||||||
"github.com/lucas-clemente/quic-go/handshake"
|
"github.com/lucas-clemente/quic-go/handshake"
|
||||||
"github.com/lucas-clemente/quic-go/protocol"
|
"github.com/lucas-clemente/quic-go/protocol"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StreamCallback gets a stream frame and returns a reply frame
|
// StreamCallback gets a stream frame and returns a reply frame
|
||||||
type StreamCallback func(*StreamFrame) []Frame
|
type StreamCallback func(*frames.StreamFrame) []frames.Frame
|
||||||
|
|
||||||
// A Session is a QUIC session
|
// A Session is a QUIC session
|
||||||
type Session struct {
|
type Session struct {
|
||||||
@@ -61,7 +62,7 @@ func (s *Session) HandlePacket(addr *net.UDPAddr, publicHeaderBinary []byte, pub
|
|||||||
}
|
}
|
||||||
s.Entropy.Add(publicHeader.PacketNumber, privateFlag&0x01 > 0)
|
s.Entropy.Add(publicHeader.PacketNumber, privateFlag&0x01 > 0)
|
||||||
|
|
||||||
s.SendFrames([]Frame{&AckFrame{
|
s.SendFrames([]frames.Frame{&frames.AckFrame{
|
||||||
LargestObserved: uint64(publicHeader.PacketNumber),
|
LargestObserved: uint64(publicHeader.PacketNumber),
|
||||||
Entropy: s.Entropy.Get(),
|
Entropy: s.Entropy.Get(),
|
||||||
}})
|
}})
|
||||||
@@ -82,7 +83,7 @@ func (s *Session) HandlePacket(addr *net.UDPAddr, publicHeaderBinary []byte, pub
|
|||||||
|
|
||||||
if typeByte&0x80 == 0x80 { // STREAM
|
if typeByte&0x80 == 0x80 { // STREAM
|
||||||
fmt.Println("Detected STREAM")
|
fmt.Println("Detected STREAM")
|
||||||
frame, err := ParseStreamFrame(r)
|
frame, err := frames.ParseStreamFrame(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -98,7 +99,7 @@ func (s *Session) HandlePacket(addr *net.UDPAddr, publicHeaderBinary []byte, pub
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if reply != nil {
|
if reply != nil {
|
||||||
s.SendFrames([]Frame{&StreamFrame{StreamID: 1, Data: reply}})
|
s.SendFrames([]frames.Frame{&frames.StreamFrame{StreamID: 1, Data: reply}})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
replyFrames := s.streamCallback(frame)
|
replyFrames := s.streamCallback(frame)
|
||||||
@@ -109,7 +110,7 @@ func (s *Session) HandlePacket(addr *net.UDPAddr, publicHeaderBinary []byte, pub
|
|||||||
continue
|
continue
|
||||||
} else if typeByte&0xC0 == 0x40 { // ACK
|
} else if typeByte&0xC0 == 0x40 { // ACK
|
||||||
fmt.Println("Detected ACK")
|
fmt.Println("Detected ACK")
|
||||||
frame, err := ParseAckFrame(r)
|
frame, err := frames.ParseAckFrame(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -121,14 +122,14 @@ func (s *Session) HandlePacket(addr *net.UDPAddr, publicHeaderBinary []byte, pub
|
|||||||
return errors.New("Detected CONGESTION_FEEDBACK")
|
return errors.New("Detected CONGESTION_FEEDBACK")
|
||||||
} else if typeByte&0x06 == 0x06 { // STOP_WAITING
|
} else if typeByte&0x06 == 0x06 { // STOP_WAITING
|
||||||
fmt.Println("Detected STOP_WAITING")
|
fmt.Println("Detected STOP_WAITING")
|
||||||
_, err := ParseStopWaitingFrame(r, publicHeader.PacketNumberLen)
|
_, err := frames.ParseStopWaitingFrame(r, publicHeader.PacketNumberLen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// ToDo: react to receiving this frame
|
// ToDo: react to receiving this frame
|
||||||
} else if typeByte&0x02 == 0x02 { // CONNECTION_CLOSE
|
} else if typeByte&0x02 == 0x02 { // CONNECTION_CLOSE
|
||||||
fmt.Println("Detected CONNECTION_CLOSE")
|
fmt.Println("Detected CONNECTION_CLOSE")
|
||||||
frame, err := ParseConnectionCloseFrame(r)
|
frame, err := frames.ParseConnectionCloseFrame(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -144,7 +145,7 @@ func (s *Session) HandlePacket(addr *net.UDPAddr, publicHeaderBinary []byte, pub
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SendFrames sends a number of frames to the client
|
// SendFrames sends a number of frames to the client
|
||||||
func (s *Session) SendFrames(frames []Frame) error {
|
func (s *Session) SendFrames(frames []frames.Frame) error {
|
||||||
var framesData bytes.Buffer
|
var framesData bytes.Buffer
|
||||||
framesData.WriteByte(0) // TODO: entropy
|
framesData.WriteByte(0) // TODO: entropy
|
||||||
for _, f := range frames {
|
for _, f := range frames {
|
||||||
|
|||||||
Reference in New Issue
Block a user