diff --git a/parser/configurations_parser.go b/parser/configurations_parser.go index 07c7efa..67c044b 100644 --- a/parser/configurations_parser.go +++ b/parser/configurations_parser.go @@ -1,3 +1,4 @@ +// Package parser is responsible for parsing the configurations of the core and honeypot service package parser import ( @@ -10,6 +11,7 @@ import ( "gopkg.in/yaml.v3" ) +// BeelzebubCoreConfigurations is the struct that contains the configurations of the core type BeelzebubCoreConfigurations struct { Core struct { Logging Logging `yaml:"logging"` @@ -18,6 +20,7 @@ type BeelzebubCoreConfigurations struct { } } +// Logging is the struct that contains the configurations of the logging type Logging struct { Debug bool `yaml:"debug"` DebugReportCaller bool `yaml:"debugReportCaller"` @@ -25,6 +28,7 @@ type Logging struct { LogsPath string `yaml:"logsPath,omitempty"` } +// Tracings is the struct that contains the configurations of the tracings type Tracings struct { RabbitMQ `yaml:"rabbit-mq"` } @@ -42,6 +46,7 @@ type Plugin struct { OpenAPIChatGPTSecretKey string `yaml:"openAPIChatGPTSecretKey"` } +// BeelzebubServiceConfiguration is the struct that contains the configurations of the honeypot service type BeelzebubServiceConfiguration struct { ApiVersion string `yaml:"apiVersion"` Protocol string `yaml:"protocol"` @@ -56,6 +61,7 @@ type BeelzebubServiceConfiguration struct { Plugin Plugin `yaml:"plugin"` } +// Command is the struct that contains the configurations of the commands type Command struct { Regex string `yaml:"regex"` Handler string `yaml:"handler"` @@ -85,6 +91,7 @@ func Init(configurationsCorePath, configurationsServicesDirectory string) *confi } } +// ReadConfigurationsCore is the method that reads the configurations of the core from files func (bp configurationsParser) ReadConfigurationsCore() (*BeelzebubCoreConfigurations, error) { buf, err := bp.readFileBytesByFilePathDependency(bp.configurationsCorePath) if err != nil { @@ -100,6 +107,7 @@ func (bp configurationsParser) ReadConfigurationsCore() (*BeelzebubCoreConfigura return beelzebubConfiguration, nil } +// ReadConfigurationsServices is the method that reads the configurations of the honeypot services from files func (bp configurationsParser) ReadConfigurationsServices() ([]BeelzebubServiceConfiguration, error) { services, err := bp.gelAllFilesNameByDirNameDependency(bp.configurationsServicesDirectory) if err != nil { diff --git a/protocols/protocol_manager.go b/protocols/protocol_manager.go index f6c6525..1ae610a 100644 --- a/protocols/protocol_manager.go +++ b/protocols/protocol_manager.go @@ -1,3 +1,4 @@ +// Package protocols is responsible for managing the different protocols package protocols import ( @@ -5,6 +6,7 @@ import ( "github.com/mariocandela/beelzebub/v3/tracer" ) +// ServiceStrategy is the common interface that each protocol honeypot implements type ServiceStrategy interface { Init(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration, tracer tracer.Tracer) error } @@ -14,10 +16,11 @@ type ProtocolManager struct { tracer tracer.Tracer } -func InitProtocolManager(tracerStrategy tracer.Strategy, strategy ServiceStrategy) *ProtocolManager { +// InitProtocolManager is the method that initializes the protocol manager, receving the concrete tracer and the concrete service +func InitProtocolManager(tracerStrategy tracer.Strategy, serviceStrategy ServiceStrategy) *ProtocolManager { return &ProtocolManager{ tracer: tracer.GetInstance(tracerStrategy), - strategy: strategy, + strategy: serviceStrategy, } } @@ -25,6 +28,7 @@ func (pm *ProtocolManager) SetProtocolStrategy(strategy ServiceStrategy) { pm.strategy = strategy } +// InitService is the method that initializes the honeypot func (pm *ProtocolManager) InitService(beelzebubServiceConfiguration parser.BeelzebubServiceConfiguration) error { return pm.strategy.Init(beelzebubServiceConfiguration, pm.tracer) } diff --git a/tracer/tracer.go b/tracer/tracer.go index e511bd7..9567878 100644 --- a/tracer/tracer.go +++ b/tracer/tracer.go @@ -1,3 +1,4 @@ +// Package tracer is responsible for tracing the events that occur in the honeypots package tracer import ( @@ -9,6 +10,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promauto" ) +// Workers is the number of workers that will const Workers = 5 type Event struct { @@ -78,14 +80,14 @@ type tracer struct { var lock = &sync.Mutex{} var singleton *tracer -func GetInstance(strategy Strategy) *tracer { +func GetInstance(defaultStrategy Strategy) *tracer { if singleton == nil { lock.Lock() defer lock.Unlock() // This is to prevent expensive lock operations every time the GetInstance method is called if singleton == nil { singleton = &tracer{ - strategy: strategy, + strategy: defaultStrategy, eventsChan: make(chan Event, Workers), eventsTotal: promauto.NewCounter(prometheus.CounterOpts{ Namespace: "beelzebub", @@ -111,7 +113,7 @@ func GetInstance(strategy Strategy) *tracer { for i := 0; i < Workers; i++ { go func(i int) { - log.Debug("GetInstance trace worker: ", i) + log.Debug("Trace worker: ", i) for event := range singleton.eventsChan { singleton.strategy(event) }