mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-12 17:41:22 +00:00
chore: enforce unreachable_pub
lint
The `unreachable_pub` lint makes us aware of uses of `pub` that are not actually reachable from the crate root. This is considered good because it means reading a `pub` somewhere means it is actually public API. Some of our crates are quite large and keeping their entire API surface in your head is difficult. We should strive for most items being `pub(crate)`. This lint helps us enforce that. Pull-Request: #3735.
This commit is contained in:
@ -33,7 +33,7 @@ use std::iter;
|
||||
/// - The network event stream, e.g. for incoming requests.
|
||||
///
|
||||
/// - The network task driving the network itself.
|
||||
pub async fn new(
|
||||
pub(crate) async fn new(
|
||||
secret_key_seed: Option<u8>,
|
||||
) -> Result<(Client, impl Stream<Item = Event>, EventLoop), Box<dyn Error>> {
|
||||
// Create a public/private key pair, either random or based on a seed.
|
||||
@ -82,13 +82,16 @@ pub async fn new(
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Client {
|
||||
pub(crate) struct Client {
|
||||
sender: mpsc::Sender<Command>,
|
||||
}
|
||||
|
||||
impl Client {
|
||||
/// Listen for incoming connections on the given address.
|
||||
pub async fn start_listening(&mut self, addr: Multiaddr) -> Result<(), Box<dyn Error + Send>> {
|
||||
pub(crate) async fn start_listening(
|
||||
&mut self,
|
||||
addr: Multiaddr,
|
||||
) -> Result<(), Box<dyn Error + Send>> {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
self.sender
|
||||
.send(Command::StartListening { addr, sender })
|
||||
@ -98,7 +101,7 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Dial the given peer at the given address.
|
||||
pub async fn dial(
|
||||
pub(crate) async fn dial(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
peer_addr: Multiaddr,
|
||||
@ -116,7 +119,7 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Advertise the local node as the provider of the given file on the DHT.
|
||||
pub async fn start_providing(&mut self, file_name: String) {
|
||||
pub(crate) async fn start_providing(&mut self, file_name: String) {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
self.sender
|
||||
.send(Command::StartProviding { file_name, sender })
|
||||
@ -126,7 +129,7 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Find the providers for the given file on the DHT.
|
||||
pub async fn get_providers(&mut self, file_name: String) -> HashSet<PeerId> {
|
||||
pub(crate) async fn get_providers(&mut self, file_name: String) -> HashSet<PeerId> {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
self.sender
|
||||
.send(Command::GetProviders { file_name, sender })
|
||||
@ -136,7 +139,7 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Request the content of the given file from the given peer.
|
||||
pub async fn request_file(
|
||||
pub(crate) async fn request_file(
|
||||
&mut self,
|
||||
peer: PeerId,
|
||||
file_name: String,
|
||||
@ -154,7 +157,11 @@ impl Client {
|
||||
}
|
||||
|
||||
/// Respond with the provided file content to the given request.
|
||||
pub async fn respond_file(&mut self, file: Vec<u8>, channel: ResponseChannel<FileResponse>) {
|
||||
pub(crate) async fn respond_file(
|
||||
&mut self,
|
||||
file: Vec<u8>,
|
||||
channel: ResponseChannel<FileResponse>,
|
||||
) {
|
||||
self.sender
|
||||
.send(Command::RespondFile { file, channel })
|
||||
.await
|
||||
@ -162,7 +169,7 @@ impl Client {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EventLoop {
|
||||
pub(crate) struct EventLoop {
|
||||
swarm: Swarm<ComposedBehaviour>,
|
||||
command_receiver: mpsc::Receiver<Command>,
|
||||
event_sender: mpsc::Sender<Event>,
|
||||
@ -190,7 +197,7 @@ impl EventLoop {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run(mut self) {
|
||||
pub(crate) async fn run(mut self) {
|
||||
loop {
|
||||
futures::select! {
|
||||
event = self.swarm.next() => self.handle_event(event.expect("Swarm stream to be infinite.")).await ,
|
||||
@ -452,7 +459,7 @@ enum Command {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Event {
|
||||
pub(crate) enum Event {
|
||||
InboundRequest {
|
||||
request: String,
|
||||
channel: ResponseChannel<FileResponse>,
|
||||
@ -468,8 +475,7 @@ struct FileExchangeCodec();
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
struct FileRequest(String);
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct FileResponse(Vec<u8>);
|
||||
|
||||
pub(crate) struct FileResponse(Vec<u8>);
|
||||
impl ProtocolName for FileExchangeProtocol {
|
||||
fn protocol_name(&self) -> &[u8] {
|
||||
"/file-exchange/1".as_bytes()
|
||||
|
Reference in New Issue
Block a user