Skip to content

Latest commit

History

188 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

P2P

Kademlia based p2p network.

Installation

P2P requires to compile:

$ git clone https://github.com/SychevS/p2p.git
$ cd p2p
$ git submodule update --init --recursive
$ mkdir build
$ cd build
$ cmake -DBOOST_ROOT=${BOOST_ROOT} -DCMAKE_INSTALL_PREFIX=${P2P_INSTALL_ROOT} ..
$ cmake --build . --target install

Basic usage

Lets suppose that we are going to connect only two nodes.

First node:

#include<p2p_network.h>usingnamespacenet;
NodeId GenerateRandomId();
NodeId GetFirstNodeId();
NodeId GetSecondNodeId();
voidStartMainEventLoop();
classHost : publicEventHandler {
voidOnNodeDiscovered(const NodeId&) {
std::cout << "Node discovered" << std::endl;
}
voidOnNodeRemoved(const NodeId&) {}
voidOnMessageReceived(const NodeId& from, ByteVector&& message) {}
voidOnFragmentFound(const FragmentId&, ByteVector&& value) {}
voidOnFragmentNotFound(const FragmentId& id) {}
FragmentId GetFragmentId(const ByteVector& fragment) {
returnGenerateRandomId();
}
};
intmain() {
net::ManagerConfig config {
GetFirstNodeId(),
6100,
{{GetSecondNodeId(), "127.0.0.1", 6101}},
false
};
Host host;
Manager netman(config, host);
netman.Start();
StartMainEventLoop();
}

Main of second node:

intmain() {
net::ManagerConfig config {
GetSecondNodeId(),
6101,
{{GetFirstNodeId(), "127.0.0.1", 6100}},
false
};
Host host;
Manager netman(config, host);
netman.Start();
StartMainEventLoop();
}

Now after discovery these two nodes will be able to communicate with each other using Manager's class interface. For more details see include/p2p_network.h

About

Kademlia based p2p network.

Topics

Resources

Stars

12 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages