Igor Egorov
de0259c3d3
|
5 years ago | |
---|---|---|
.. | ||
CMakeLists.txt | 5 years ago | |
README.md | 5 years ago | |
go.mod | 5 years ago | |
libp2p_client.go | 5 years ago | |
libp2p_echo_client.cpp | 5 years ago | |
libp2p_echo_server.cpp | 5 years ago |
README.md
Example Libp2p Echo
General description
This example shows you how to create a simple Echo client and server in cpp-libp2p. There are three ways to launch this example: C++ to C++, C++ Client to Go Server and C++ Server to Go Client. The last two examples can be used to test a compatibility between the implementations and should be moved to some separate repository to produce automatic tests.
C++ Server and Client
Currently, libp2p_echo_server
can operate in two modes - via Plaintext or SECIO security protocols.
By default, it is launched in SECIO secured mode.
To run it with Plaintext exclusive mode just add -insecure
command-line argument.
libp2p_echo_server -insecure
The client application does not have such an option and supports both types of connection at any time. Which security type is going to be used is defined by the server's working mode and its preferences.
Golang Implementation Compatibility Note
The libp2p_client.go
which is an echo server source from go-libp2p-examples
can be built only when go.mod
file is present.
The current version of the go.mod
is outdated, and only Plaintext security could be cross-tested.
To update the go.mod
file there are changes required in c++ implementation of libp2p.
Those changes are the subject of ongoin work.
C++ to C++
- Build C++ targets
libp2p_echo_server
andlibp2p_echo_client
- Start a C++ server. If you build using CMake and now are in this directory, executable can be launched as
../../cmake-build-debug/example/01-echo/libp2p_echo_server
. - Start a C++ client. If you build using CMake and now are in directory, executable can be launched as
../../cmake-build-debug/example/01-echo/libp2p_echo_client /ip4/127.0.0.1/tcp/40010/ipfs/12D3KooWLs7RC93EGXZzn9YdKyZYYx3f9UjTLYNX1reThpCkFb83
. - Watch how the message is exchanged between server and client
C++ Client to Go Server
- Build C++ target
libp2p_echo_client
- Build a Go example via
go build libp2p_client.go
- Execute
./libp2p_client -insecure -l 40010
. It will start a Go server - Go server outputs its address in form
I am /ip4/.../tcp/.../ipfs/...
. Please, take a note of this address - Start C++ client. If you build using CMake and now are in directory, executable can be launched as
../../cmake-build-debug/example/01-echo/libp2p_echo_client $ADDRESS_OF_GO_SERVER$
. - Watch how message is exchanged
C++ Server and Go Client
- Build C++ target
libp2p_echo_server
- Build a Go example via
go build libp2p_client.go
- Execute
../../cmake-build-debug/example/01-echo/libp2p_echo_server -insecure
. It will start a C++ server. - Execute
./libp2p_client -insecure -l 40011 -d /ip4/127.0.0.1/tcp/40010/ipfs/12D3KooWLs7RC93EGXZzn9YdKyZYYx3f9UjTLYNX1reThpCkFb83
- Watch how message is exchanged