Skip to main content

NetworkManager

Struct NetworkManager 

Source
pub struct NetworkManager { /* private fields */ }
Expand description

Network manager for FAI Protocol

Implementations§

Source§

impl NetworkManager

Source

pub fn new( storage: Arc<StorageManager>, database: DatabaseManager, ) -> Result<Self>

Create a new network manager

§Arguments
  • storage - Storage manager for retrieving chunks
  • database - Database manager for commit operations
§Returns

A new NetworkManager instance with configured libp2p stack

Source

pub async fn start(&mut self) -> Result<()>

Start the network manager and begin listening

§Returns

Ok(()) if successfully started

Source

pub async fn poll_events(&mut self) -> Result<()>

Poll for network events and handle them

§Returns

Ok(()) if events processed successfully

Source

pub fn list_peers(&self) -> Vec<PeerInfo>

Get list of discovered peers

§Returns

Vector of PeerInfo for all discovered peers

Source

pub fn local_peer_id(&self) -> PeerId

Get local peer ID

§Returns

The local peer ID

Source

pub fn listeners(&self) -> Vec<Multiaddr>

Get listening addresses

§Returns

Vector of addresses the swarm is listening on

Source

pub fn connect_to_peer(&mut self, addr: Multiaddr) -> Result<()>

Connect to a peer by address

§Arguments
  • addr - The multiaddress of the peer to connect to
§Returns

Ok(()) if connection initiated successfully

Source

pub fn load_peers_from_files(&mut self) -> Result<usize>

Load peer info from shared files (useful for testing)

Source

pub fn add_peer_manually( &mut self, peer_id: PeerId, addr: Multiaddr, ) -> Result<()>

Add a peer to the discovered peers list manually

§Arguments
  • peer_id - The peer ID
  • addr - The multiaddress of the peer
§Returns

Ok(()) if peer added successfully

Source

pub fn connect_to_known_peers( &mut self, peer_addrs: Vec<(PeerId, Multiaddr)>, ) -> Result<()>

Connect to multiple known peers (useful for testing)

§Arguments
  • peer_addrs - List of (peer_id, address) tuples to connect to
§Returns

Ok(()) if all connections initiated successfully

Source

pub async fn request_chunk( &mut self, peer: PeerId, hash: &str, ) -> Result<Option<Vec<u8>>>

Request a chunk of data from a peer

§Arguments
  • peer - The peer to request from
  • hash - The hash of the data to request
§Returns

The data if found, None if not found

Source

pub async fn request_commits( &mut self, peer: PeerId, commit_hash: Option<String>, ) -> Result<Vec<CommitInfo>>

Request commits from a peer

§Arguments
  • peer - The peer to request from
  • commit_hash - Optional specific commit hash to request
§Returns

Vector of commits

Source

pub async fn send_commits( &mut self, peer: PeerId, commits: Vec<CommitInfo>, ) -> Result<()>

Send commits to a peer (主动推送)

§Arguments
  • peer - The peer to send commits to
  • commits - The commits to send
§Returns

Ok(()) if commits were sent successfully

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more