-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b04a951
commit b450fec
Showing
2 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
} |