Struct sn_api::SectionTree
source · pub struct SectionTree { /* private fields */ }
Expand description
Container for storing information about other sections in the network.
Implementations§
source§impl SectionTree
impl SectionTree
sourcepub fn new(
genesis_sap: SectionSigned<SectionAuthorityProvider>
) -> Result<SectionTree, Error>
pub fn new( genesis_sap: SectionSigned<SectionAuthorityProvider> ) -> Result<SectionTree, Error>
Create a SectionTree
with just the genesis section
sourcepub fn from_bytes(bytes: &[u8]) -> Result<SectionTree, Error>
pub fn from_bytes(bytes: &[u8]) -> Result<SectionTree, Error>
Create a new SectionTree deserialised from bytes
sourcepub async fn from_disk(
path: &Path
) -> impl Future<Output = Result<SectionTree, Error>>
pub async fn from_disk( path: &Path ) -> impl Future<Output = Result<SectionTree, Error>>
Create a new SectionTree deserialised from a file
sourcepub fn genesis_key(&self) -> &PublicKey
pub fn genesis_key(&self) -> &PublicKey
Returns the genesis key of the Network
pub fn get_sections_dag(&self) -> &SectionsDAG
pub fn prefixes(&self) -> impl Iterator<Item = &Prefix>
sourcepub fn closest(
&self,
name: &XorName,
exclude: Option<&Prefix>
) -> Option<&SectionSigned<SectionAuthorityProvider>>
pub fn closest( &self, name: &XorName, exclude: Option<&Prefix> ) -> Option<&SectionSigned<SectionAuthorityProvider>>
Returns the known section that is closest to the given name,
regardless of whether name
belongs in that section or not.
If provided, it excludes any section matching the passed prefix.
sourcepub fn all(&self) -> impl Iterator<Item = &SectionAuthorityProvider>
pub fn all(&self) -> impl Iterator<Item = &SectionAuthorityProvider>
Returns all known sections SAP.
sourcepub fn get(&self, prefix: &Prefix) -> Option<SectionAuthorityProvider>
pub fn get(&self, prefix: &Prefix) -> Option<SectionAuthorityProvider>
Get SectionAuthorityProvider
of a known section with the given prefix.
sourcepub fn get_signed(
&self,
prefix: &Prefix
) -> Option<&SectionSigned<SectionAuthorityProvider>>
pub fn get_signed( &self, prefix: &Prefix ) -> Option<&SectionSigned<SectionAuthorityProvider>>
Get signed SectionAuthorityProvider
of a known section with the given prefix.
sourcepub fn get_signed_by_key(
&self,
section_key: &PublicKey
) -> Option<&SectionSigned<SectionAuthorityProvider>>
pub fn get_signed_by_key( &self, section_key: &PublicKey ) -> Option<&SectionSigned<SectionAuthorityProvider>>
Get signed SectionAuthorityProvider
of a known section with the given section key.
sourcepub fn get_signed_by_name(
&self,
name: &XorName
) -> Result<SectionSigned<SectionAuthorityProvider>, Error>
pub fn get_signed_by_name( &self, name: &XorName ) -> Result<SectionSigned<SectionAuthorityProvider>, Error>
Returns the section authority provider for the prefix that matches name
.
In case there is no prefix matches the name
, we shall return the one with longest
common bits. i.e. for the name of 00xxx
, if we have 01
and 1
, then we shall return
with 01
.
sourcepub fn get_signed_by_prefix(
&self,
prefix: &Prefix
) -> Result<SectionSigned<SectionAuthorityProvider>, Error>
pub fn get_signed_by_prefix( &self, prefix: &Prefix ) -> Result<SectionSigned<SectionAuthorityProvider>, Error>
Get the section that matches prefix
. In case of multiple matches, returns the
one with the longest prefix.
sourcepub fn section_keys(&self) -> Vec<PublicKey, Global>
pub fn section_keys(&self) -> Vec<PublicKey, Global>
Returns the known section public keys.
sourcepub fn known_sections_count(&self) -> usize
pub fn known_sections_count(&self) -> usize
Get total number of known sections
pub fn generate_section_tree_update( &self, prefix: &Prefix ) -> Result<SectionTreeUpdate, Error>
sourcepub fn update_the_section_tree(
&mut self,
section_tree_update: SectionTreeUpdate
) -> Result<bool, Error>
pub fn update_the_section_tree( &mut self, section_tree_update: SectionTreeUpdate ) -> Result<bool, Error>
Update our SectionTree
if the provided update can be verified
Returns true if an update was made
sourcepub fn insert_without_chain(
&mut self,
sap: SectionSigned<SectionAuthorityProvider>
) -> bool
pub fn insert_without_chain( &mut self, sap: SectionSigned<SectionAuthorityProvider> ) -> bool
For testing purpose, we may need to populate a section_tree
without a proof chain.
sourcepub async fn write_to_disk(
&self,
path: &Path
) -> impl Future<Output = Result<(), Error>>
pub async fn write_to_disk( &self, path: &Path ) -> impl Future<Output = Result<(), Error>>
Serialise and write it to disk on the provided file path
sourcepub fn network_stats(&self, our: &SectionAuthorityProvider) -> NetworkStats
pub fn network_stats(&self, our: &SectionAuthorityProvider) -> NetworkStats
Returns network statistics.
Trait Implementations§
source§impl Clone for SectionTree
impl Clone for SectionTree
source§fn clone(&self) -> SectionTree
fn clone(&self) -> SectionTree
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SectionTree
impl Debug for SectionTree
source§impl<'de> Deserialize<'de> for SectionTree
impl<'de> Deserialize<'de> for SectionTree
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<SectionTree, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>( __deserializer: __D ) -> Result<SectionTree, <__D as Deserializer<'de>>::Error>where __D: Deserializer<'de>,
source§impl Ord for SectionTree
impl Ord for SectionTree
source§fn cmp(&self, other: &SectionTree) -> Ordering
fn cmp(&self, other: &SectionTree) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<SectionTree> for SectionTree
impl PartialEq<SectionTree> for SectionTree
source§fn eq(&self, other: &SectionTree) -> bool
fn eq(&self, other: &SectionTree) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<SectionTree> for SectionTree
impl PartialOrd<SectionTree> for SectionTree
source§fn partial_cmp(&self, other: &SectionTree) -> Option<Ordering>
fn partial_cmp(&self, other: &SectionTree) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl Serialize for SectionTree
impl Serialize for SectionTree
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where __S: Serializer,
impl Eq for SectionTree
Auto Trait Implementations§
impl RefUnwindSafe for SectionTree
impl Send for SectionTree
impl Sync for SectionTree
impl Unpin for SectionTree
impl UnwindSafe for SectionTree
Blanket Implementations§
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where &'a Self: for<'a> IntoIterator,
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere Self: Borrow<B>, B: 'a + ?Sized, R: 'a,
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> Rwhere Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere Self: AsRef<U>, U: 'a + ?Sized, R: 'a,
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere Self: AsMut<U>, U: 'a + ?Sized, R: 'a,
self
, then passes self.as_mut()
into the pipe
function.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere Self: Deref<Target = T>, T: ?Sized,
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere Self: DerefMut<Target = T> + Deref, T: ?Sized,
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere Self: Borrow<B>, B: ?Sized,
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere Self: BorrowMut<B>, B: ?Sized,
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere Self: AsRef<R>, R: ?Sized,
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere Self: AsMut<R>, R: ?Sized,
.tap_ref_mut()
only in debug builds, and is erased in release
builds.