Skip to content

Commit

Permalink
#9 Add part of ddosml and validator
Browse files Browse the repository at this point in the history
  • Loading branch information
thegodenage committed May 6, 2024
1 parent b04a951 commit b450fec
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
42 changes: 39 additions & 3 deletions internal/ddosml/ml.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
package ddosml

import (
"context"
"fmt"
"net/http"
)

type RequestRepository interface {
CreateRequest(ctx context.Context, req *Request) error
}

type Request struct {
IsDDOS bool
}

// DDOS represents machine learning
// DDOS protection.
type DDOS struct {
isEnabled bool
// isEnabled is used in order to enable or disable the ddosml
isEnabled bool
repository RequestRepository
}

// NewDDOS creates new ddos ML analyzer used to
// analyze requests in order to find out if given
// request is ddos attack or not.
func NewDDOS(isEnabled bool) *DDOS {
return &DDOS{isEnabled: isEnabled}
func NewDDOS(isEnabled bool, repository RequestRepository) *DDOS {
return &DDOS{
isEnabled: isEnabled,
repository: repository,
}
}

// IsRequestSuspicious checks if given request is suspicious (and then saves it in the database in order to be
// used in future evaluations of this validator)
func (d *DDOS) IsRequestSuspicious(ctx context.Context, req *http.Request) (bool, error) {
ok, err := d.validateRequest(ctx, req)
if err != nil {
return ok, fmt.Errorf("validate request: %w", err)
}

return ok, nil
}

// validateRequest is used to validate if given request is ddos or not. The validation is based on the ML
// model, which decides based on normal user decisions from the UI.
func (d *DDOS) validateRequest(ctx context.Context, req *http.Request) (bool, error) {

}
8 changes: 8 additions & 0 deletions internal/ddosml/validator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ddosml

// Validator is a core of the ddosml, it validates
// each request against trained model and from time to time,
// it's retraining the model against new data, and also it
// clears database.
type Validator struct {
}

0 comments on commit b450fec

Please sign in to comment.