Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace channel with callback of transport in swarm #561

Merged
merged 29 commits into from
Mar 28, 2024

Conversation

Ma233
Copy link
Member

@Ma233 Ma233 commented Mar 1, 2024

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes/features)
  • Docs have been added / updated (for bug fixes / features)

🔵 What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

🟤 What is the current behavior? (You can also link to an open issue here)

🟢 What is the new behavior (if this is a feature change)?

☢️ Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)

ℹ️ Other information

Closes #issue

@Ma233 Ma233 force-pushed the channel branch 5 times, most recently from ad7ec31 to 243601f Compare March 10, 2024 14:25
@Ma233 Ma233 force-pushed the channel branch 2 times, most recently from 77aa542 to d3958f7 Compare March 25, 2024 03:28
@Ma233 Ma233 changed the title [WIP] refactor: replace channel with callback of transport in swarm refactor: replace channel with callback of transport in swarm Mar 25, 2024
@RyanKung
Copy link
Member

RyanKung commented Mar 25, 2024

plz avoid exposing swarm components such as:

➜  core git:(ma_channel) ✗ pcregrep -rM 'swarm.transport(\n)?.*' src
src/swarm/builder.rs:    /// Sets up the external address for swarm transport.
src/dht/stabilization.rs:        let conns = self.swarm.transport.get_connections();
src/dht/stabilization.rs:                    self.swarm.transport.session_sk(),
src/dht/stabilization.rs:                self.swarm.transport.send_payload(payload).await?;
src/dht/stabilization.rs:                        self.swarm.transport.session_sk(),
src/dht/stabilization.rs:                    self.swarm.transport.send_payload(payload).await?;
src/tests/default/test_connection.rs:    assert!(node1.swarm.transport.get_connection(node2.did()).is_none());
src/tests/default/test_connection.rs:    assert!(node2.swarm.transport.get_connection(node1.did()).is_none());
src/tests/default/mod.rs:            self.swarm.transport.get_connection_ids(),
src/tests/default/mod.rs:            self.swarm.transport.get_connections().len(),
src/tests/default/mod.rs:            assert!(self.swarm.transport.get_connection(addr).is_some());
src/tests/default/test_message_handler.rs:    let connection_1_to_2 = node1.swarm.transport.get_connection(node2.did()).unwrap();
src/tests/default/test_message_handler.rs:    let connection_2_to_3 = node2.swarm.transport.get_connection(node3.did()).unwrap();
src/tests/default/test_message_handler.rs:    let connection_1_to_3 = node1.swarm.transport.get_connection(node3.did());
src/tests/default/test_message_handler.rs:    let connection_1_to_2 = node1.swarm.transport.get_connection(node2.did()).unwrap();
src/tests/default/test_message_handler.rs:    let connection_1_to_2 = node1.swarm.transport.get_connection(node2.did()).unwrap();
src/tests/default/test_message_handler.rs:    let connection_1_to_2 = node1.swarm.transport.get_connection(node2.did()).unwrap();
src/tests/default/test_message_handler.rs:    let connection_1_to_2 = node1.swarm.transport.get_connection(node2.did()).unwrap();
src/message/handlers/connection.rs:        assert!(node1.swarm.transport.get_connection(node3.did()).is_none());
src/message/handlers/connection.rs:        assert!(node1.swarm.transport.get_connection(node3.did()).is_none());
src/message/handlers/connection.rs:            if let Some(t) = node2.swarm.transport.get_connection(node1.did()) {
src/inspect.rs:            let connections = swarm.transport.get_connections();

just hide or wrap the transport, and call functions as

swam.get_connections
swarm.get_connection_ids


for (did, conn) in conns.into_iter() {
if conn.is_disconnected().await {
if matches!(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think match WebrtcConnectionState here is a good idea.

The keyword WebRTC and belonged details is not necessary to be known for swarm / DHT layer.

Just is_connected / is_pending / is_disconnected is fine here

@@ -88,11 +92,11 @@ impl Stabilization {
tracing::debug!("STABILIZATION notify_predecessor: {:?}", s);
let payload = MessagePayload::new_send(
msg.clone(),
self.swarm.session_sk(),
self.swarm.transport.session_sk(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between swarm.session_sk and swarm.transport.session_sk ?

s,
self.swarm.did(),
)?;
self.swarm.send_payload(payload).await?;
self.swarm.transport.send_payload(payload).await?;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont expose transport, just wrap it.


if payload.transaction.destination == self.did {
if payload.transaction.destination == self.transport.dht.did {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transport.dht.did?
swarm.did()?
swarm.dht.did?

message_handler: MessageHandler,
transport: BoxedTransport<ConnectionOwner, TransportError>,
/// Swarm tansport.
pub transport: Arc<SwarmTransport>,
Copy link
Member

@RyanKung RyanKung Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the SwarmTransport is actually TransportWithDHT

pub struct SwarmTransport {
    transport: Transport,
    session_sk: SessionSk,
    pub(crate) dht: Arc<PeerRing>,
    #[allow(dead_code)]
    measure: Option<MeasureImpl>,
}

Copy link
Member

@RyanKung RyanKung Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just rename SwarmTransport to ConnectionManager is better.

The word Transport Connection, and the way we call them are making confuse here.

Just a metaphor, Transport is a train, Connection is a railway. getting railwayS from a train via the railway station is making no sense.

@Ma233 Ma233 merged commit 3ffcdd2 into RingsNetwork:master Mar 28, 2024
5 checks passed
@Ma233 Ma233 deleted the channel branch March 28, 2024 03:54
RyanKung added a commit that referenced this pull request Mar 28, 2024
Key changes:

Feature: data channel pool: #562
Feature: Using callback instead MPMC channel: #561
Chore: Make rings-snark optional: #558
Chore: Using forked protocolJs: #556
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants