From d33e69faa3274c6baa2e7dfdf1ecdb9693b4e877 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Sun, 1 Nov 2020 16:49:30 +0100 Subject: [PATCH] Introduction of the "faulty" toggle, to test transfer errors on clients. --- src/requests/transfer.cr | 7 +++++++ src/server/main.cr | 25 +++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/requests/transfer.cr b/src/requests/transfer.cr index 0af6f86..c57760f 100644 --- a/src/requests/transfer.cr +++ b/src/requests/transfer.cr @@ -22,6 +22,13 @@ class FileStorage::Request raise NotLoggedException.new if user.nil? + if filestoraged.faulty + if @faulty_nb == 4 + @faulty_nb = 0 + raise "FAULTY" + end + end + # FIXME: Maybe this should be moved to FileStorage::Service fd = event.fd diff --git a/src/server/main.cr b/src/server/main.cr index 73da2bf..385636d 100644 --- a/src/server/main.cr +++ b/src/server/main.cr @@ -50,13 +50,15 @@ end class Baguette::Configuration class FileStorage < Base - property max_file_size : UInt64 = 10_000_000 # default, 10 MB - property storage : String = "files/" - property db_reindex : Bool = false + property max_file_size : UInt64 = 10_000_000 # default, 10 MB + property storage : String = "files/" + property db_reindex : Bool = false - property verbosity : Int32 = 3 - property ipc_timer : Int32 = 30_000 # Default timer: 30 seconds. - property print_ipc_timer : Bool = false + property faulty : Bool = false # To test clients on transfer errors. + + property verbosity : Int32 = 3 + property ipc_timer : Int32 = 30_000 # Default timer: 30 seconds. + property print_ipc_timer : Bool = false def initialize end @@ -83,6 +85,9 @@ class FileStorage::Service < IPC::Server property print_timer : Bool = false + property faulty : Bool = false + property faulty_nb : Int32 = 0 + @auth : AuthD::Client @auth_key : String @@ -281,6 +286,13 @@ class FileStorage::Service < IPC::Server configuration.max_file_size = s.to_u64 * 1000 end + parser.on "-f", + "--faulty", + "Messages will be dropped, rate: 1/5." do + Baguette::Log.info "Faulty: messages will be dropped." + configuration.faulty = true + end + parser.on "-k file", "--key file", "Reads the authentication key from the provided file." do |file| @@ -307,6 +319,7 @@ class FileStorage::Service < IPC::Server service.timer = configuration.ipc_timer service.max_file_size = configuration.max_file_size service.print_timer = configuration.print_ipc_timer + service.faulty = configuration.faulty end end end