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

Merge latest dev and doc updates to main #31

Merged
merged 125 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
64d8087
add docs stuff
sacha-l May 10, 2024
b497428
docs: add doc folder structure
sacha-l May 10, 2024
bb270fb
docs: minor fixes
sacha-l May 10, 2024
c5204f5
chore: complete gossipsub impl
thewoodfish May 10, 2024
6128ab5
docs: update README
sacha-l May 10, 2024
5c651b5
docs: update networkbuilder
sacha-l May 10, 2024
8c8d120
docs
sacha-l May 10, 2024
a5899c3
fix: cleanup generics from ConfigBuilder::with_rpc()
thewoodfish May 10, 2024
c1f7572
docs: update nodesetup
sacha-l May 10, 2024
78e6afb
docs: add nodesetup
sacha-l May 10, 2024
e6d8d61
docs: update network builder docs
sacha-l May 10, 2024
fbea143
docs: add fullstops at the end of each doc line
sacha-l May 10, 2024
43e4ef0
doc fixes
sacha-l May 10, 2024
0e582cf
add: demonstrations on library capbilities
thewoodfish May 10, 2024
4125f2c
fix: move core tests to own folder
sacha-l May 10, 2024
c9fc99a
add: tests for echo
sacha-l May 10, 2024
25bbc90
add: tests for dialing peer
sacha-l May 10, 2024
ebf0872
tests for dialing node works
sacha-l May 11, 2024
e9a0406
add: test for kad request
sacha-l May 11, 2024
4703dff
add: test for kad lookup record
sacha-l May 11, 2024
2a490f8
add: get providers tests draft
sacha-l May 11, 2024
686b8e6
add: Appended a new variant: KademliaNoProbidersFound to the AppRespo…
thewoodfish May 11, 2024
16ed3ec
add: Handled the other variants of the GetProvidersOk Kad event
thewoodfish May 11, 2024
887dfdd
add: important debugging comments
thewoodfish May 11, 2024
f4abb3e
add: test provider error works
sacha-l May 11, 2024
f625fb3
add more tests stuff
sacha-l May 11, 2024
259746a
add: more tests for gossipsub
thewoodfish May 12, 2024
c2219c6
add test for blacklist node
sacha-l May 13, 2024
b4c4a5b
fix tests
sacha-l May 13, 2024
3f858c3
chore: finish kademlia integration test
thewoodfish May 13, 2024
e85c83e
chore: complete gossipsub impl
thewoodfish May 10, 2024
b375554
add: demonstrations on library capbilities
thewoodfish May 10, 2024
afc6199
fix: move core tests to own folder
sacha-l May 10, 2024
cda3713
add: tests for echo
sacha-l May 10, 2024
636ef6d
add: tests for dialing peer
sacha-l May 10, 2024
eb63705
tests for dialing node works
sacha-l May 11, 2024
9556da1
add: test for kad request
sacha-l May 11, 2024
7768cf6
add: test for kad lookup record
sacha-l May 11, 2024
60c76b0
add: get providers tests draft
sacha-l May 11, 2024
ce89cc7
add: Appended a new variant: KademliaNoProbidersFound to the AppRespo…
thewoodfish May 11, 2024
b590217
add: Handled the other variants of the GetProvidersOk Kad event
thewoodfish May 11, 2024
457765d
add: important debugging comments
thewoodfish May 11, 2024
894e13a
add: test provider error works
sacha-l May 11, 2024
9084736
add more tests stuff
sacha-l May 11, 2024
6999ddf
add: more tests for gossipsub
thewoodfish May 12, 2024
4ace930
add test for blacklist node
sacha-l May 13, 2024
4bf16af
fix tests
sacha-l May 13, 2024
a68c5ca
chore: finish kademlia integration test
thewoodfish May 13, 2024
d2f1f4d
add docs stuff
sacha-l May 10, 2024
a4ba5f2
docs: minor fixes
sacha-l May 10, 2024
876f7a2
docs: update networkbuilder
sacha-l May 10, 2024
33091ec
docs: add fullstops at the end of each doc line
sacha-l May 10, 2024
4441ff7
fixes from merge 🤦‍♂️
sacha-l May 13, 2024
f4f9e8e
Merge branch 'dev' into docs
sacha-l May 13, 2024
e922e4a
add: addition of the routing_table_updated event handler
thewoodfish May 14, 2024
1ab5e75
Merge branch 'dev' into docs
thewoodfish May 14, 2024
c681cbb
Merge pull request #30 from algorealmInc/docs
thewoodfish May 14, 2024
4bcd35a
fix: completion of the kademlia integration test
thewoodfish May 15, 2024
05953a5
add: gossipsub integration test
thewoodfish May 15, 2024
2646c52
fix: cleanup of unused values
thewoodfish May 15, 2024
fb24f4e
fix: changed time u64 to the Seconds type
thewoodfish May 15, 2024
6b8a522
fix: update ReadMe
thewoodfish May 15, 2024
43089dd
fix: update ReadMe
thewoodfish May 15, 2024
8c03d4e
fix: Update README.md
thewoodfish May 15, 2024
15382f6
fix: Update README.md
thewoodfish May 15, 2024
c3fe530
fix: update ReadMe
thewoodfish May 15, 2024
a172e81
fix: Update README.md
thewoodfish May 15, 2024
a15368a
fix: Update README.md
thewoodfish May 15, 2024
451ec20
fix: Update README.md
thewoodfish May 15, 2024
db76161
fix: Update README.md
thewoodfish May 15, 2024
83658a5
Update README.md
thewoodfish May 15, 2024
057f8c7
Update README.md
thewoodfish May 15, 2024
5abd86e
fix: update ReadMe
thewoodfish May 15, 2024
bcc0bef
fix: update ReadMe
thewoodfish May 15, 2024
dfd0d06
fix: update ReadMe
thewoodfish May 15, 2024
58c4e76
fix: update ReadMe
thewoodfish May 15, 2024
5443bbe
fix: update ReadMe
thewoodfish May 15, 2024
2284a5b
fix: update ReadMe
thewoodfish May 15, 2024
daf9019
fix: update ReadMe
thewoodfish May 15, 2024
ce097c9
fix: update ReadMe
thewoodfish May 15, 2024
eb7c5f1
fix: update ReadMe
thewoodfish May 15, 2024
b175f0c
fix: update ReadMe
thewoodfish May 15, 2024
7d84438
fix: update ReadMe
thewoodfish May 15, 2024
f38b6e1
fix: update ReadMe
thewoodfish May 15, 2024
507ef8d
fix: update ReadMe
thewoodfish May 15, 2024
1a5c7a2
fix: update ReadMe
thewoodfish May 15, 2024
f153497
fix: update ReadMe
thewoodfish May 15, 2024
c4395f4
fix: update ReadMe
thewoodfish May 15, 2024
d5e1e97
fix: update ReadMe
thewoodfish May 15, 2024
763fa04
fix: update ReadMe
thewoodfish May 15, 2024
6ccee6d
fix: update ReadMe
thewoodfish May 15, 2024
d8b6f18
fix: update ReadMe
thewoodfish May 15, 2024
651c86c
fix: update ReadMe
thewoodfish May 15, 2024
443eec2
fix: update ReadMe
thewoodfish May 15, 2024
ebf195b
fix: update ReadMe
thewoodfish May 15, 2024
39a5204
fix: update ReadMe
thewoodfish May 15, 2024
a2ff558
fix: update ReadMe
thewoodfish May 15, 2024
ea7f07a
fix: update ReadMe
thewoodfish May 15, 2024
e9dd7d5
fix: update ReadMe
thewoodfish May 15, 2024
93c53cb
add: update ReadMe
thewoodfish May 15, 2024
424b55f
add: update ReadMe
thewoodfish May 15, 2024
48938d7
add: update and cleanup of docs
thewoodfish May 15, 2024
40938de
fix: ran cargo fmt on entire codebase
thewoodfish May 15, 2024
d550acb
fix: todos
sacha-l May 15, 2024
de3d6e7
chore: revamp workspace structure for guides
sacha-l May 15, 2024
a410738
fix: move testing guide to main library crate
sacha-l May 15, 2024
1932689
add: tutorial directory
sacha-l May 15, 2024
de4be84
docs: clarify docs in bootstrap config template
sacha-l May 15, 2024
67bc850
fix: update testing guide
sacha-l May 15, 2024
e33c346
fix: remove unecessary doc comments
sacha-l May 15, 2024
64e88f4
add: setup of the binary crates of the tutorial examples
thewoodfish May 16, 2024
aa3b618
add: setup of the binary crates of the tutorial examples
thewoodfish May 16, 2024
f53a1c2
add: update ReadMe
thewoodfish May 16, 2024
cd255ad
add: update ReadMe
thewoodfish May 16, 2024
850e028
fix: revert the workspace issues
sacha-l May 16, 2024
d0fcb15
add: echo-server turorial
thewoodfish May 16, 2024
d847195
fix: tests for file reading
sacha-l May 16, 2024
d42bd4e
fix: remove tokio from default
sacha-l May 16, 2024
d36592b
fix ports for tests
sacha-l May 16, 2024
8400fe1
add: docs to echo example
sacha-l May 16, 2024
611d111
docs: prettify all things
sacha-l May 16, 2024
0c3f119
fix: testing nodes mistake
sacha-l May 16, 2024
0d04ac4
docs: minor fixes
sacha-l May 16, 2024
39dd568
update README
sacha-l May 16, 2024
18da305
add: impl file_sharing_app tutorial example
thewoodfish May 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"rust-analyzer.linkedProjects": [
"./client/Cargo.toml"
"./client/Cargo.toml",
"./swarm_nl/Cargo.toml"
]
}
202 changes: 201 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,202 @@
<!-- <img src="https://github.com/algorealmInc/SwarmNL/blob/c3fe530350ec37755c64b47cba06361d39b3b095/SwarmNL.png" alt="SwarmNL" style="border-radius: 15px !important;"> -->

# SwarmNL
SwarmNL is a configurable p2p networking layer for transporting arbitrary data between nodes in a network.
**A library to build custom networking layers for decentralized applications**

SwarmNL is a library designed for P2P networking in distributed systems. It's lightweight, scalable, and easy to configure, making it perfect for decentralized applications. Powered by [libp2p](https://docs.libp2p.io/), SwarmNL simplifies networking so developers can focus on building.

## Why SwarmNL?
SwarmNL makes buiding a peer-to-peer decentralized and distributed networking stack for your application a breeze. With SwarmNL, you can effortlessly configure nodes, tailor network conditions, and fine-tune behaviors specific to your project's needs, allowing you to dive into networking without any hassle.

Say goodbye to the complexities of networking and hello to simplicity. With SwarmNL, all the hard work is done for you, leaving you to focus on simple configurations and your application logic.

## Tutorials

Have a look at some tutorials that demonstrate the use of SwarmNl in various contexts:

- [Echo server]()
- [File sharing app]()
- [Simple game]()

## Documentation

Visit the deployed Rust docs [here](https://algorealminc.github.io/SwarmNL/swarm_nl/index.html).

## Features

- **Node Configuration**: SwarmNL provides a simple interface to configure a node and specify parameters to dictate its behaviour. This includes:

- Selection and configuration of the transport layers to be supported by the node
- Selection of cryptographic keypairs (ed25519, RSA, secp256k1, ecdsa)
- Storage and retrieval of keypair locally
- PeerID and multiaddress generation
- Protocol specification and handlers
- Event handlers for network events and logging

#### Example

```rust
//! Using the default node setup configuration and the default network event handler

// Default config
let config = BootstrapConfig::default();
// Default network handler
let handler = DefaultHandler;
// Build node or network core
let node = CoreBuilder::with_config(config, handler)
.build()
.await
.unwrap();


//! Using a custom node setup configuration and a custom network event handler

// Custom configuration
// a. Using config from an `.ini` file
let config = BootstrapConfig::from_file("bootstrap_config.ini");

// b. Using config methods
let mut bootnode = HashMap::new(); // Bootnodes
let ports = (1509, 2710); // TCP, UDP ports

bootnode.insert(
PeerId::random(),
"/ip4/x.x.x.x/tcp/1509".to_string()
);

let config = BootstrapConfig::new()
.with_bootnodes(bootnode)
.with_tcp(ports.0)
.with_udp(ports.1);

// Custom event handler
use swarm_nl::core::EventHandler;

#[derive(Clone)]
struct ApplicationState{
name: String,
version: i8,
}

// Define custom behaviour to respond to network events
impl EventHandler for AppState {
fn new_listen_addr(
&mut self,
local_peer_id: PeerId,
listener_id: ListenerId,
addr: Multiaddr,
) {
// Announce interfaces we're listening on
println!("Peer id: {}", local_peer_id);
println!("We're listening on the {}", addr);
}

// Echo data recieved from a RPC
fn rpc_handle_incoming_message(&mut self, data: Vec<Vec<u8>>) -> Vec<Vec<u8>> {
println!("Recvd incoming RPC: {:?}", data);
data
}

// Handle the incoming gossip message
fn gossipsub_handle_incoming_message(&mut self, source: PeerId, data: Vec<String>) {
println!("Recvd incoming gossip: {:?}", data);
}
}

// Define custom event handler
let state = ApplicationState {
name: String::from("SwarmNL"),
version: 0.1
}

// Build node or network core
let node = CoreBuilder::with_config(config, state)
.build()
.await
.unwrap();

```
Please look at a template `.ini` file [here](https://github.com/algorealmInc/SwarmNL/blob/dev/swarm_nl/bootstrap_config.ini) for configuring a node in the network.<br><br>

- **Node Communication**: For communication, SwarmNL leverages the powerful capabilities of libp2p. These includes:

- The Kadmlia DHT: Developers can use the DHT to store infomation and leverage the capabilities of the DHT to build powerful applications, easily.
- A simple RPC mechanism to exchange data quickly between peers.
- Gossiping: SwarmNL uses the Gossipsub 1.1 protocol, specified by the [libp2p spec](https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md).

#### Example

```rust
//! Communicate with remote nodes using the simple and familiar async-await paradigm.

// Build node or network core
let node = CoreBuilder::with_config(config, state)
.build()
.await
.unwrap();

// Communication interfaces
// a. Kademlia DHT e.g

// Prepare an kademlia `store_record` request to send to the network layer
let (key, value, expiration_time, explicit_peers) = (
KADEMLIA_TEST_KEY.as_bytes().to_vec(),
KADEMLIA_TEST_VALUE.as_bytes().to_vec(),
None,
None,
);

let kad_request = AppData::KademliaStoreRecord {
key: key.clone(),
value,
expiration_time,
explicit_peers,
};

// Send request
if let Ok(result) = node.query_network(kad_request).await {
assert_eq!(KademliaStoreRecordSuccess,result);
}

// b. RPC (request-response) e.g

// Prepare a RPC fetch request
let fetch_key = vec!["SomeFetchKey".as_bytes().to_vec()];

let fetch_request = AppData::FetchData {
keys: fetch_key.clone(),
peer: node4_peer_id,
};

// Get a stream id to track the request
let stream_id = node.send_to_network(fetch_request).await.unwrap();

// Poll for the result
if let Ok(result) = node.recv_from_network(stream_id).await {
// Here, the request data was simply echoed by the remote peer
assert_eq!(AppResponse::FetchData(fetch_key), result);
}

// c. Gossiping e.g

// Prepare gossip request
let gossip_request = AppData::GossipsubBroadcastMessage {
topic: GOSSIP_NETWORK.to_string(),
message: vec!["Daniel".to_string(), "Deborah".to_string()],
};

if let Ok(result) = node.query_network(gossip_request).await {
assert_eq!(AppResponse::GossipsubBroadcastSuccess, result);
}

```

- _In Development 👷_:
- _Node failure handling involving reconnection strategies, failover mechanisms etc_.
- _Scaling involving techniques like sharding, data forwarding etc_.
- _IPFS upload and download interfaces_.

In essence, SwarmNL is designed to simplify networking so you can focus on building that world-changing application of yours! Cheers! 🥂

With ❤️ from [Deji](https://github.com/thewoodfish) and [Sacha](https://github.com/sacha-l).

Binary file added SwarmNl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 0 additions & 19 deletions bootstrap_config.ini

This file was deleted.

Binary file added client/.DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ rust-ini = "0.20.0"
swarm_nl = { path = "../swarm_nl", features = ["tokio-runtime"] }
tokio = { version = "1.37.0", features = ["full"] }
base58 = "0.2.0"

[features]
second-node = []
test-reading-node = []
test-writing-node = []
9 changes: 2 additions & 7 deletions client/bootstrap_config.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
; Copyright (c) 2024 Algorealm
; A typical template showing the necessary config to bootstrap a node

[ports]
; TCP/IP port to listen on
tcp=49200
; UDP port to listen on
udp=49201

[bootstrap]
; The boostrap nodes to connect to immediately after start up
boot_nodes=[12D3KooWMD3kvZ7hSngeu1p7HAoCCYusSXqPPYDPvzxsa9T4vz3a:/ip4/127.0.0.1/tcp/49152]
boot_nodes=[12D3KooWMNKx84syHXFLRz7Ejfj9UgyvdtTeFMwUyfjwcykMKofq:/ip4/127.0.0.1/tcp/49152]

Loading
Loading