-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
listener.go
49 lines (42 loc) · 1.5 KB
/
listener.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2022-present Datadog, Inc.
package server
import (
"github.com/DataDog/datadog-agent/comp/core/log"
"github.com/DataDog/datadog-agent/comp/netflow/config"
"github.com/DataDog/datadog-agent/comp/netflow/flowaggregator"
"github.com/DataDog/datadog-agent/comp/netflow/goflowlib"
"go.uber.org/atomic"
)
// netflowListener contains state of goflow listener and the related netflow config
// flowState can be of type *utils.StateNetFlow/StateSFlow/StateNFLegacy
type netflowListener struct {
flowState *goflowlib.FlowStateWrapper
config config.ListenerConfig
error *atomic.String
flowCount *atomic.Int64
}
func startFlowListener(listenerConfig config.ListenerConfig, flowAgg *flowaggregator.FlowAggregator, logger log.Component) (*netflowListener, error) {
listenerAtomicErr := atomic.NewString("")
listenerFlowCount := atomic.NewInt64(0)
flowState, err := goflowlib.StartFlowRoutine(
listenerConfig.FlowType,
listenerConfig.BindHost,
listenerConfig.Port,
listenerConfig.Workers,
listenerConfig.Namespace,
listenerConfig.Mapping,
flowAgg.GetFlowInChan(),
logger,
listenerAtomicErr,
listenerFlowCount)
listener := &netflowListener{
flowState: flowState,
config: listenerConfig,
error: listenerAtomicErr,
flowCount: listenerFlowCount,
}
return listener, err
}