2024-01-22 01:56:34 +00:00
|
|
|
use monero_pruning::{PruningError, PruningSeed};
|
2023-12-08 15:03:01 +00:00
|
|
|
use monero_wire::{NetZone, NetworkAddress, PeerListEntryBase};
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
client::InternalPeerID, handles::ConnectionHandle, NetZoneAddress, NetworkAddressIncorrectZone,
|
|
|
|
NetworkZone,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub enum CoreSyncDataRequest {
|
|
|
|
Ours,
|
|
|
|
HandleIncoming(monero_wire::CoreSyncData),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum CoreSyncDataResponse {
|
|
|
|
Ours(monero_wire::CoreSyncData),
|
|
|
|
Ok,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
|
|
|
#[cfg_attr(
|
|
|
|
feature = "borsh",
|
|
|
|
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
|
|
|
|
)]
|
|
|
|
pub struct ZoneSpecificPeerListEntryBase<A: NetZoneAddress> {
|
|
|
|
pub adr: A,
|
|
|
|
pub id: u64,
|
|
|
|
pub last_seen: i64,
|
|
|
|
pub pruning_seed: PruningSeed,
|
|
|
|
pub rpc_port: u16,
|
|
|
|
pub rpc_credits_per_hash: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<A: NetZoneAddress> From<ZoneSpecificPeerListEntryBase<A>> for monero_wire::PeerListEntryBase {
|
|
|
|
fn from(value: ZoneSpecificPeerListEntryBase<A>) -> Self {
|
|
|
|
Self {
|
|
|
|
adr: value.adr.into(),
|
|
|
|
id: value.id,
|
|
|
|
last_seen: value.last_seen,
|
2024-03-15 22:11:27 +00:00
|
|
|
pruning_seed: value.pruning_seed.compress(),
|
2023-12-08 15:03:01 +00:00
|
|
|
rpc_port: value.rpc_port,
|
|
|
|
rpc_credits_per_hash: value.rpc_credits_per_hash,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, thiserror::Error)]
|
|
|
|
pub enum PeerListConversionError {
|
|
|
|
#[error("Address is in incorrect zone")]
|
|
|
|
Address(#[from] NetworkAddressIncorrectZone),
|
|
|
|
#[error("Pruning seed error: {0}")]
|
|
|
|
PruningSeed(#[from] PruningError),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<A: NetZoneAddress> TryFrom<monero_wire::PeerListEntryBase>
|
|
|
|
for ZoneSpecificPeerListEntryBase<A>
|
|
|
|
{
|
|
|
|
type Error = PeerListConversionError;
|
|
|
|
|
|
|
|
fn try_from(value: PeerListEntryBase) -> Result<Self, Self::Error> {
|
|
|
|
Ok(Self {
|
|
|
|
adr: value.adr.try_into()?,
|
|
|
|
id: value.id,
|
|
|
|
last_seen: value.last_seen,
|
2024-03-15 22:11:27 +00:00
|
|
|
pruning_seed: PruningSeed::decompress_p2p_rules(value.pruning_seed)?,
|
2023-12-08 15:03:01 +00:00
|
|
|
rpc_port: value.rpc_port,
|
|
|
|
rpc_credits_per_hash: value.rpc_credits_per_hash,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum AddressBookRequest<Z: NetworkZone> {
|
2024-03-20 20:58:12 +00:00
|
|
|
/// Tells the address book that we have connected or received a connection from a peer.
|
2023-12-08 15:03:01 +00:00
|
|
|
NewConnection {
|
2024-03-20 20:58:12 +00:00
|
|
|
/// The [`InternalPeerID`] of this connection.
|
2023-12-08 15:03:01 +00:00
|
|
|
internal_peer_id: InternalPeerID<Z::Addr>,
|
2024-03-20 20:58:12 +00:00
|
|
|
/// The public address of the peer, if this peer has a reachable public address.
|
|
|
|
public_address: Option<Z::Addr>,
|
|
|
|
/// The [`ConnectionHandle`] to this peer.
|
2023-12-08 15:03:01 +00:00
|
|
|
handle: ConnectionHandle,
|
2024-03-20 20:58:12 +00:00
|
|
|
/// An ID the peer assigned itself.
|
2023-12-08 15:03:01 +00:00
|
|
|
id: u64,
|
2024-03-20 20:58:12 +00:00
|
|
|
/// The peers [`PruningSeed`].
|
2023-12-08 15:03:01 +00:00
|
|
|
pruning_seed: PruningSeed,
|
2024-03-20 20:58:12 +00:00
|
|
|
/// The peers rpc port.
|
2023-12-08 15:03:01 +00:00
|
|
|
rpc_port: u16,
|
|
|
|
/// The peers rpc credits per hash
|
|
|
|
rpc_credits_per_hash: u32,
|
|
|
|
},
|
2024-03-20 20:58:12 +00:00
|
|
|
/// Tells the address book about a peer list received from a peer.
|
2023-12-08 15:03:01 +00:00
|
|
|
IncomingPeerList(Vec<ZoneSpecificPeerListEntryBase<Z::Addr>>),
|
2024-03-20 20:58:12 +00:00
|
|
|
/// Takes a random white peer from the peer list. If height is specified
|
2023-12-08 15:03:01 +00:00
|
|
|
/// then the peer list should retrieve a peer that should have a full
|
|
|
|
/// block at that height according to it's pruning seed
|
2024-03-20 20:58:12 +00:00
|
|
|
TakeRandomWhitePeer { height: Option<u64> },
|
|
|
|
/// Takes a random gray peer from the peer list. If height is specified
|
2023-12-08 15:03:01 +00:00
|
|
|
/// then the peer list should retrieve a peer that should have a full
|
|
|
|
/// block at that height according to it's pruning seed
|
2024-03-20 20:58:12 +00:00
|
|
|
TakeRandomGrayPeer { height: Option<u64> },
|
|
|
|
/// Takes a random peer from the peer list. If height is specified
|
|
|
|
/// then the peer list should retrieve a peer that should have a full
|
|
|
|
/// block at that height according to it's pruning seed.
|
|
|
|
///
|
|
|
|
/// The address book will look in the white peer list first, then the gray
|
|
|
|
/// one if no peer is found.
|
|
|
|
TakeRandomPeer { height: Option<u64> },
|
|
|
|
/// Gets the specified number of white peers, or less if we don't have enough.
|
2023-12-08 15:03:01 +00:00
|
|
|
GetWhitePeers(usize),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum AddressBookResponse<Z: NetworkZone> {
|
|
|
|
Ok,
|
|
|
|
Peer(ZoneSpecificPeerListEntryBase<Z::Addr>),
|
|
|
|
Peers(Vec<ZoneSpecificPeerListEntryBase<Z::Addr>>),
|
|
|
|
}
|