kubeshark/tap/tlstapper/tls_reader.go
David Levanon 57f8a8dca9
Feature/fix tls not listening (#1046)
* avoid chunks with invalid address

* tls tapper should distict between pids

* prettfy tls verbose log and tls key

* support tls from multi threads + duplicate calls to the same target

* introduce fdCache and user address pair as tls key

* remove unused comment

* fix merge conflicts

* use lru for fdcache

* pr fixes - renaming

* fix conflict issue
2022-05-02 21:33:26 +03:00

101 lines
1.7 KiB
Go

package tlstapper
import (
"io"
"time"
"github.com/up9inc/mizu/tap/api"
)
type tlsReader struct {
key string
chunks chan *tlsChunk
seenChunks int
data []byte
doneHandler func(r *tlsReader)
progress *api.ReadProgress
tcpID *api.TcpID
isClient bool
captureTime time.Time
extension *api.Extension
emitter api.Emitter
counterPair *api.CounterPair
parent *tlsStream
reqResMatcher api.RequestResponseMatcher
}
func (r *tlsReader) newChunk(chunk *tlsChunk) {
r.captureTime = time.Now()
r.seenChunks = r.seenChunks + 1
r.chunks <- chunk
}
func (r *tlsReader) Read(p []byte) (int, error) {
var chunk *tlsChunk
for len(r.data) == 0 {
var ok bool
select {
case chunk, ok = <-r.chunks:
if !ok {
return 0, io.EOF
}
r.data = chunk.getRecordedData()
case <-time.After(time.Second * 3):
r.doneHandler(r)
return 0, io.EOF
}
if len(r.data) > 0 {
break
}
}
l := copy(p, r.data)
r.data = r.data[l:]
r.progress.Feed(l)
return l, nil
}
func (r *tlsReader) GetReqResMatcher() api.RequestResponseMatcher {
return r.reqResMatcher
}
func (r *tlsReader) GetIsClient() bool {
return r.isClient
}
func (r *tlsReader) GetReadProgress() *api.ReadProgress {
return r.progress
}
func (r *tlsReader) GetParent() api.TcpStream {
return r.parent
}
func (r *tlsReader) GetTcpID() *api.TcpID {
return r.tcpID
}
func (r *tlsReader) GetCounterPair() *api.CounterPair {
return r.counterPair
}
func (r *tlsReader) GetCaptureTime() time.Time {
return r.captureTime
}
func (r *tlsReader) GetEmitter() api.Emitter {
return r.emitter
}
func (r *tlsReader) GetIsClosed() bool {
return false
}
func (r *tlsReader) GetExtension() *api.Extension {
return r.extension
}