Skip to content

Latest commit

 

History

History
245 lines (133 loc) · 4.94 KB

README.md

File metadata and controls

245 lines (133 loc) · 4.94 KB

Mothra: LibP2P for Dummies

⚠️ This is a work in progress! ⚠️

Mothra was created to house bindings between Rust-LibP2P and any number of other languages. The languages that are supported (so far) are:

  • C
  • Java
  • .Net
  • Rust (duh)

The Thing That Should Not Be

mothra

Mothra providea a simple (slightly opinionated) API that requires no previous knowledge of libP2P. The API consists of:

  • Basic network configuration settings
    • ip addresses
    • ports
    • logging
    • etc
  • GossipSub
  • RPC
  • Discv5

MacOS Prereqs

Rust:

Install rustup so you can switch between Rust versions:

> brew install rustup

Install the Rust compiler and package manager:

> rustup-init

DotNet:

Install dotnet sdk here

Once the dotnet sdk is installed open a new Terminal and type:

> dotnet
Usage: dotnet [options]
Usage: dotnet [path-to-application]

Options:
  -h|--help         Display help.
  --info            Display .NET Core information.
  --list-sdks       Display the installed SDKs.
  --list-runtimes   Display the installed runtimes.

path-to-application:
  The path to an application .dll file to execute.

Note: if you receive an error message make sure you are working from a new Terminal session

tmux (optional):

Installing this will make running the demo easier:

> brew install tmux

On Windows:

Follow the instructions to install rust-up on Windows.

You will need Visual Studio installed; the linker is used by Rust, and the compiler for the C-bindings and example, and dotnet core for the dotnet example.

You will also need vcpkg installed in a sibling folder of Mothra. Clone it from 'https://github.com/microsoft/vcpkg' and then run the bootstrap to configure.

Then use it to install the OpenSSL libraries:

vcpkg install openssl:x64-windows

Build Mothra

Building is easy. First, clone the repo:

> git clone https://github.com/prrkl/mothra.git

Build for Rust

Next cd into the project's root dir

Debug:

> make rust

Release:

> make rls=1 rust

Build for C

Next cd into the project's root dir and build:

> make c

Build for Java

Next cd into the project's root dir and build:

> make java

Build for DotNet

Next cd into the project's root dir and build:

> make dotnet

Debuggig the Makefile

Use the debug-{VAR_NAME} option to inspect the value of variables set in config.mk.

For example, to inspect the value of the OS_LFLAGS var:

> make debug-OS_LFLAGS
OS_LFLAGS=-mmacosx-version-min=10.15.4 -framework CoreFoundation -framework Security

Build on Windows

Run the build scripts a in Visual Studio x64 Native Tools Command Prompt.

A set of batch files, conveniently called Make.cmd, are provided for running on Windows.

> Make.cmd

This will make the C example and dotnet example. (It's not a make file, so no separate targets, just a batch file.)

There is no tmux, but there is a PeerDemo.cmd batch file in the dotnet example which will launch and run two dotnet sessions.

You can also grab the ENR and run a demo between C and dotnet.

Sample App

Here is a screenshot of the sample app in action:

demo

Run Sample App (Rust)

The sample app demonstrates two clients using Disv5 to find each other and the use of GossipSub to send messages back and forth.

If you have tmux installed, it is a little simpler to run:

> cd examples/rust && sh peerDemo.sh

Run Sample App (C)

The sample app demonstrates two clients using Disv5 to find each other and the use of GossipSub to send messages back and forth.

If you have tmux installed, it is a little simpler to run:

> cd examples/c && sh peerDemo.sh

Run Sample App (Java)

The sample app demonstrates two clients using Disv5 to find each other and the use of GossipSub to send messages back and forth.

If you have tmux installed, it is a little simpler to run:

> cd examples/java && sh peerDemo.sh

Run Sample App (DotNet)

The sample app demonstrates two clients using Disv5 to find each other and the use of GossipSub to send messages back and forth.

If you have tmux installed, it is a little simpler to run:

> cd examples/dotnet && sh peerDemo.sh

Credits/Acknowledgements

  • A big thanks to the Lighthouse crew. Not only does Mothra shamelessly borrow from their project, but I literally learned Rust by looking at their code.

  • Since Mothra is essentially a wrapper around Rust-LibP2P, they deserve a fist bump too.≠≠≠