Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POA-155] Changes for capturing client and server timeouts #201

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions akinet/http/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ func (p *httpParser) Name() string {
return "HTTP/1.x Response Parser"
}

func (p *httpParser) ConnectionType() string {
if p.isRequest {
return akinet.CONNECTION_TYPE_HTTP_CLIENT
}
return akinet.CONNECTION_TYPE_HTTP_SERVER
}

func (p *httpParser) Parse(input memview.MemView, isEnd bool) (result akinet.ParsedNetworkContent, unused memview.MemView, totalBytesConsumed int64, err error) {
var consumedBytes int64
defer func() {
Expand Down
4 changes: 4 additions & 0 deletions akinet/http2/parser_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (*http2Sink) Name() string {
return "HTTP/2 sink"
}

func (*http2Sink) ConnectionType() string {
return akinet.CONNECTION_TYPE_HTTP2_PREFACE
}

func (s *http2Sink) Parse(input memview.MemView, isEnd bool) (result akinet.ParsedNetworkContent, unused memview.MemView, totalBytesConsumed int64, err error) {
// Return one event at the start of the stream, so we can count it.
if s.firstInput {
Expand Down
24 changes: 24 additions & 0 deletions akinet/net_traffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,30 @@ func (tls *TLSHandshakeMetadata) ApplicationLatencyMeasurable() bool {
return *tls.SelectedProtocol == "http/1.1"
}

// Represents the content when a TCP connection is closed by the client.
type ClientShutdowntMetadata struct {
// StreamID and Seq uniquely identify a pair of request and response.
StreamID uuid.UUID
Seq int
}

var _ ParsedNetworkContent = (*ClientShutdowntMetadata)(nil)

func (ClientShutdowntMetadata) implParsedNetworkContent() {}
func (ClientShutdowntMetadata) ReleaseBuffers() {}

// Represents the content when a TCP connection is closed by the server.
type ServerShutdownMetadata struct {
// StreamID and Seq uniquely identify a pair of request and response.
StreamID uuid.UUID
Seq int
}

var _ ParsedNetworkContent = (*ServerShutdownMetadata)(nil)

func (ServerShutdownMetadata) implParsedNetworkContent() {}
func (ServerShutdownMetadata) ReleaseBuffers() {}

// Represents an observed HTTP/2 connection preface; no data from it
// is stored.
type HTTP2ConnectionPreface struct {
Expand Down
26 changes: 18 additions & 8 deletions akinet/tcp_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const (
NeedMoreData
)

const (
CONNECTION_TYPE_HTTP_CLIENT = "HTTP_CLIENT"
CONNECTION_TYPE_HTTP_SERVER = "HTTP_SERVER"
CONNECTION_TYPE_TLS_CLIENT = "TLS_CLIENT"
CONNECTION_TYPE_TLS_SERVER = "TLS_SERVER"
CONNECTION_TYPE_HTTP2_PREFACE = "HTTP2_PREFACE"
)
Comment on lines +17 to +23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth having these defined for each protocol type, or should we have only client and server? (Or unknown?)


func (d AcceptDecision) String() string {
switch d {
case Reject:
Expand Down Expand Up @@ -67,6 +75,8 @@ type TCPParserFactory interface {
type TCPParser interface {
Name() string

ConnectionType() string

// Caller should repeatedly supply data from the TCP flow until a non-nil
// result or an error is returned.
//
Expand All @@ -93,16 +103,16 @@ type TCPParserFactorySelector []TCPParserFactory
// SelectFactory selects a TCPParserFactory that suitable for input. The
// possible set of return values:
// - f=nil, decision=Reject, discardFront=len(input)
// - no factory is suitable
// - no factory is suitable
// - f=nil, decision=NeedMoreData, discardFront>=0
// - no factory returned Accept
// - at least one factory requested more data
// - discardFront is the MIN of all the discardFronts returned by
// factories requesting more data
// - no factory returned Accept
// - at least one factory requested more data
// - discardFront is the MIN of all the discardFronts returned by
// factories requesting more data
// - f!=nil, decision=Accept, discardFront>=0
// - a factory has been selected
// - caller must discard discardFront number of bytes from input before
// feeding input to the parser generated by the factory.
// - a factory has been selected
// - caller must discard discardFront number of bytes from input before
// feeding input to the parser generated by the factory.
func (s TCPParserFactorySelector) Select(input memview.MemView, isEnd bool) (f TCPParserFactory, decision AcceptDecision, discardFront int64) {
discardFront = -1
allReject := true
Expand Down
4 changes: 4 additions & 0 deletions akinet/tls/client_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func (*tlsClientHelloParser) Name() string {
return "TLS 1.2/1.3 Client-Hello Parser"
}

func (*tlsClientHelloParser) ConnectionType() string {
return akinet.CONNECTION_TYPE_TLS_CLIENT
}

func (parser *tlsClientHelloParser) Parse(input memview.MemView, isEnd bool) (result akinet.ParsedNetworkContent, unused memview.MemView, totalBytesConsumed int64, err error) {
result, numBytesConsumed, err := parser.parse(input)
// It's an error if we're at the end and we don't yet have a result.
Expand Down
4 changes: 4 additions & 0 deletions akinet/tls/server_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func (*tlsServerHelloParser) Name() string {
return "TLS 1.2/1.3 Server-Hello Parser"
}

func (*tlsServerHelloParser) ConnectionType() string {
return akinet.CONNECTION_TYPE_TLS_SERVER
}

func (parser *tlsServerHelloParser) Parse(input memview.MemView, isEnd bool) (result akinet.ParsedNetworkContent, unused memview.MemView, totalBytesConsumed int64, err error) {
result, numBytesConsumed, err := parser.parse(input)
// It's an error if we're at the end and we don't yet have a result.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/OneOfOne/xxhash v1.2.8
github.com/akitasoftware/akita-ir v0.0.0-20220630210013-8926783978fe
github.com/akitasoftware/akita-ir v0.0.0-20231103112405-e2221503d639 // todo: update this to match the commit on master once akita-ir#10 is merged
github.com/akitasoftware/go-utils v0.0.0-20221207014235-6f4c9079488d
github.com/akitasoftware/objecthash-proto v0.0.0-20211020004800-9990a7ea5dc0
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/akitasoftware/akita-ir v0.0.0-20220630210013-8926783978fe h1:0BeBDjLDFPwv2bkk6YuRAPf1r6U4Wby98NHI9+Lddvs=
github.com/akitasoftware/akita-ir v0.0.0-20220630210013-8926783978fe/go.mod h1:WEWPzhZtxlJnov3MxcqSDiZaHHf00vs3aJwCdt3OwzA=
github.com/akitasoftware/akita-ir v0.0.0-20231102193917-8b96486d4377 h1:AaUu5pd9GnOZptkkhoFrWJUivv+2+s/zmKHVOGItsrg=
github.com/akitasoftware/akita-ir v0.0.0-20231102193917-8b96486d4377/go.mod h1:WEWPzhZtxlJnov3MxcqSDiZaHHf00vs3aJwCdt3OwzA=
github.com/akitasoftware/akita-ir v0.0.0-20231103112405-e2221503d639 h1:hIWGdk/RJGbvfLA2pODQLn8lAygHXEQLZN3VuIrkCHU=
github.com/akitasoftware/akita-ir v0.0.0-20231103112405-e2221503d639/go.mod h1:WEWPzhZtxlJnov3MxcqSDiZaHHf00vs3aJwCdt3OwzA=
github.com/akitasoftware/go-utils v0.0.0-20221207014235-6f4c9079488d h1:pN1dbNacZ/mvlU1NcJVDxqmKnrDQDTVaN6iKOarfdYM=
github.com/akitasoftware/go-utils v0.0.0-20221207014235-6f4c9079488d/go.mod h1:+IOXf7l/QCAQECJzjJwhTp1sBkRoJ6WciZwJezUwBa4=
github.com/akitasoftware/gopacket v1.1.18-0.20210730205736-879e93dac35b h1:toBhS5rhCjo/N4YZ1cYtlsdSTGjMFH+gbJGCc+OmZiY=
Expand Down
1 change: 1 addition & 0 deletions spec_util/ir_hash/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func main() {
gf.AddHashFunc(reflect.TypeOf(pb.HTTPHeader{}))
gf.AddHashFunc(reflect.TypeOf(pb.HTTPMeta{}))
gf.AddHashFunc(reflect.TypeOf(pb.HTTPMethodMeta{}))
gf.AddHashFunc(reflect.TypeOf(pb.HTTPMethodError{}))
gf.AddHashFunc(reflect.TypeOf(pb.HTTPMultipart{}))
gf.AddHashFunc(reflect.TypeOf(pb.HTTPPath{}))
gf.AddHashFunc(reflect.TypeOf(pb.HTTPQuery{}))
Expand Down
24 changes: 23 additions & 1 deletion spec_util/ir_hash/generated_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,19 @@ func HashHTTPMethodMeta(node *pb.HTTPMethodMeta) []byte {
}
return hash.Sum(nil)
}
func HashHTTPMethodError(node *pb.HTTPMethodError) []byte {
hash := xxhash.New64()
hash.Write([]byte("d"))
if node.Type != 0 {
hash.Write(intHashes[1])
hash.Write(Hash_Int32(int32(node.Type)))
}
if node.Message != "" {
hash.Write(intHashes[2])
hash.Write(Hash_Unicode(node.Message))
}
return hash.Sum(nil)
}
func HashHTTPMultipart(node *pb.HTTPMultipart) []byte {
hash := xxhash.New64()
hash.Write([]byte("d"))
Expand Down Expand Up @@ -621,6 +634,15 @@ func HashMethodMeta(node *pb.MethodMeta) []byte {
hash.Write(intHashes[2])
hash.Write(HashHTTPMethodMeta(val.Http))
}
if len(node.Errors) != 0 {
hash.Write(intHashes[3])
listHash := xxhash.New64()
listHash.Write([]byte("l"))
for _, v := range node.Errors {
listHash.Write(HashHTTPMethodError(v))
}
hash.Write(listHash.Sum(nil))
}
return hash.Sum(nil)
}
func HashNone(node *pb.None) []byte {
Expand Down Expand Up @@ -897,4 +919,4 @@ func HashWitness(node *pb.Witness) []byte {
return hash.Sum(nil)
}

var ProtobufFileHashes map[string][]byte = map[string][]byte{"method.proto": []byte{69, 16, 236, 176, 97, 180, 164, 70}, "witness.proto": []byte{42, 213, 185, 25, 124, 226, 76, 187}, "types.proto": []byte{98, 84, 34, 180, 249, 140, 214, 227}, "spec.proto": []byte{13, 101, 129, 126, 232, 252, 1, 146}}
var ProtobufFileHashes map[string][]byte = map[string][]byte{"method.proto": []byte{177, 245, 189, 217, 244, 231, 2, 63}, "witness.proto": []byte{42, 213, 185, 25, 124, 226, 76, 187}, "types.proto": []byte{98, 84, 34, 180, 249, 140, 214, 227}, "spec.proto": []byte{13, 101, 129, 126, 232, 252, 1, 146}}