ExCEP. Gateway. FileTransfer
(ex_cep v0.1.1)
Copy Markdown
Bidirectional chunked file transfer engine per CSG CEP TS2.2 Section 6.2.
Supports both directions:
- Pull (
FileGet, Section 6.2.1) — Requester sendsFileGet, receivesFileGetRespmetadata (FileCrc,FileSize,ModifyTime), and receives & acknowledges eachFileDataTranssegment untilContinue == "0", verifying CRC32 + size. - Push (
FileSend, Section 6.2.2) — Sender sendsFileSend, awaitsFileSendResp, then streamsFileDataTranschunks stop-and-wait until complete.
Summary
Functions
Validates monotonic FileSegNo (1, 2, 3, ...) and Base64-decodes a FileDataTrans ASDU
into a transfer accumulator map.
Splits binary content into chunks of chunk_size bytes with 1-based segment numbers
and has_more? boolean flags.
Helper for FileGet receiver/reassembler state.
Given a FileGetResp ASDU, creates an initial transfer accumulator map.
Returns the maximum allowed transfer size in bytes (16 MiB).
Pushes content (binary) to a remote peer using request_fn.(asdu) :: {:ok, resp} | {:error, reason}.
Streams content chunks in response to a peer's FileGet after FileGetResp has been sent.
Uses stop-and-wait per-segment confirmation (FileDataTrans -> FileDataTransResp).
Verifies reassembled file content against expected FileCrc and FileSize metadata.
Functions
@spec append_segment(map(), ExCEP.Codec.DataAsdu.t()) :: {:more, map()} | {:done, binary()} | {:error, atom(), term()}
Validates monotonic FileSegNo (1, 2, 3, ...) and Base64-decodes a FileDataTrans ASDU
into a transfer accumulator map.
Returns:
{:more, updated_xfer}whenContinue == "1"{:done, content}whenContinue == "0"and CRC32 + size match{:error, error_code, reason}on out-of-order segment, invalid base64, or CRC/size mismatch
@spec chunk_binary(binary(), pos_integer()) :: [{pos_integer(), binary(), boolean()}]
Splits binary content into chunks of chunk_size bytes with 1-based segment numbers
and has_more? boolean flags.
@spec init_pull_state(String.t(), ExCEP.Codec.DataAsdu.t()) :: {:ok, map()} | {:error, term()}
Helper for FileGet receiver/reassembler state.
Given a FileGetResp ASDU, creates an initial transfer accumulator map.
@spec max_file_size() :: pos_integer()
Returns the maximum allowed transfer size in bytes (16 MiB).
@spec push_binary( (ExCEP.Codec.DataAsdu.t() -> {:ok, ExCEP.Codec.DataAsdu.t()} | {:error, term()}), String.t(), String.t(), binary(), keyword() ) :: :ok | {:error, term()}
Pushes content (binary) to a remote peer using request_fn.(asdu) :: {:ok, resp} | {:error, reason}.
@spec serve_file_chunks( (ExCEP.Codec.DataAsdu.t() -> {:ok, ExCEP.Codec.DataAsdu.t()} | {:error, term()}), String.t(), String.t(), binary(), keyword() ) :: :ok | {:error, term()}
Streams content chunks in response to a peer's FileGet after FileGetResp has been sent.
Uses stop-and-wait per-segment confirmation (FileDataTrans -> FileDataTransResp).
Verifies reassembled file content against expected FileCrc and FileSize metadata.