Skip to content

A rust client working on Swarm, Gossipsub and Identify to communicate, verify and exchange messages with other peers in a p2p network.

License

Notifications You must be signed in to change notification settings

vbhattaccmu/p2p-verify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

P2P Verify

A network interaction client working on Swarm, Gossipsub and Identify to communicate, verify and exchange messages with each other in a p2p network.

Usage

With binary

  1. You can build the binary with the following command
cargo build --release
  1. Open two shells with binary placed in two shells.

2 a. In one shell start the first binary with

./client connect --port 7025 --listener 6000

2 b. In the other shell start the second binary with

./client connect --port 7012 --listener 6001

Here port refers to the HTTP server port and the listener refers to the swarm listener for the client. A fresh peer id for each peer is generated everytime the binary is started.

  1. Trigger the message transfer API with the first client with the HTTP API with the following:-
curl --location 'http://localhost:7025/p2p/peers/dial' \
--header 'Content-Type: application/json' \
--data '{
    "multiaddress": "/ip4/127.0.0.1/tcp/6001",
    "message": "data in flow 12"
}'

The response on the shell will look something like:-

{
    "dial_success": {
        "verifier_peer_id": "12D3KooWRcDNahGcnzu3tF4KWKYV9zsPuMEBZfwSzbGMPiWoSHTn",
        "sender_peer_id": "12D3KooWMs37vi7eNFVsG7KkimxZXGLihF7NEMThbUs2fdoE3hD4"
    },
    "verification_result": true,
    "signature": "549b7063a70e0233a193427b94ffe9c7e9f836fe2f6fbbf44ad0f128b1b8452c710c89562cf31050de43850279066a49962ee6b595b9fd43ca3bd269d4e9320d",
    "public_key": "f8492014c7b6ad9c448b1a7e7354ca65262b195403d5550f6ec1b1d862ba50bb",
    "message": "data in flow 12"
}

Here verifier_peer_id is the peer id of the verifier in the network. sender_peer_id is the peer id of the sender in the network. signature is the signature used to verify the message sent to the verifier. public_key is the public key of the peer sending the message message is the message sent

  1. Similarly with the other client
curl --location 'http://localhost:7012/p2p/peers/dial' \
--header 'Content-Type: application/json' \
--data '{
    "multiaddress": "/ip4/127.0.0.1/tcp/6000",
    "signature": ""
    "message": "data in flow 12"
}'

The response on the shell will look something like:-

{
    "dial_success": {
        "verifier_peer_id": "12D3KooWMs37vi7eNFVsG7KkimxZXGLihF7NEMThbUs2fdoE3hD4",
        "sender_peer_id": "12D3KooWRcDNahGcnzu3tF4KWKYV9zsPuMEBZfwSzbGMPiWoSHTn"
    },
    "verification_result": true,
    "signature": "19ae6695bd9d273b1e6d9a2ad1621e13342f84628db3adeb3763ad97bf7731fe7d03af81f8fa2c03f33be05eacc94dc21eebef97ca708a79f5a5c8d5b17f5e09",
    "public_key": "dc7df9ddf31487b2d337694d272036478dc461edaac0018d64b501cf993c06f5",
    "message": "data in flow 12"
}

Notice how the sender and the verifier swapped their positions! In case you are restarting the binaries, it would be better to kill previous client related processes.

pkill -9 client

About

A rust client working on Swarm, Gossipsub and Identify to communicate, verify and exchange messages with other peers in a p2p network.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages