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

Implement constructor, initial bootstrap, and tests, for PropagationNetwork. #41

Merged
merged 21 commits into from
Aug 24, 2022

Conversation

f2koi
Copy link
Contributor

@f2koi f2koi commented Aug 12, 2022

Type of this PR

  • New feature (non-breaking change which adds functionality)
  • Change in tests

Describe your changes

Interface implementations

Among the following interfaces, async fn new(the constructor) and async fn create_recv_queue are implemented. The rest will be available after broadcasting logic is implemented.

#[async_trait]
pub trait AuthorizedNetwork {
    /// Joins the network with an authorized identity.
    async fn new([OMITTED]) -> Result<Self, String> where Self: Sized;
    /// Broadcasts a message to the network, after signed by the key given to this instance.
    async fn broadcast(&self, message: &[u8]) -> Result<BroadcastToken, String>;
    /// Stops a currently broadcasting message.
    async fn stop_broadcast(&self, token: BroadcastToken) -> Result<(), String>;
    /// Gets the current status of a broadcasting message.
    async fn get_broadcast_status(&self, token: BroadcastToken) -> Result<BroadcastStatus, String>;
    /// Creates a receiver for every message broadcasted to the network, except the one sent by this instance.
    async fn create_recv_queue(&self) -> Result<broadcast::Receiver<Vec<u8>>, ()>;
    /// Provides the estimated list of live nodes that are eligible and identified by their public keys.
    async fn get_live_list(&self) -> Result<Vec<PublicKey>, ()>;
}

Other implemented features

  • Provide configurations for some parameters used to construct and maintain the network.
  • Implement initial bootstrap, which is run once and while the PropagationNetwork is being constructed.
  • Create background task that listens on network events (such as incoming connection requests) and handles them to provide public interfaces.
  • Message passing between PropagationNetwork and the background task.

Unit tests

The following unit tests for initial bootstrap are added.

/// Test if every node fills its routing table with the addresses of all the other nodes
/// in a tiny network when they join the network sequentially.
/// (network_size = 5 < [`libp2p::kad::K_VALUE`] = 20)
async fn discovery_with_tiny_network_sequential();

/// Test if every node fills its routing table with the addresses of all the other nodes
/// in a small network when they join the network sequentially.
/// (network_size = [`libp2p::kad::K_VALUE`] = 20)
async fn discovery_with_small_network_sequential();

/// Test if every node fills its routing table with the addresses of all the other nodes
/// in a tiny network when they join the network at the same time.
/// (network_size = 5 < [`libp2p::kad::K_VALUE`] = 20)
async fn discovery_with_tiny_network_concurrent();

/// Test if every node fills its routing table with the addresses of all the other nodes
/// in a small network when they join the network at the same time.
/// (network_size = [`libp2p::kad::K_VALUE`] = 20)
async fn discovery_with_small_network_concurrent();

Remaining works

The followings are ordered by priority but can be changed.

  • Provide error types for this module(simperby-network)
  • Add tests for broadcasting
  • Implement public interfaces related to broadcasting

@posgnu
Copy link

posgnu commented Aug 13, 2022

@f2koi f2koi removed the request for review from posgnu August 14, 2022 01:13
@f2koi f2koi force-pushed the main branch 4 times, most recently from cfd4844 to 0a8a624 Compare August 19, 2022 13:36
Copy link
Member

@junha1 junha1 left a comment

Choose a reason for hiding this comment

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

  1. Please use does ~ instead of do ~ for doc-comments.
  2. What is K_VALUE?

network/src/propagation_network/mod.rs Show resolved Hide resolved
}

impl PropagationNetwork {
#[allow(dead_code)]
Copy link
Member

Choose a reason for hiding this comment

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

If this will be only for the tests ever, then just move it in mod tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved it

@f2koi
Copy link
Contributor Author

f2koi commented Aug 23, 2022

Automatically rebased on the latest commit of main.

@f2koi
Copy link
Contributor Author

f2koi commented Aug 23, 2022

  1. Please use does ~ instead of do ~ for doc-comments.
  2. What is K_VALUE?
  1. Fixed.
  2. It is the maximum number of connections(except for one-time connections) or the maximum number of nodes in contact. I replaced it in the comment with descriptive text.


[dev-dependencies]
rand = "0.8.5"
Copy link
Member

Choose a reason for hiding this comment

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

Add newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

floodsub: Floodsub::new(local_peer_id),
}
}
// Todo: Add constructor taking a configuration as an argument.
Copy link
Member

Choose a reason for hiding this comment

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

TODO

Copy link
Contributor Author

@f2koi f2koi Aug 24, 2022

Choose a reason for hiding this comment

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

Just removed the comment because it is already achieved (config.rs).

/// Returns a default.
///
/// To customize configurations, call `default` and chain the functions with the name of `with_<fieldname>`.
pub fn default() -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

Why not trait Default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved it into impl Default block.

if let Ok(keypair_inner) = ed25519::Keypair::decode(&mut keypair_bytes) {
Ok(Keypair::Ed25519(keypair_inner))
} else {
Err("Invalid public/private keypair was given.".to_string())
Copy link
Member

Choose a reason for hiding this comment

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

Using a non-capitalized sentence is the (loose) convention for error msgs. Please apply it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied it to all err messages and panic messages.

pub(crate) peer_discovery_interval: Duration,
/// Capacity for the message queue that passes messages from other nodes
/// to its simperby node.
pub(crate) message_queue_capacity: usize,
Copy link
Member

Choose a reason for hiding this comment

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

It is common to refer struct fields with The in the doc comments.
(e.g., The addresses to ..)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied it to all structs.

@junha1 junha1 merged commit 5cac70a into postech-dao:main Aug 24, 2022
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.

3 participants