mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-10-22 07:51:30 +00:00
* Use log in tap package instead of fmt. * Moved api/pkg/tap to root. * Added go.mod and go.sum for tap. * Added replace for shared. * api uses tap module instead of tap package. * Removed dependency of tap in shared by moving env var out of tap. * Fixed compilation bugs. * Fixed: Forgot to export struct field HostMode. * Removed unused flag. * Close har output channel when done. * Moved websocket out of mizu and into passive-tapper. * Send connection details over har output channel. * Fixed compilation errors. * Removed unused info from request response cache. * Renamed connection -> connectionID. * Fixed rename bug. * Export setters and getters for filter ips and ports. * Added tap dependency to Dockerfile. * Uncomment error messages. * Renamed `filterIpAddresses` -> `filterAuthorities`. * Renamed ConnectionID -> ConnectionInfo. * Fixed: Missed one replace.
70 lines
1.2 KiB
Go
70 lines
1.2 KiB
Go
package tap
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/google/gopacket/reassembly"
|
|
)
|
|
|
|
type CleanerStats struct {
|
|
flushed int
|
|
closed int
|
|
deleted int
|
|
}
|
|
|
|
type Cleaner struct {
|
|
assembler *reassembly.Assembler
|
|
assemblerMutex *sync.Mutex
|
|
matcher *requestResponseMatcher
|
|
cleanPeriod time.Duration
|
|
connectionTimeout time.Duration
|
|
stats CleanerStats
|
|
statsMutex sync.Mutex
|
|
}
|
|
|
|
func (cl *Cleaner) clean() {
|
|
startCleanTime := time.Now()
|
|
|
|
cl.assemblerMutex.Lock()
|
|
flushed, closed := cl.assembler.FlushCloseOlderThan(startCleanTime.Add(-cl.connectionTimeout))
|
|
cl.assemblerMutex.Unlock()
|
|
|
|
deleted := cl.matcher.deleteOlderThan(startCleanTime.Add(-cl.connectionTimeout))
|
|
|
|
cl.statsMutex.Lock()
|
|
cl.stats.flushed += flushed
|
|
cl.stats.closed += closed
|
|
cl.stats.deleted += deleted
|
|
cl.statsMutex.Unlock()
|
|
}
|
|
|
|
func (cl *Cleaner) start() {
|
|
go func() {
|
|
ticker := time.NewTicker(cl.cleanPeriod)
|
|
|
|
for true {
|
|
<-ticker.C
|
|
cl.clean()
|
|
}
|
|
}()
|
|
}
|
|
|
|
func (cl *Cleaner) dumpStats() CleanerStats {
|
|
cl.statsMutex.Lock()
|
|
|
|
stats := CleanerStats{
|
|
flushed: cl.stats.flushed,
|
|
closed : cl.stats.closed,
|
|
deleted: cl.stats.deleted,
|
|
}
|
|
|
|
cl.stats.flushed = 0
|
|
cl.stats.closed = 0
|
|
cl.stats.deleted = 0
|
|
|
|
cl.statsMutex.Unlock()
|
|
|
|
return stats
|
|
}
|