MCPcopy Create free account
hub / github.com/ceramicnetwork/rust-ceramic / handle_rpc_message

Method handle_rpc_message

p2p/src/node.rs:958–1229  ·  view source on GitHub ↗
(&mut self, message: RpcMessage)

Source from the content-addressed store, hash-verified

956
957 #[tracing::instrument(skip(self))]
958 async fn handle_rpc_message(&mut self, message: RpcMessage) -> Result<bool> {
959 // Inbound messages
960 match message {
961 RpcMessage::ExternalAddrs(response_channel) => {
962 response_channel
963 .send(self.swarm.external_addresses().cloned().collect())
964 .ok();
965 }
966 RpcMessage::Listeners(response_channel) => {
967 response_channel
968 .send(self.swarm.listeners().cloned().collect())
969 .ok();
970 }
971 RpcMessage::LocalPeerId(response_channel) => {
972 response_channel.send(*self.swarm.local_peer_id()).ok();
973 }
974 RpcMessage::BitswapRequest {
975 ctx,
976 cids,
977 response_channels,
978 providers,
979 } => {
980 trace!("context:{} bitswap_request", ctx);
981 for (cid, response_channel) in cids.into_iter().zip(response_channels.into_iter()) {
982 self.want_block(ctx, cid, providers.clone(), response_channel)
983 .map_err(|err| anyhow!("Failed to send a bitswap want_block: {:?}", err))?;
984 }
985 }
986 RpcMessage::BitswapNotifyNewBlocks {
987 blocks,
988 response_channel,
989 } => {
990 self.swarm.behaviour().notify_new_blocks(blocks);
991 response_channel.send(Ok(())).ok();
992 }
993 RpcMessage::BitswapStopSession {
994 ctx,
995 response_channel,
996 } => {
997 self.destroy_session(ctx, response_channel);
998 }
999 RpcMessage::ProviderRequest {
1000 key,
1001 limit,
1002 response_channel,
1003 } => match key {
1004 ProviderRequestKey::Dht(key) => {
1005 debug!("fetching providers for: {:?}", key);
1006 if self.swarm.behaviour().kad.is_enabled() {
1007 if !self.providers.push(key.clone(), limit, response_channel) {
1008 warn!("provider query dropped because the queue is full {:?}", key);
1009 }
1010 } else {
1011 tokio::task::spawn(async move {
1012 response_channel
1013 .send(Err("kademlia is not available".into()))
1014 .await
1015 .ok();

Callers 1

handle_node_eventMethod · 0.80

Calls 15

external_addressesMethod · 0.80
into_iterMethod · 0.80
want_blockMethod · 0.80
destroy_sessionMethod · 0.80
connected_peersMethod · 0.80
mapMethod · 0.80
info_for_peerMethod · 0.80
is_connectedMethod · 0.80
addressesMethod · 0.80
popMethod · 0.80
emit_network_eventMethod · 0.80
sendMethod · 0.45

Tested by

no test coverage detected