2020-05-14 17:03:09 +02:00
|
|
|
class FileStorage::Request
|
2020-10-20 19:15:50 +02:00
|
|
|
IPC::JSON.message PutChunk, 40 do
|
2020-05-14 17:03:09 +02:00
|
|
|
property mid : String # autogenerated
|
|
|
|
property filedigest : String # SHA256 digest of the entire file
|
2020-05-16 01:40:09 +02:00
|
|
|
# Chunk:
|
|
|
|
# - n : Int32 => chunk number
|
|
|
|
# - on : Int32 => number of chunks
|
2020-06-06 20:43:14 +02:00
|
|
|
# - digest : String => digest of the chunk
|
2020-05-14 17:03:09 +02:00
|
|
|
property chunk : Chunk # For now, just the counter in a string
|
|
|
|
property data : String # base64 slice
|
|
|
|
def initialize(file_info : FileInfo, count, bindata)
|
|
|
|
# count: chunk number
|
|
|
|
|
|
|
|
@filedigest = file_info.digest
|
|
|
|
@data = Base64.encode bindata
|
|
|
|
@chunk = FileStorage::Chunk.new count, file_info.nb_chunks - 1, @data
|
|
|
|
@mid = UUID.random.to_s
|
|
|
|
end
|
|
|
|
|
2023-02-09 23:28:10 +01:00
|
|
|
def handle(filestoraged : FileStorage::Service, event : IPC::Event)
|
2020-05-16 01:40:09 +02:00
|
|
|
user = filestoraged.get_logged_user event
|
2020-05-14 17:03:09 +02:00
|
|
|
|
2020-10-20 23:57:37 +02:00
|
|
|
raise NotLoggedException.new if user.nil?
|
2020-05-14 17:03:09 +02:00
|
|
|
|
2020-11-01 16:49:30 +01:00
|
|
|
if filestoraged.faulty
|
2020-11-01 17:29:16 +01:00
|
|
|
filestoraged.faulty_nb += 1
|
|
|
|
if filestoraged.faulty_nb == 4
|
|
|
|
filestoraged.faulty_nb = 0
|
2020-11-01 16:49:30 +01:00
|
|
|
raise "FAULTY"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-14 17:03:09 +02:00
|
|
|
# FIXME: Maybe this should be moved to FileStorage::Service
|
2020-07-18 16:35:35 +02:00
|
|
|
fd = event.fd
|
2020-05-14 17:03:09 +02:00
|
|
|
|
|
|
|
user_data = filestoraged.get_user_data user.uid
|
|
|
|
|
2020-10-20 23:57:37 +02:00
|
|
|
Baguette::Log.debug "PutChunk request: #{@mid}, file #{@filedigest}, chunk: n=#{@chunk.n}, on=#{@chunk.on}, digest=#{@chunk.digest}"
|
2020-06-14 20:23:10 +02:00
|
|
|
|
2020-06-06 20:43:14 +02:00
|
|
|
filestoraged.storage.write_chunk self, user_data
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|
|
|
|
end
|
2020-06-06 20:43:14 +02:00
|
|
|
FileStorage.requests << PutChunk
|
2020-05-14 17:03:09 +02:00
|
|
|
|
2020-10-20 19:15:50 +02:00
|
|
|
IPC::JSON.message GetChunk, 41 do
|
2020-06-06 20:43:14 +02:00
|
|
|
property mid : String # autogenerated
|
|
|
|
property filedigest : String # SHA256 digest of the entire file
|
|
|
|
property n : Int32 # chunk number
|
2020-05-14 17:03:09 +02:00
|
|
|
|
2020-06-06 20:43:14 +02:00
|
|
|
def initialize(@filedigest, @n)
|
|
|
|
@mid = UUID.random.to_s
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|
|
|
|
|
2023-02-09 23:28:10 +01:00
|
|
|
def handle(filestoraged : FileStorage::Service, event : IPC::Event)
|
2020-06-06 20:43:14 +02:00
|
|
|
user = filestoraged.get_logged_user event
|
|
|
|
|
2020-10-20 23:57:37 +02:00
|
|
|
raise NotLoggedException.new if user.nil?
|
2020-06-06 20:43:14 +02:00
|
|
|
|
|
|
|
# FIXME: Maybe this should be moved to FileStorage::Service
|
2020-07-18 16:35:35 +02:00
|
|
|
fd = event.fd
|
2020-06-06 20:43:14 +02:00
|
|
|
|
|
|
|
user_data = filestoraged.get_user_data user.uid
|
|
|
|
|
2020-10-20 23:57:37 +02:00
|
|
|
Baguette::Log.debug "PutChunk request: #{@mid}, file #{@filedigest}, chunk: n=#{@n}"
|
|
|
|
|
2020-06-06 20:43:14 +02:00
|
|
|
filestoraged.storage.read_chunk self, user_data
|
|
|
|
end
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|
2020-06-06 20:43:14 +02:00
|
|
|
FileStorage.requests << GetChunk
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
class FileStorage::Response
|
2020-10-20 19:15:50 +02:00
|
|
|
IPC::JSON.message PutChunk, 40 do
|
2020-05-14 17:03:09 +02:00
|
|
|
property mid : String
|
2020-05-20 09:49:16 +02:00
|
|
|
property file_digest : String
|
2020-05-20 09:28:06 +02:00
|
|
|
property n : Int32 # chunk number
|
2020-05-20 09:49:16 +02:00
|
|
|
def initialize(@mid, @file_digest, @n)
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|
|
|
|
end
|
2020-06-06 20:43:14 +02:00
|
|
|
|
2020-10-20 19:15:50 +02:00
|
|
|
IPC::JSON.message GetChunk, 41 do
|
2020-06-06 20:43:14 +02:00
|
|
|
property mid : String
|
|
|
|
property file_digest : String
|
|
|
|
# Chunk:
|
|
|
|
# - n : Int32 => chunk number
|
|
|
|
# - on : Int32 => number of chunks
|
|
|
|
# - digest : String => digest of the chunk
|
|
|
|
property chunk : Chunk # Currently: info about the chunk
|
|
|
|
property data : String # base64 slice
|
|
|
|
def initialize(@mid, @file_digest, @chunk, @data)
|
|
|
|
end
|
|
|
|
end
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|