mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-16 08:10:40 +08:00
Ref announcements contain the namespace (NID) and the SHA of the new `rad/sigrefs`. This information can be used by the fetch protocol to fetch only those `Oid`s for those namespaces. Add a new stage `SigrefsAnnouncement` that captures this behaviour by only asking for the advertised `Oid`s and updating the corresponding `rad/sigrefs` for each namespace. Note that this is a special case of the `SpecialRefs` stage and so the protocol chooses between these two by checking if there was announcement passed through. The following stage, `DataRefs`, stays the same. Note that this stage can only be activated via a `pull`, and `clone` stays the same. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
109 lines
2.6 KiB
Rust
109 lines
2.6 KiB
Rust
pub mod git;
|
|
pub mod handle;
|
|
pub mod tracking;
|
|
pub mod transport;
|
|
|
|
pub(crate) mod sigrefs;
|
|
|
|
mod refs;
|
|
mod stage;
|
|
mod state;
|
|
|
|
pub use handle::Handle;
|
|
pub use state::{FetchLimit, FetchResult};
|
|
pub use tracking::{BlockList, Scope, Tracked};
|
|
pub use transport::Transport;
|
|
|
|
use std::io;
|
|
|
|
use radicle::crypto::PublicKey;
|
|
use radicle::storage::refs::RefsAt;
|
|
use state::FetchState;
|
|
use thiserror::Error;
|
|
|
|
#[derive(Debug, Error)]
|
|
pub enum Error {
|
|
#[error("failed to perform fetch handshake")]
|
|
Handshake {
|
|
#[source]
|
|
err: io::Error,
|
|
},
|
|
#[error("failed to load `rad/id`")]
|
|
Identity {
|
|
#[source]
|
|
err: Box<dyn std::error::Error + Send + Sync + 'static>,
|
|
},
|
|
#[error(transparent)]
|
|
Protocol(#[from] state::error::Protocol),
|
|
#[error("missing `rad/id`")]
|
|
MissingRadId,
|
|
#[error("attempted to replicate from self")]
|
|
ReplicateSelf,
|
|
}
|
|
|
|
/// Pull changes from the `remote`.
|
|
///
|
|
/// It is expected that the local peer has a copy of the repository
|
|
/// and is pulling new changes. If the repository does not exist, then
|
|
/// [`clone`] should be used.
|
|
pub fn pull<S>(
|
|
handle: &mut Handle<S>,
|
|
limit: FetchLimit,
|
|
remote: PublicKey,
|
|
refs_at: Option<Vec<RefsAt>>,
|
|
) -> Result<FetchResult, Error>
|
|
where
|
|
S: transport::ConnectionStream,
|
|
{
|
|
let local = *handle.local();
|
|
if local == remote {
|
|
return Err(Error::ReplicateSelf);
|
|
}
|
|
let state = FetchState::default();
|
|
let handshake = handle
|
|
.transport
|
|
.handshake()
|
|
.map_err(|err| Error::Handshake { err })?;
|
|
// N.b. ensure that we ignore the local peer's key.
|
|
handle.blocked.extend([local]);
|
|
state
|
|
.run(handle, &handshake, limit, remote, refs_at)
|
|
.map_err(Error::Protocol)
|
|
}
|
|
|
|
/// Clone changes from the `remote`.
|
|
///
|
|
/// It is expected that the local peer has an empty repository which
|
|
/// they want to populate with the `remote`'s view of the project.
|
|
pub fn clone<S>(
|
|
handle: &mut Handle<S>,
|
|
limit: FetchLimit,
|
|
remote: PublicKey,
|
|
) -> Result<FetchResult, Error>
|
|
where
|
|
S: transport::ConnectionStream,
|
|
{
|
|
if *handle.local() == remote {
|
|
return Err(Error::ReplicateSelf);
|
|
}
|
|
let handshake = handle
|
|
.transport
|
|
.handshake()
|
|
.map_err(|err| Error::Handshake { err })?;
|
|
let mut state = FetchState::default();
|
|
state
|
|
.run_stage(
|
|
handle,
|
|
&handshake,
|
|
&stage::CanonicalId {
|
|
remote,
|
|
limit: limit.special,
|
|
},
|
|
)
|
|
.map_err(|e| Error::from(state::error::Protocol::from(e)))?;
|
|
|
|
state
|
|
.run(handle, &handshake, limit, remote, None)
|
|
.map_err(Error::Protocol)
|
|
}
|