2019-04-27 06:57:35 +00:00
|
|
|
use failure::*;
|
|
|
|
|
2019-05-07 12:07:00 +00:00
|
|
|
use std::sync::Arc;
|
2019-05-07 09:24:44 +00:00
|
|
|
|
|
|
|
use futures::*;
|
2019-04-27 06:57:35 +00:00
|
|
|
use hyper::header::{HeaderValue, UPGRADE};
|
2019-05-08 15:36:19 +00:00
|
|
|
use hyper::{Body, Response, StatusCode};
|
2019-04-27 06:57:35 +00:00
|
|
|
use hyper::http::request::Parts;
|
2019-05-08 11:17:23 +00:00
|
|
|
use chrono::{Local, TimeZone};
|
2019-04-27 06:57:35 +00:00
|
|
|
|
2019-05-10 08:25:40 +00:00
|
|
|
use serde_json::{json, Value};
|
2019-04-27 06:57:35 +00:00
|
|
|
|
2019-05-07 09:24:44 +00:00
|
|
|
use crate::tools;
|
2019-05-11 14:05:50 +00:00
|
|
|
use crate::tools::wrapped_reader_stream::*;
|
2019-04-27 06:57:35 +00:00
|
|
|
use crate::api_schema::router::*;
|
|
|
|
use crate::api_schema::*;
|
2019-05-08 09:26:54 +00:00
|
|
|
use crate::server::WorkerTask;
|
2019-05-09 11:06:09 +00:00
|
|
|
use crate::backup::*;
|
2019-04-27 06:57:35 +00:00
|
|
|
|
2019-05-08 10:41:58 +00:00
|
|
|
mod environment;
|
|
|
|
use environment::*;
|
|
|
|
|
2019-05-08 15:36:19 +00:00
|
|
|
mod service;
|
|
|
|
use service::*;
|
|
|
|
|
2019-05-09 11:06:09 +00:00
|
|
|
mod upload_chunk;
|
|
|
|
use upload_chunk::*;
|
|
|
|
|
|
|
|
|
2019-05-08 10:35:15 +00:00
|
|
|
pub fn api_method_upgrade_backup() -> ApiAsyncMethod {
|
2019-04-27 06:57:35 +00:00
|
|
|
ApiAsyncMethod::new(
|
2019-05-08 11:17:23 +00:00
|
|
|
upgrade_to_backup_protocol,
|
2019-05-08 10:35:15 +00:00
|
|
|
ObjectSchema::new("Upgraded to backup protocol.")
|
2019-05-08 11:17:23 +00:00
|
|
|
.required("store", StringSchema::new("Datastore name."))
|
|
|
|
.required("backup-type", StringSchema::new("Backup type.")
|
2019-05-23 09:27:45 +00:00
|
|
|
.format(Arc::new(ApiStringFormat::Enum(&["vm", "ct", "host"]))))
|
2019-05-08 11:17:23 +00:00
|
|
|
.required("backup-id", StringSchema::new("Backup ID."))
|
2019-04-27 06:57:35 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-05-08 11:17:23 +00:00
|
|
|
fn upgrade_to_backup_protocol(
|
2019-04-27 06:57:35 +00:00
|
|
|
parts: Parts,
|
|
|
|
req_body: Body,
|
2019-05-08 11:17:23 +00:00
|
|
|
param: Value,
|
2019-04-27 06:57:35 +00:00
|
|
|
_info: &ApiAsyncMethod,
|
2019-05-09 16:01:24 +00:00
|
|
|
rpcenv: Box<RpcEnvironment>,
|
2019-04-27 06:57:35 +00:00
|
|
|
) -> Result<BoxFut, Error> {
|
2019-05-08 11:17:23 +00:00
|
|
|
|
2019-05-08 15:36:19 +00:00
|
|
|
static PROXMOX_BACKUP_PROTOCOL_ID: &str = "proxmox-backup-protocol-h2";
|
|
|
|
|
2019-05-15 08:09:46 +00:00
|
|
|
let store = tools::required_string_param(¶m, "store")?.to_owned();
|
|
|
|
let datastore = DataStore::lookup_datastore(&store)?;
|
2019-05-09 11:06:09 +00:00
|
|
|
|
2019-05-08 11:17:23 +00:00
|
|
|
let backup_type = tools::required_string_param(¶m, "backup-type")?;
|
|
|
|
let backup_id = tools::required_string_param(¶m, "backup-id")?;
|
2019-05-10 08:25:40 +00:00
|
|
|
let backup_time = Local.timestamp(Local::now().timestamp(), 0);
|
2019-04-27 06:57:35 +00:00
|
|
|
|
|
|
|
let protocols = parts
|
|
|
|
.headers
|
|
|
|
.get("UPGRADE")
|
|
|
|
.ok_or_else(|| format_err!("missing Upgrade header"))?
|
|
|
|
.to_str()?;
|
|
|
|
|
2019-05-08 11:17:23 +00:00
|
|
|
if protocols != PROXMOX_BACKUP_PROTOCOL_ID {
|
2019-04-27 06:57:35 +00:00
|
|
|
bail!("invalid protocol name");
|
|
|
|
}
|
|
|
|
|
2019-05-06 08:29:34 +00:00
|
|
|
if parts.version >= http::version::Version::HTTP_2 {
|
|
|
|
bail!("unexpected http version '{:?}' (expected version < 2)", parts.version);
|
|
|
|
}
|
|
|
|
|
2019-05-08 11:17:23 +00:00
|
|
|
let worker_id = format!("{}_{}_{}", store, backup_type, backup_id);
|
2019-05-07 11:42:00 +00:00
|
|
|
|
2019-05-08 09:26:54 +00:00
|
|
|
let username = rpcenv.get_user().unwrap();
|
|
|
|
let env_type = rpcenv.env_type();
|
2019-05-07 09:24:44 +00:00
|
|
|
|
2019-05-11 10:07:09 +00:00
|
|
|
let backup_group = BackupGroup::new(backup_type, backup_id);
|
2019-05-13 05:06:56 +00:00
|
|
|
let last_backup = BackupInfo::last_backup(&datastore.base_path(), &backup_group).unwrap_or(None);
|
2019-05-11 10:07:09 +00:00
|
|
|
let backup_dir = BackupDir::new_with_group(backup_group, backup_time.timestamp());
|
2019-05-10 08:25:40 +00:00
|
|
|
|
2019-05-15 08:09:46 +00:00
|
|
|
let (path, is_new) = datastore.create_backup_dir(&backup_dir)?;
|
2019-05-10 08:25:40 +00:00
|
|
|
if !is_new { bail!("backup directorty already exists."); }
|
|
|
|
|
2019-05-08 11:17:23 +00:00
|
|
|
WorkerTask::spawn("backup", Some(worker_id), &username.clone(), true, move |worker| {
|
2019-05-15 08:09:46 +00:00
|
|
|
let mut env = BackupEnvironment::new(
|
2019-05-11 10:13:44 +00:00
|
|
|
env_type, username.clone(), worker.clone(), datastore, backup_dir);
|
2019-05-11 09:21:13 +00:00
|
|
|
|
2019-05-15 08:09:46 +00:00
|
|
|
env.last_backup = last_backup;
|
2019-05-11 09:21:13 +00:00
|
|
|
|
2019-05-15 08:09:46 +00:00
|
|
|
env.log(format!("starting new backup on datastore '{}': {:?}", store, path));
|
|
|
|
|
2019-05-15 10:58:55 +00:00
|
|
|
let service = BackupService::new(env.clone(), worker.clone());
|
2019-05-07 12:07:00 +00:00
|
|
|
|
2019-05-08 05:14:40 +00:00
|
|
|
let abort_future = worker.abort_future();
|
|
|
|
|
2019-05-15 10:58:55 +00:00
|
|
|
let env2 = env.clone();
|
2019-05-15 08:09:46 +00:00
|
|
|
|
2019-04-27 06:57:35 +00:00
|
|
|
req_body
|
|
|
|
.on_upgrade()
|
2019-05-07 09:24:44 +00:00
|
|
|
.map_err(Error::from)
|
2019-04-27 06:57:35 +00:00
|
|
|
.and_then(move |conn| {
|
2019-05-07 11:42:00 +00:00
|
|
|
worker.log("upgrade done");
|
2019-05-07 09:24:44 +00:00
|
|
|
|
|
|
|
let mut http = hyper::server::conn::Http::new();
|
|
|
|
http.http2_only(true);
|
2019-05-16 08:24:23 +00:00
|
|
|
// increase window size: todo - find optiomal size
|
2019-05-27 05:40:50 +00:00
|
|
|
let window_size = 32*1024*1024; // max = (1 << 31) - 2
|
|
|
|
http.http2_initial_stream_window_size(window_size);
|
|
|
|
http.http2_initial_connection_window_size(window_size);
|
2019-05-07 09:24:44 +00:00
|
|
|
|
2019-05-07 11:42:00 +00:00
|
|
|
http.serve_connection(conn, service)
|
|
|
|
.map_err(Error::from)
|
2019-05-08 11:17:23 +00:00
|
|
|
})
|
2019-05-08 05:14:40 +00:00
|
|
|
.select(abort_future.map_err(|_| {}).then(move |_| { bail!("task aborted"); }))
|
2019-05-15 10:58:55 +00:00
|
|
|
.map_err(|(err, _)| err)
|
2019-05-15 08:09:46 +00:00
|
|
|
.and_then(move |(_result, _)| {
|
2019-05-15 10:58:55 +00:00
|
|
|
env.ensure_finished()?;
|
|
|
|
env.log("backup finished sucessfully");
|
2019-05-15 08:09:46 +00:00
|
|
|
Ok(())
|
|
|
|
})
|
2019-05-15 10:58:55 +00:00
|
|
|
.then(move |result| {
|
|
|
|
if let Err(err) = result {
|
2019-05-21 07:54:11 +00:00
|
|
|
match env2.ensure_finished() {
|
|
|
|
Ok(()) => {}, // ignorte error after finish
|
|
|
|
_ => {
|
|
|
|
env2.log(format!("backup failed: {}", err));
|
|
|
|
env2.log("removing failed backup");
|
|
|
|
env2.remove_backup()?;
|
|
|
|
return Err(err);
|
|
|
|
}
|
|
|
|
}
|
2019-05-15 10:58:55 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
2019-05-15 08:09:46 +00:00
|
|
|
})
|
2019-05-08 06:21:18 +00:00
|
|
|
})?;
|
|
|
|
|
|
|
|
let response = Response::builder()
|
|
|
|
.status(StatusCode::SWITCHING_PROTOCOLS)
|
2019-05-08 11:17:23 +00:00
|
|
|
.header(UPGRADE, HeaderValue::from_static(PROXMOX_BACKUP_PROTOCOL_ID))
|
2019-05-08 06:21:18 +00:00
|
|
|
.body(Body::empty())?;
|
|
|
|
|
|
|
|
Ok(Box::new(futures::future::ok(response)))
|
2019-04-27 06:57:35 +00:00
|
|
|
}
|
2019-05-07 09:24:44 +00:00
|
|
|
|
|
|
|
fn backup_api() -> Router {
|
|
|
|
|
|
|
|
let router = Router::new()
|
2019-05-10 08:25:40 +00:00
|
|
|
.subdir(
|
|
|
|
"dynamic_chunk", Router::new()
|
|
|
|
.upload(api_method_upload_dynamic_chunk())
|
|
|
|
)
|
|
|
|
.subdir(
|
|
|
|
"dynamic_index", Router::new()
|
2019-05-11 14:05:50 +00:00
|
|
|
.download(api_method_dynamic_chunk_index())
|
2019-05-10 08:25:40 +00:00
|
|
|
.post(api_method_create_dynamic_index())
|
2019-05-20 12:19:24 +00:00
|
|
|
.put(api_method_dynamic_append())
|
2019-05-10 08:25:40 +00:00
|
|
|
)
|
2019-05-15 05:58:05 +00:00
|
|
|
.subdir(
|
|
|
|
"dynamic_close", Router::new()
|
|
|
|
.post(api_method_close_dynamic_index())
|
|
|
|
)
|
2019-05-15 10:58:55 +00:00
|
|
|
.subdir(
|
|
|
|
"finish", Router::new()
|
2019-05-22 11:04:58 +00:00
|
|
|
.post(
|
2019-05-15 10:58:55 +00:00
|
|
|
ApiMethod::new(
|
|
|
|
finish_backup,
|
|
|
|
ObjectSchema::new("Mark backup as finished.")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2019-05-16 08:24:23 +00:00
|
|
|
.subdir(
|
|
|
|
"speedtest", Router::new()
|
|
|
|
.upload(api_method_upload_speedtest())
|
|
|
|
)
|
2019-05-07 09:24:44 +00:00
|
|
|
.list_subdirs();
|
|
|
|
|
|
|
|
router
|
|
|
|
}
|
|
|
|
|
2019-05-11 14:05:50 +00:00
|
|
|
pub fn api_method_dynamic_chunk_index() -> ApiAsyncMethod {
|
|
|
|
ApiAsyncMethod::new(
|
|
|
|
dynamic_chunk_index,
|
|
|
|
ObjectSchema::new(r###"
|
|
|
|
Download the dynamic chunk index from the previous backup.
|
|
|
|
Simply returns an empty list if this is the first backup.
|
|
|
|
"###
|
|
|
|
)
|
2019-05-15 05:14:08 +00:00
|
|
|
.required("archive-name", crate::api2::types::BACKUP_ARCHIVE_NAME_SCHEMA.clone())
|
2019-05-11 14:05:50 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-05-10 08:25:40 +00:00
|
|
|
pub fn api_method_create_dynamic_index() -> ApiMethod {
|
|
|
|
ApiMethod::new(
|
|
|
|
create_dynamic_index,
|
|
|
|
ObjectSchema::new("Create dynamic chunk index file.")
|
2019-05-15 05:14:08 +00:00
|
|
|
.required("archive-name", crate::api2::types::BACKUP_ARCHIVE_NAME_SCHEMA.clone())
|
2019-05-10 08:25:40 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_dynamic_index(
|
|
|
|
param: Value,
|
|
|
|
_info: &ApiMethod,
|
|
|
|
rpcenv: &mut RpcEnvironment,
|
|
|
|
) -> Result<Value, Error> {
|
|
|
|
|
|
|
|
let env: &BackupEnvironment = rpcenv.as_ref();
|
|
|
|
|
2019-05-23 06:50:36 +00:00
|
|
|
let name = tools::required_string_param(¶m, "archive-name")?.to_owned();
|
2019-05-10 08:25:40 +00:00
|
|
|
|
2019-05-23 06:50:36 +00:00
|
|
|
let mut archive_name = name.clone();
|
2019-05-10 08:25:40 +00:00
|
|
|
if !archive_name.ends_with(".pxar") {
|
|
|
|
bail!("wrong archive extension");
|
|
|
|
} else {
|
|
|
|
archive_name.push_str(".didx");
|
|
|
|
}
|
|
|
|
|
2019-05-11 10:13:44 +00:00
|
|
|
let mut path = env.backup_dir.relative_path();
|
2019-05-10 08:25:40 +00:00
|
|
|
path.push(archive_name);
|
|
|
|
|
|
|
|
let chunk_size = 4096*1024; // todo: ??
|
|
|
|
|
2019-05-15 08:09:46 +00:00
|
|
|
let index = env.datastore.create_dynamic_writer(&path, chunk_size)?;
|
2019-05-23 06:50:36 +00:00
|
|
|
let wid = env.register_dynamic_writer(index, name)?;
|
2019-05-10 08:25:40 +00:00
|
|
|
|
2019-05-15 08:09:46 +00:00
|
|
|
env.log(format!("created new dynamic index {} ({:?})", wid, path));
|
2019-05-10 08:25:40 +00:00
|
|
|
|
2019-05-15 08:09:46 +00:00
|
|
|
Ok(json!(wid))
|
2019-05-10 08:25:40 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 12:19:24 +00:00
|
|
|
pub fn api_method_dynamic_append() -> ApiMethod {
|
|
|
|
ApiMethod::new(
|
|
|
|
dynamic_append,
|
|
|
|
ObjectSchema::new("Append chunk to dynamic index writer.")
|
2019-05-24 08:05:22 +00:00
|
|
|
.required("wid", IntegerSchema::new("Dynamic writer ID.")
|
|
|
|
.minimum(1)
|
|
|
|
.maximum(256)
|
|
|
|
)
|
2019-05-23 10:29:33 +00:00
|
|
|
.required("digest-list", ArraySchema::new(
|
|
|
|
"Chunk digest list.",
|
|
|
|
StringSchema::new("Chunk digest.").into())
|
|
|
|
)
|
2019-05-24 08:05:22 +00:00
|
|
|
.required("offset-list", ArraySchema::new(
|
|
|
|
"Chunk offset list.",
|
|
|
|
IntegerSchema::new("Corresponding chunk offsets.")
|
|
|
|
.minimum(0)
|
|
|
|
.into())
|
2019-05-20 12:19:24 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn dynamic_append (
|
|
|
|
param: Value,
|
|
|
|
_info: &ApiMethod,
|
|
|
|
rpcenv: &mut RpcEnvironment,
|
|
|
|
) -> Result<Value, Error> {
|
|
|
|
|
|
|
|
let wid = tools::required_integer_param(¶m, "wid")? as usize;
|
2019-05-23 10:29:33 +00:00
|
|
|
let digest_list = tools::required_array_param(¶m, "digest-list")?;
|
2019-05-24 08:05:22 +00:00
|
|
|
let offset_list = tools::required_array_param(¶m, "offset-list")?;
|
2019-05-23 10:29:33 +00:00
|
|
|
|
|
|
|
println!("DIGEST LIST LEN {}", digest_list.len());
|
2019-05-20 12:19:24 +00:00
|
|
|
|
2019-05-24 08:05:22 +00:00
|
|
|
if offset_list.len() != digest_list.len() {
|
|
|
|
bail!("offset list has wrong length ({} != {})", offset_list.len(), digest_list.len());
|
|
|
|
}
|
|
|
|
|
2019-05-20 12:19:24 +00:00
|
|
|
let env: &BackupEnvironment = rpcenv.as_ref();
|
|
|
|
|
2019-05-24 08:05:22 +00:00
|
|
|
for (i, item) in digest_list.iter().enumerate() {
|
2019-05-23 10:29:33 +00:00
|
|
|
let digest_str = item.as_str().unwrap();
|
|
|
|
let digest = crate::tools::hex_to_digest(digest_str)?;
|
2019-05-24 08:05:22 +00:00
|
|
|
let offset = offset_list[i].as_u64().unwrap();
|
2019-05-23 10:29:33 +00:00
|
|
|
let size = env.lookup_chunk(&digest).ok_or_else(|| format_err!("no such chunk {}", digest_str))?;
|
2019-05-24 08:05:22 +00:00
|
|
|
env.dynamic_writer_append_chunk(wid, offset, size, &digest)?;
|
2019-05-20 12:19:24 +00:00
|
|
|
|
2019-05-23 10:29:33 +00:00
|
|
|
env.log(format!("sucessfully added chunk {} to dynamic index {}", digest_str, wid));
|
|
|
|
}
|
2019-05-20 12:19:24 +00:00
|
|
|
|
|
|
|
Ok(Value::Null)
|
|
|
|
}
|
|
|
|
|
2019-05-15 05:58:05 +00:00
|
|
|
pub fn api_method_close_dynamic_index() -> ApiMethod {
|
|
|
|
ApiMethod::new(
|
|
|
|
close_dynamic_index,
|
|
|
|
ObjectSchema::new("Close dynamic index writer.")
|
|
|
|
.required("wid", IntegerSchema::new("Dynamic writer ID.")
|
|
|
|
.minimum(1)
|
|
|
|
.maximum(256)
|
|
|
|
)
|
2019-05-23 06:50:36 +00:00
|
|
|
.required("chunk-count", IntegerSchema::new("Chunk count. This is used to verify that the server got all chunks.")
|
|
|
|
.minimum(1)
|
|
|
|
)
|
|
|
|
.required("size", IntegerSchema::new("File size. This is used to verify that the server got all data.")
|
|
|
|
.minimum(1)
|
|
|
|
)
|
2019-05-15 05:58:05 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn close_dynamic_index (
|
|
|
|
param: Value,
|
|
|
|
_info: &ApiMethod,
|
|
|
|
rpcenv: &mut RpcEnvironment,
|
|
|
|
) -> Result<Value, Error> {
|
|
|
|
|
|
|
|
let wid = tools::required_integer_param(¶m, "wid")? as usize;
|
2019-05-23 06:50:36 +00:00
|
|
|
let chunk_count = tools::required_integer_param(¶m, "chunk-count")? as u64;
|
|
|
|
let size = tools::required_integer_param(¶m, "size")? as u64;
|
2019-05-15 05:58:05 +00:00
|
|
|
|
|
|
|
let env: &BackupEnvironment = rpcenv.as_ref();
|
|
|
|
|
2019-05-23 06:50:36 +00:00
|
|
|
env.dynamic_writer_close(wid, chunk_count, size)?;
|
2019-05-15 05:58:05 +00:00
|
|
|
|
2019-05-15 08:09:46 +00:00
|
|
|
env.log(format!("sucessfully closed dynamic index {}", wid));
|
|
|
|
|
2019-05-15 05:58:05 +00:00
|
|
|
Ok(Value::Null)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-15 10:58:55 +00:00
|
|
|
fn finish_backup (
|
|
|
|
_param: Value,
|
|
|
|
_info: &ApiMethod,
|
|
|
|
rpcenv: &mut RpcEnvironment,
|
|
|
|
) -> Result<Value, Error> {
|
|
|
|
|
|
|
|
let env: &BackupEnvironment = rpcenv.as_ref();
|
|
|
|
|
|
|
|
env.finish_backup()?;
|
|
|
|
|
|
|
|
Ok(Value::Null)
|
|
|
|
}
|
2019-05-15 05:58:05 +00:00
|
|
|
|
2019-05-11 14:05:50 +00:00
|
|
|
fn dynamic_chunk_index(
|
|
|
|
_parts: Parts,
|
|
|
|
_req_body: Body,
|
|
|
|
param: Value,
|
|
|
|
_info: &ApiAsyncMethod,
|
|
|
|
rpcenv: Box<RpcEnvironment>,
|
|
|
|
) -> Result<BoxFut, Error> {
|
|
|
|
|
|
|
|
let env: &BackupEnvironment = rpcenv.as_ref();
|
|
|
|
|
2019-05-21 07:54:11 +00:00
|
|
|
println!("TEST CHUNK DOWNLOAD");
|
|
|
|
|
2019-05-11 14:05:50 +00:00
|
|
|
let mut archive_name = tools::required_string_param(¶m, "archive-name")?.to_owned();
|
|
|
|
|
|
|
|
if !archive_name.ends_with(".pxar") {
|
|
|
|
bail!("wrong archive extension");
|
|
|
|
} else {
|
|
|
|
archive_name.push_str(".didx");
|
|
|
|
}
|
|
|
|
|
2019-05-21 07:54:11 +00:00
|
|
|
let empty_response = {
|
|
|
|
Response::builder()
|
|
|
|
.status(StatusCode::OK)
|
|
|
|
.body(Body::empty())?
|
|
|
|
};
|
|
|
|
|
2019-05-11 14:05:50 +00:00
|
|
|
let last_backup = match &env.last_backup {
|
|
|
|
Some(info) => info,
|
2019-05-21 07:54:11 +00:00
|
|
|
None => return Ok(Box::new(future::ok(empty_response))),
|
2019-05-11 14:05:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let mut path = last_backup.backup_dir.relative_path();
|
2019-05-21 07:54:11 +00:00
|
|
|
path.push(&archive_name);
|
2019-05-11 14:05:50 +00:00
|
|
|
|
2019-05-21 07:54:11 +00:00
|
|
|
let index = match env.datastore.open_dynamic_reader(path) {
|
|
|
|
Ok(index) => index,
|
|
|
|
Err(_) => {
|
|
|
|
env.log(format!("there is no last backup for archive '{}'", archive_name));
|
|
|
|
return Ok(Box::new(future::ok(empty_response)));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let count = index.index_count();
|
|
|
|
for pos in 0..count {
|
|
|
|
let (start, end, digest) = index.chunk_info(pos)?;
|
|
|
|
let size = (end - start) as u32;
|
|
|
|
env.register_chunk(digest, size)?;
|
|
|
|
}
|
2019-05-11 14:05:50 +00:00
|
|
|
|
2019-05-21 10:28:44 +00:00
|
|
|
let reader = DigestListEncoder::new(Box::new(index));
|
2019-05-11 14:05:50 +00:00
|
|
|
|
|
|
|
let stream = WrappedReaderStream::new(reader);
|
|
|
|
|
|
|
|
// fixme: set size, content type?
|
|
|
|
let response = http::Response::builder()
|
|
|
|
.status(200)
|
|
|
|
.body(Body::wrap_stream(stream))?;
|
|
|
|
|
|
|
|
Ok(Box::new(future::ok(response)))
|
|
|
|
}
|