http2

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2025 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodecProtobuf = iota
	CodecOther
)
View Source
const (
	HeaderSize            = 9
	LengthSize            = 3
	ConnectionPrefaceSize = 24
	StreamArraySize       = 10000
	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 MaxWindowSize = 65536
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) Reverse added in v0.2.6

func (d *DirectConn) Reverse() DirectConn

func (*DirectConn) String

func (d *DirectConn) String() string

type FilePBFinder added in v0.2.8

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

func NewFilePBFinder added in v0.2.8

func NewFilePBFinder(protoFiles []string) *FilePBFinder

func (*FilePBFinder) Get added in v0.2.8

func (f *FilePBFinder) Get(svcAndMethod string) (*MethodInputOutput, error)

func (*FilePBFinder) GetDescriptorSource added in v0.2.8

func (f *FilePBFinder) GetDescriptorSource() grpcurl.DescriptorSource

type FrameBase

type FrameBase struct {
	DirectConn DirectConn
	// input or output ?
	InputFlag bool

	StreamID uint32
	Type     uint8
	Flags    uint8
	Length   uint32
	Payload  []byte
}

Frame Header

func ParseFrameBase

func ParseFrameBase(b []byte, dc DirectConn, inputFlag bool) (*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 HTTPItem added in v0.2.6

type HTTPItem struct {
	EndHeader bool
	EndStream bool

	Headers *sync.Map `json:"headers"`
	Method  string    `json:"method"`

	DataBuf *bytes.Buffer `json:"-"`
}

func NewHTTPItem added in v0.2.6

func NewHTTPItem() *HTTPItem

func (*HTTPItem) Reset added in v0.2.6

func (item *HTTPItem) Reset()

type Http2Conn

type Http2Conn struct {
	DirectConn DirectConn

	Streams [StreamArraySize]*Stream
	// ###### for input ######
	Input *MessageParser
	// ###### for output ######
	Output *MessageParser

	Processor          *Processor
	RecordResponse     bool
	MaxHeaderStringLen uint32
}

http2 connection context

func NewHttp2Conn

func NewHttp2Conn(conn DirectConn, maxDynamicTableSize uint32, p *Processor) *Http2Conn

func (*Http2Conn) DealInput added in v0.2.6

func (hc *Http2Conn) DealInput()

func (*Http2Conn) DealOutput added in v0.2.6

func (hc *Http2Conn) DealOutput()

func (*Http2Conn) ProcessFrame added in v0.2.1

func (hc *Http2Conn) ProcessFrame(f *FrameBase)

type MessageParser added in v0.2.6

type MessageParser struct {
	TCPBuffer           *TCPBuffer
	MaxDynamicTableSize uint32
	HeaderDecoder       *hpack.Decoder
}

func NewMessageParser added in v0.2.6

func NewMessageParser(maxDynamicTableSize uint32) *MessageParser

type MethodInputOutput added in v0.2.6

type MethodInputOutput struct {
	InType  proto.Message
	OutType proto.Message
}

func Find added in v0.2.8

func Find(ds grpcurl.DescriptorSource, svcAndMethod string) (*MethodInputOutput, error)

type NetPkg

type NetPkg struct {
	SrcIP string
	DstIP string

	Ethernet  *layers.Ethernet
	IPv4      *layers.IPv4
	IPv6      *layers.IPv6
	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 PBFinder added in v0.2.6

type PBFinder interface {
	// svcAndMethod looks like"/helloworld.Greeter/SayHello"
	Get(svcAndMethod string) (*MethodInputOutput, error)
	GetDescriptorSource() grpcurl.DescriptorSource
}

type Processor

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

func NewProcessor

func NewProcessor(input chan *NetPkg, recordResponse bool, finder PBFinder) *Processor

func (*Processor) ProcessIncomingTCPPkg added in v0.2.6

func (p *Processor) ProcessIncomingTCPPkg(pkg *NetPkg)

func (*Processor) ProcessOutComingTCPPkg added in v0.2.6

func (p *Processor) ProcessOutComingTCPPkg(pkg *NetPkg)

func (*Processor) ProcessTCPPkg

func (p *Processor) ProcessTCPPkg()

type ReflectionPBFinder added in v0.2.6

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

func NewReflectionPBFinder added in v0.2.6

func NewReflectionPBFinder(addr string) *ReflectionPBFinder

func (*ReflectionPBFinder) Get added in v0.2.6

func (f *ReflectionPBFinder) Get(svcAndMethod string) (*MethodInputOutput, error)

func (*ReflectionPBFinder) GetDescriptorSource added in v0.2.8

func (f *ReflectionPBFinder) GetDescriptorSource() grpcurl.DescriptorSource

type Stream

type Stream struct {
	StreamID       uint32
	RecordResponse bool
	Request        *HTTPItem
	Response       *HTTPItem
}

func NewStream

func NewStream(recordResponse bool) *Stream

func (*Stream) Reset

func (s *Stream) Reset()

type TCPBuffer added in v0.2.1

type TCPBuffer struct {
	List *skiplist.SkipList
	// contains filtered or unexported fields
}

func NewTCPBuffer added in v0.2.1

func NewTCPBuffer() *TCPBuffer

func (*TCPBuffer) AddTCP added in v0.2.1

func (sb *TCPBuffer) AddTCP(tcpPkg *layers.TCP)

func (*TCPBuffer) Close added in v0.2.2

func (sb *TCPBuffer) Close()

func (*TCPBuffer) Read added in v0.2.1

func (sb *TCPBuffer) Read(p []byte) (n int, err error)

may block

Jump to

Keyboard shortcuts

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