Skip to content

Commit

Permalink
Merge branch 'gamerhash/master' of github.com:golemfactory/yagna into…
Browse files Browse the repository at this point in the history
… gamerhash/update-master
  • Loading branch information
nieznanysprawiciel committed Sep 10, 2024
2 parents bc4e7e5 + 7e610fa commit 877c726
Show file tree
Hide file tree
Showing 25 changed files with 281 additions and 201 deletions.
176 changes: 67 additions & 109 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions core/gftp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ ya-service-bus = { workspace = true }

actix-rt = "2.7"
anyhow = "1.0"
digest = "0.8.1"
digest = "0.10"
dotenv = { version = "0.15.0", optional = true }
env_logger = { version = "0.7.1", optional = true }
futures = "0.3"
log = "0.4"
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha3 = "0.8.2"
sha3 = "0.10"
structopt = "0.3.9"
thiserror = "1.0.20"
tokio = { version = "1", features = ["io-std", "time"] }
Expand All @@ -41,7 +41,6 @@ url = { version = "2.1.1", features = ["serde"] }
[dev-dependencies]
dotenv = { version = "0.15.0" }
env_logger = { version = "0.7.1" }
sha3 = "0.8.2"
tempdir = "0.3.7"
tokio = { version = "1", features = ["process"] }

Expand Down
9 changes: 4 additions & 5 deletions core/gftp/examples/gftp-server.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use anyhow::{anyhow, Result};
use digest::{Digest, Output};
use futures::future::{FutureExt, LocalBoxFuture};
use gftp::rpc::*;
use sha3::digest::generic_array::GenericArray;
use sha3::Digest;
use std::ffi::OsString;
use std::fs::OpenOptions;
use std::io::Read;
Expand All @@ -14,7 +13,7 @@ use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::process::{ChildStdin, ChildStdout, Command};

static SEQ: AtomicUsize = AtomicUsize::new(0);
type HashOutput = GenericArray<u8, <sha3::Sha3_512 as Digest>::OutputSize>;
type HashOutput = Output<sha3::Sha3_512>;

/// Build the GFTP binary, start the daemon and run:
///
Expand Down Expand Up @@ -94,12 +93,12 @@ fn hash_file(path: &Path) -> Result<HashOutput> {
let mut chunk = vec![0; 4096];

while let Ok(count) = file_src.read(&mut chunk[..]) {
hasher.input(&chunk[..count]);
hasher.update(&chunk[..count]);
if count != 4096 {
break;
}
}
Ok(hasher.result())
Ok(hasher.finalize())
}

#[actix_rt::main]
Expand Down
2 changes: 1 addition & 1 deletion core/gftp/src/gftp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ fn hash_file_sha256(mut file: &mut fs::File) -> Result<String> {
.with_context(|| "Can't seek file at offset 0.".to_string())?;
io::copy(&mut file, &mut hasher)?;

Ok(format!("{:x}", hasher.result()))
Ok(format!("{:x}", hasher.finalize()))
}

/// Returns NodeId and file hash from gftp url.
Expand Down
2 changes: 1 addition & 1 deletion core/identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ r2d2 = "0.8.8"
rand = "0.8"
rpassword = "3.0.2"
serde_json = "1.0"
sha2 = "0.9.1"
sha2 = "0.10"
structopt = "0.3"
thiserror = "1.0"
tokio = { version = "1", features = ["fs", "io-std", "signal", "io-util"] }
Expand Down
4 changes: 2 additions & 2 deletions core/market/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ chrono = { version = "0.4", features = ["serde"] }
derive_more = { workspace = true }
diesel = { version = "1.4", features = ["chrono", "sqlite", "r2d2"] }
diesel_migrations = "1.4"
digest = "0.8.1"
digest = "0.10"
env_logger = { version = "0.7" }
futures = "0.3"
humantime = "2"
Expand All @@ -55,7 +55,7 @@ regex = "1.4.2"
serde = { version = "1.0", features = ["derive"] }
serde_bytes = "0.11.14"
serde_json = "1.0"
sha3 = "0.8.2"
sha3 = "0.10"
structopt = "0.3"
strum = { workspace = true }
strum_macros = "0.24"
Expand Down
8 changes: 4 additions & 4 deletions core/market/src/db/model/proposal_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ pub fn hash_proposal(
) -> String {
let mut hasher = Sha3_256::new();

hasher.input(offer_id.to_string());
hasher.input(demand_id.to_string());
hasher.input(creation_ts.format("%Y-%m-%d %H:%M:%f").to_string());
hasher.update(offer_id.to_string());
hasher.update(demand_id.to_string());
hasher.update(creation_ts.format("%Y-%m-%d %H:%M:%f").to_string());

format!("{:x}", hasher.result())
format!("{:x}", hasher.finalize())
}

impl FromStr for ProposalId {
Expand Down
12 changes: 6 additions & 6 deletions core/market/src/db/model/subscription_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ pub fn hash(
) -> String {
let mut hasher = Sha3_256::new();

hasher.input(properties);
hasher.input(constraints);
hasher.input(node_id);
hasher.update(properties);
hasher.update(constraints);
hasher.update(node_id);
// We can't change format freely, because it is important to compute hash.
// Is there any other solution, to compute hash, that is format independent?
hasher.input(creation_ts.format("%Y-%m-%d %H:%M:%f").to_string());
hasher.input(expiration_ts.format("%Y-%m-%d %H:%M:%f").to_string());
hasher.update(creation_ts.format("%Y-%m-%d %H:%M:%f").to_string());
hasher.update(expiration_ts.format("%Y-%m-%d %H:%M:%f").to_string());

format!("{:x}", hasher.result())
format!("{:x}", hasher.finalize())
}

impl FromStr for SubscriptionId {
Expand Down
2 changes: 1 addition & 1 deletion core/payment-driver/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ num-bigint = { version = "0.3", features = ["serde"] }
num-traits = "0.2"
num-derive = "0.3"
r2d2 = "0.8"
sha3 = "0.9"
sha3 = "0.10"
thiserror = "1.0"
tokio = { version = "1", features = ["macros"] }

Expand Down
2 changes: 1 addition & 1 deletion core/payment-driver/erc20/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ num-traits = "0.2"
rlp = "0.5"
serde = "1.0"
serde_json = "^1.0"
sha3 = "0.8"
sha3 = "0.10"
thiserror = "1.0"
tiny-keccak = { version = "2.0", features = ["keccak"] }
tokio = { version = "1", features = ["full"] }
Expand Down
3 changes: 2 additions & 1 deletion core/vpn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ default = []
[dev-dependencies]
ya-client = { workspace = true }
actix-rt = "2.7"
sha3 = "0.8.2"
digest = "0.10"
sha3 = "0.10"
structopt = "0.3"
tokio = { version = "1", features = ["time", "fs"] }
url = "2.1"
Expand Down
10 changes: 5 additions & 5 deletions core/vpn/examples/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ use actix::prelude::*;
use actix_web_actors::ws;
use actix_web_actors::ws::Frame;
use bytes::Bytes;
use digest::{Digest, Output};
use futures::{SinkExt, StreamExt};
use sha3::digest::generic_array::GenericArray;
use sha3::Digest;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
use tokio::fs::OpenOptions;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use url::Url;

use ya_client::net::NetVpnApi;
use ya_client::web::WebClient;
use ya_client_model::net::{Address, NewNetwork, Node};

type HashOutput = GenericArray<u8, <sha3::Sha3_512 as Digest>::OutputSize>;
type HashOutput = Output<sha3::Sha3_512>;

#[derive(StructOpt, Clone, Debug)]
struct Cli {
Expand Down Expand Up @@ -50,10 +50,10 @@ async fn file_checksum<P: AsRef<Path>>(path: P) -> anyhow::Result<HashOutput> {
if count == 0 {
break;
}
hasher.input(&chunk[..count]);
hasher.update(&chunk[..count]);
}

Ok(hasher.result())
Ok(hasher.finalize())
}

#[actix_rt::main]
Expand Down
4 changes: 2 additions & 2 deletions exe-unit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ secp256k1 = { version = "0.27.0", optional = true }
serde = { version = "^1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.8"
sha3 = "0.8.2"
sha3 = "0.10"
signal-hook = "0.3"
socket2 = "0.4"
structopt = "0.3"
Expand Down Expand Up @@ -104,7 +104,7 @@ actix-files = "0.6"
actix-web = "4"
env_logger = "0.7"
rustyline = "7.0.0"
sha3 = "0.8.2"
sha3 = "0.10"
shell-words = "1.0.0"
tempdir = "0.3.7"

Expand Down
7 changes: 5 additions & 2 deletions exe-unit/components/transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ actix-rt = "2.7"
anyhow = "1.0"
# async-compression 0.3.8+ deprecates the "stream" module
async-compression = { version = "=0.3.7", features = ["tokio", "futures-io", "stream", "bzip2", "gzip", "xz"] }
blake2 = "0.10"
blake3 = { version = "1.5", features = ["traits-preview"] }
bytes = "1.0"
futures = "0.3.4"
globset = "0.4.5"
Expand All @@ -34,7 +36,8 @@ rand = "0.8"
regex = "1.3.4"
reqwest = { version = "0.11", optional = true }
serde = "1.0.104"
sha3 = "0.8.2"
sha2 = "0.10"
sha3 = "0.10"
tempdir = "0.3.7"
thiserror = "1.0.11"
tokio = { version = "1", features = ["fs", "io-util"] }
Expand Down Expand Up @@ -73,10 +76,10 @@ actix-web = "4"
actix-rt = "2.9.0"
anyhow = "1.0"
crossterm = "0.26.1"
digest = "0.10"
env_logger = "0.7"
secp256k1 = { version = "0.27.0" }
serial_test = { git = "https://github.com/tworec/serial_test.git", branch = "actix_rt_test", features = ["actix-rt2"] }
sha2 = "0.8.1"
structopt = "0.3.15"
test-context = "0.1.4"
test-case = "3"
Expand Down
13 changes: 6 additions & 7 deletions exe-unit/components/transfer/examples/gftp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crossterm::{cursor, terminal, ExecutableCommand, QueueableCommand};
use digest::{Digest, Output};
use rand::RngCore;
use sha3::digest::generic_array::GenericArray;
use sha3::Digest;
use std::env;
use std::fs::OpenOptions;
use std::io::{Read, Write};
Expand All @@ -14,7 +13,7 @@ use ya_transfer::{
transfer, FileTransferProvider, GftpTransferProvider, TransferContext, TransferProvider,
};

type HashOutput = GenericArray<u8, <sha3::Sha3_512 as Digest>::OutputSize>;
type HashOutput = Output<sha3::Sha3_512>;

fn create_file(path: &Path, name: &str, chunk_size: usize, chunk_count: usize) -> HashOutput {
let path = path.join(name);
Expand All @@ -32,11 +31,11 @@ fn create_file(path: &Path, name: &str, chunk_size: usize, chunk_count: usize) -
for _ in 0..chunk_count {
rng.fill_bytes(&mut input);

hasher.input(&input);
hasher.update(&input);
file_src.write_all(&input).unwrap();
}
file_src.flush().unwrap();
hasher.result()
hasher.finalize()
}

fn hash_file(path: &Path) -> HashOutput {
Expand All @@ -46,12 +45,12 @@ fn hash_file(path: &Path) -> HashOutput {
let mut chunk = vec![0; 4096];

while let Ok(count) = file_src.read(&mut chunk[..]) {
hasher.input(&chunk[..count]);
hasher.update(&chunk[..count]);
if count != 4096 {
break;
}
}
hasher.result()
hasher.finalize()
}

// processing progress updates must not panic or the transfer will be aborted
Expand Down
6 changes: 3 additions & 3 deletions exe-unit/components/transfer/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ impl CachePath {
/// Creates the long version of path, including hash and the "random" token.
pub fn temp_path(&self) -> PathBuf {
let mut digest = sha3::Sha3_224::default();
digest.input(&self.hash);
digest.input(&self.nonce);
let hash = digest.result();
digest.update(&self.hash);
digest.update(&self.nonce);
let hash = digest.finalize();
PathBuf::from(hex::encode(hash))
}

Expand Down
6 changes: 4 additions & 2 deletions exe-unit/components/transfer/src/gftp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::error::Error;
use crate::{abortable_sink, abortable_stream};
use crate::{TransferContext, TransferData, TransferProvider, TransferSink, TransferStream};

use bytes::Bytes;
use futures::channel::mpsc;
use futures::future::{ready, try_select, Either};
Expand All @@ -9,6 +10,7 @@ use gftp::DEFAULT_CHUNK_SIZE;
use sha3::{Digest, Sha3_256};
use tokio::task::spawn_local;
use url::Url;

use ya_core_model::gftp as model;
use ya_core_model::gftp::Error as GftpError;
use ya_core_model::gftp::GftpChunk;
Expand Down Expand Up @@ -109,12 +111,12 @@ impl TransferProvider<TransferData, Error> for GftpTransferProvider {
};

offset += chunk.content.len();
digest.input(&chunk.content);
digest.update(&chunk.content);
chunk_tx.send(Ok::<_, Error>(chunk)).await?;
}
}

Ok::<_, Error>(digest.result())
Ok::<_, Error>(digest.finalize())
};

let send_fut = chunk_rx.try_for_each_concurrent(concurrency, |chunk| async {
Expand Down
Loading

0 comments on commit 877c726

Please sign in to comment.