mirror of
https://github.com/kubeshark/kubeshark.git
synced 2026-07-07 07:30:12 +00:00
Refactoring (#84)
* Only use one channel for filtering HARs. * Only check if dest is service ip if message is outgoing. * Parse direction flag on input. * Renamed filterHarHeaders -> filterHarItems. * Fixed compilation bugs.
This commit is contained in:
27
api/main.go
27
api/main.go
@@ -35,12 +35,10 @@ func main() {
|
||||
|
||||
if *standalone {
|
||||
harOutputChannel, outboundLinkOutputChannel := tap.StartPassiveTapper(tapOpts)
|
||||
filteredHarChannel0 := make(chan *tap.OutputChannelItem)
|
||||
filteredHarChannel1 := make(chan *tap.OutputChannelItem)
|
||||
filteredHarChannel := make(chan *tap.OutputChannelItem)
|
||||
|
||||
go filterServices(harOutputChannel, filteredHarChannel0, getTrafficFilteringOptions())
|
||||
go filterHarHeaders(filteredHarChannel0, filteredHarChannel1, getTrafficFilteringOptions())
|
||||
go api.StartReadingEntries(filteredHarChannel1, nil)
|
||||
go filterHarItems(harOutputChannel, filteredHarChannel, getTrafficFilteringOptions())
|
||||
go api.StartReadingEntries(filteredHarChannel, nil)
|
||||
go api.StartReadingOutbound(outboundLinkOutputChannel)
|
||||
|
||||
hostApi(nil)
|
||||
@@ -66,12 +64,10 @@ func main() {
|
||||
go api.StartReadingOutbound(outboundLinkOutputChannel)
|
||||
} else if *aggregator {
|
||||
socketHarOutChannel := make(chan *tap.OutputChannelItem, 1000)
|
||||
filteredHarChannel0 := make(chan *tap.OutputChannelItem)
|
||||
filteredHarChannel1 := make(chan *tap.OutputChannelItem)
|
||||
filteredHarChannel := make(chan *tap.OutputChannelItem)
|
||||
|
||||
go filterServices(socketHarOutChannel, filteredHarChannel0, getTrafficFilteringOptions())
|
||||
go filterHarHeaders(filteredHarChannel0, filteredHarChannel1, getTrafficFilteringOptions())
|
||||
go api.StartReadingEntries(filteredHarChannel1, nil)
|
||||
go filterHarItems(socketHarOutChannel, filteredHarChannel, getTrafficFilteringOptions())
|
||||
go api.StartReadingEntries(filteredHarChannel, nil)
|
||||
|
||||
hostApi(socketHarOutChannel)
|
||||
}
|
||||
@@ -129,19 +125,14 @@ func getTrafficFilteringOptions() *shared.TrafficFilteringOptions {
|
||||
return &filteringOptions
|
||||
}
|
||||
|
||||
func filterServices(inChannel <- chan *tap.OutputChannelItem, outChannel chan *tap.OutputChannelItem, filterOptions *shared.TrafficFilteringOptions) {
|
||||
func filterHarItems(inChannel <- chan *tap.OutputChannelItem, outChannel chan *tap.OutputChannelItem, filterOptions *shared.TrafficFilteringOptions) {
|
||||
for message := range inChannel {
|
||||
if api.CheckIsServiceIP(message.ConnectionInfo.ServerIP) {
|
||||
if message.ConnectionInfo.IsOutgoing && api.CheckIsServiceIP(message.ConnectionInfo.ServerIP) {
|
||||
continue
|
||||
}
|
||||
|
||||
outChannel <- message
|
||||
}
|
||||
}
|
||||
|
||||
func filterHarHeaders(inChannel <- chan *tap.OutputChannelItem, outChannel chan *tap.OutputChannelItem, filterOptions *shared.TrafficFilteringOptions) {
|
||||
for message := range inChannel {
|
||||
sensitiveDataFiltering.FilterSensitiveInfoFromHarRequest(message, filterOptions)
|
||||
|
||||
outChannel <- message
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user