http2

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodecProtobuf = iota
	CodecOther
)
View Source
const (
	HeaderSize            = 9
	LengthSize            = 3
	ConnectionPrefaceSize = 24
	StreamArraySize       = 1000
	SettingFormatItemSize = 48
)
View Source
const (
	DirUnknown = iota
	DirIncoming
	DirOutcoming
)
View Source
const (
	PrefaceEarly = "FOO * HTTP/2.0\r\n\r\nBA\r\n\r\n"
	PrefaceSTD   = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"
)
View Source
const (
	FrameTypeData         = 0x0
	FrameTypeHeader       = 0x1
	FrameTypePriority     = 0x2
	FrameTypeRSTStream    = 0x3
	FrameTypeSetting      = 0x4
	FrameTypePushPromise  = 0x5
	FrameTypePing         = 0x6
	FrameTypeGoAway       = 0x7
	FrameTypeWindowUpdate = 0x8
	FrameTypeContinuation = 0x9
)
View Source
const (
	PseudoHeaderPath = ":path"
)

Variables

View Source
var DirStr map[Dir]string
View Source
var FrameTypeStr map[uint8]string

Functions

func GetDirection

func GetDirection(d Dir) string

func GetFrameType

func GetFrameType(t uint8) string

func IsConnPreface

func IsConnPreface(payload []byte) bool

Types

type ConnSet

type ConnSet struct {
	// contains filtered or unexported fields
}

func NewConnSet

func NewConnSet() *ConnSet

func (*ConnSet) Add

func (set *ConnSet) Add(c DirectConn)

func (*ConnSet) AddAll

func (set *ConnSet) AddAll(cons []DirectConn)

func (*ConnSet) Clone

func (set *ConnSet) Clone() *ConnSet

func (*ConnSet) Has

func (set *ConnSet) Has(c DirectConn) bool

func (*ConnSet) Intersection

func (set *ConnSet) Intersection(set2 *ConnSet) *ConnSet

func (*ConnSet) Remove

func (set *ConnSet) Remove(c DirectConn)

func (*ConnSet) RemoveAll

func (set *ConnSet) RemoveAll(other *ConnSet)

func (*ConnSet) Size

func (set *ConnSet) Size() int

func (*ConnSet) String

func (set *ConnSet) String() string

func (*ConnSet) ToArray

func (set *ConnSet) ToArray() []DirectConn

type Dir

type Dir uint8

type DirectConn

type DirectConn struct {
	SrcAddr psnet.Addr
	DstAddr psnet.Addr
}

func (*DirectConn) String

func (d *DirectConn) String() string

type FrameBase

type FrameBase struct {
	DirectConn *DirectConn
	StreamID   uint32
	Type       uint8
	Flags      uint8
	Length     uint32
	Payload    []byte
}

帧头部

func ParseFrameBase

func ParseFrameBase(b []byte) (*FrameBase, error)

type FrameContinuation

type FrameContinuation struct {
	EndHeader           bool
	HeaderBlockFragment []byte
	// contains filtered or unexported fields
}

func ParseFrameContinuation

func ParseFrameContinuation(f *FrameBase) (*FrameContinuation, error)

type FrameData

type FrameData struct {
	EndStream bool
	Padded    bool
	// Frame Payload
	PadLength uint8
	Data      []byte
	// contains filtered or unexported fields
}

func ParseFrameData

func ParseFrameData(f *FrameBase) (*FrameData, error)

func (*FrameData) ParseGRPCMessage

func (fd *FrameData) ParseGRPCMessage() (*GRPCMessage, error)

type FrameHeader

type FrameHeader struct {
	EndStream bool
	EndHeader bool
	Padded    bool
	// I don't care
	Priority bool
	// Frame Payload
	PadLength           uint8
	HeaderBlockFragment []byte
	// contains filtered or unexported fields
}

func ParseFrameHeader

func ParseFrameHeader(f *FrameBase) (*FrameHeader, error)

type FrameSetting

type FrameSetting struct {
	Ack bool
	// contains filtered or unexported fields
}

func ParseFrameSetting

func ParseFrameSetting(f *FrameBase) (*FrameSetting, error)

type GRPCMessage

type GRPCMessage struct {
	// ------ complete gRPC Message------
	// https://github.com/grpc/grpc-go/blob/master/Documentation/encoding.md
	//	gRPC lets you use encoders other than Protobuf.
	//  gRPC is compatible with JSON, Thrift, Avro, Flatbuffers, Cap’n Proto, and even raw bytes!
	/*
				+--------------------+
				|  payloadFormat(8)  |
				+--------------------+------------------------------------------+
				|                          length(32)                           |
				+---------------------------------------------------------------+
				|                        encodedMessage(*)                  ... |
				+---------------------------------------------------------------+
			   payloadFormat: compressed or not?
		       encodedMessage: Protobuf,JSON,Thrift,etc.
	*/
	PayloadFormat  payloadFormat
	Length         uint32
	EncodedMessage []byte
}

type Http2Conn

type Http2Conn struct {
	DirectConn          DirectConn
	MaxDynamicTableSize uint32
	MaxHeaderStringLen  uint32
	HeaderDecoder       *hpack.Decoder
	Streams             [StreamArraySize]*Stream
}

http2 connection context

func NewHttp2Conn

func NewHttp2Conn(conn DirectConn, maxDynamicTableSize uint32) *Http2Conn

type NetPkg

type NetPkg struct {
	IP        *layers.IPv4
	TCP       *layers.TCP
	Direction Dir
}

func ProcessPacket

func ProcessPacket(packet gopacket.Packet, ipSet *util.StringSet, port int) (*NetPkg, error)

func (*NetPkg) DirectConn

func (p *NetPkg) DirectConn() DirectConn

func (*NetPkg) TCPFlags

func (p *NetPkg) TCPFlags() []string

type PBMessageFinder

type PBMessageFinder struct {
	// contains filtered or unexported fields
}

func NewPBMessageFinder

func NewPBMessageFinder(addr string) *PBMessageFinder

func (*PBMessageFinder) FindMethodInput

func (f *PBMessageFinder) FindMethodInput(svcAndMethod string) proto.Message

type Processor

type Processor struct {
	ConnRepository map[DirectConn]*Http2Conn
	InputChan      chan *NetPkg
	OutputChan     chan *protocol.Message
	Finder         *PBMessageFinder
}

func NewProcessor

func NewProcessor(input chan *NetPkg, svcAddr string) *Processor

func (*Processor) ProcessFrame

func (p *Processor) ProcessFrame(f *FrameBase)

func (*Processor) ProcessTCPPkg

func (p *Processor) ProcessTCPPkg()

type Stream

type Stream struct {
	StreamID  uint32
	EndHeader bool
	EndStream bool
	Headers   map[string]string `json:"headers"`
	Method    string            `json:"method"`
	// json序列化后的结果
	Request []byte `json:"request"`
}

func NewStream

func NewStream() *Stream

func (*Stream) Reset

func (s *Stream) Reset()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL