Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
chore: code-review fixes from PR #8
Browse files Browse the repository at this point in the history
  • Loading branch information
axb-topos committed Aug 10, 2022
1 parent 7814d62 commit faa2e07
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
7 changes: 5 additions & 2 deletions node/net/src/discovery_behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub(crate) struct DiscoveryBehavior {
routable_peers: HashSet<PeerId>,
}

const TCE_TRANSMISSION_PROTOCOL: &str = "/trbp-transmission/1";
const TCE_DISCOVERY_PROTOCOL: &str = "/tce-disco/1";

impl DiscoveryBehavior {
pub(crate) fn new(
local_key: Keypair,
Expand All @@ -46,13 +49,13 @@ impl DiscoveryBehavior {

// identify
let ident_config =
IdentifyConfig::new("/trbp-transmission/1".to_string(), local_key.public())
IdentifyConfig::new(TCE_TRANSMISSION_PROTOCOL.to_string(), local_key.public())
.with_push_listen_addr_updates(true);
let ident = Identify::new(ident_config);

// kademlia
let kad_config = KademliaConfig::default()
.set_protocol_name("/tce-disco/1".as_bytes())
.set_protocol_name(TCE_DISCOVERY_PROTOCOL.as_bytes())
.set_replication_interval(Some(Duration::from_secs(30)))
.set_publication_interval(Some(Duration::from_secs(30)))
.set_provider_publication_interval(Some(Duration::from_secs(30)))
Expand Down
15 changes: 0 additions & 15 deletions node/net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,6 @@ impl NetworkWorker {
// Listen on all interfaces and whatever port the OS assigns
swarm.listen_on(local_listen_addr).expect("Bind port");

// gossip launch
// for known_peer in config.known_peers.clone() {
// log::info!(
// "---- adding gossip peer:{} at {}",
// &known_peer.0,
// &known_peer.1
// );
//
// // we need to dial peer so that gossipsub would be aware of it
// match swarm.dial(known_peer.1.clone()) {
// Ok(_) => log::debug!("Dialed {:?}", &known_peer.1),
// Err(e) => log::debug!("Dial {:?} failed: {:?}", &known_peer.1, e),
// }
// }

// networking loop
loop {
tokio::select! {
Expand Down
8 changes: 4 additions & 4 deletions node/net/src/transmission_behavior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use tokio::{
#[derive(NetworkBehaviour)]
#[behaviour(event_process = true)]
pub(crate) struct TransmissionBehavior {
pub rr: RequestResponse<TransmissionCodec>,
pub req_resp_protocol: RequestResponse<TransmissionCodec>,
#[behaviour(ignore)]
pub tx_events: mpsc::UnboundedSender<NetworkEvents>,
#[behaviour(ignore)]
Expand All @@ -39,7 +39,7 @@ impl TransmissionBehavior {
/// Factory
pub(crate) fn new(events_sender: mpsc::UnboundedSender<NetworkEvents>) -> Self {
Self {
rr: RequestResponse::new(
req_resp_protocol: RequestResponse::new(
TransmissionCodec(),
iter::once((TransmissionProtocol(), ProtocolSupport::Full)),
Default::default(),
Expand All @@ -56,7 +56,7 @@ impl TransmissionBehavior {
for peer_id in to {
// publish
let req_id = self
.rr
.req_resp_protocol
.send_request(&peer_id, TransmissionRequest(data.clone()));
// remember each (req_id)
self.req_ids_to_ext_ids.insert(req_id);
Expand All @@ -78,7 +78,7 @@ impl TransmissionBehavior {
data: req_payload.0,
})?;
// send the response back, error handled in other event handling branches
self.rr
self.req_resp_protocol
.send_response(resp_chan, TransmissionResponse(vec![]))?;
Ok(())
}
Expand Down

0 comments on commit faa2e07

Please sign in to comment.