0g-storage-node/node/file_location_cache/src/test_util.rs
Bo QIU 9b4b0436c3
Supports to sync partial chunks (#4)
* refactor p2p signed message

* add new pubsub messages in network layer to find chunks

* handle find chunks pubsub message in router

* Supports to sync partial chunks

* add admin rpc to sync chunks

* limit number of chunks to sync at a time

* refactor code to sync file and chunks

* add more switches to trigger file sync

* fix ut failure

* refactor code
2024-01-19 14:04:59 +08:00

48 lines
1.3 KiB
Rust

use network::{
libp2p::identity,
types::{AnnounceFile, SignedAnnounceFile, SignedMessage},
Multiaddr, PeerId,
};
use shared_types::{timestamp_now, TxID};
#[derive(Default)]
pub struct AnnounceFileBuilder {
tx_id: Option<TxID>,
peer_id: Option<PeerId>,
timestamp: Option<u32>,
}
impl AnnounceFileBuilder {
pub fn with_tx_id(mut self, tx_id: TxID) -> Self {
self.tx_id = Some(tx_id);
self
}
pub fn with_peer_id(mut self, peer_id: PeerId) -> Self {
self.peer_id = Some(peer_id);
self
}
pub fn with_timestamp(mut self, timestamp: u32) -> Self {
self.timestamp = Some(timestamp);
self
}
pub fn build(self) -> SignedAnnounceFile {
let tx_id = self.tx_id.unwrap_or_else(|| TxID::random_hash(0));
let peer_id = self.peer_id.unwrap_or_else(PeerId::random);
let at: Multiaddr = "/ip4/127.0.0.1/tcp/10000".parse().unwrap();
let timestamp = self.timestamp.unwrap_or_else(timestamp_now);
let msg = AnnounceFile {
tx_id,
peer_id: peer_id.into(),
at: at.into(),
timestamp,
};
let keypair = identity::Keypair::generate_secp256k1();
SignedMessage::sign_message(msg, &keypair).unwrap()
}
}