GithubHelp home page GithubHelp logo

p-brz / kademlia-sample Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 102 KB

Simple sample to experiment kademlia (https://github.com/DavidKeller/kademlia) library features.

License: The Unlicense

Python 32.43% C++ 67.57%

kademlia-sample's Introduction

Kademlia Sample

This a simple sample to experiment kademlia library features.

The sample uses also the conan dependency manager and the Clara command line parser library.

The code is licensed under the unlicense terms. So in resume can use it for wherever you want.

Building

  1. First you need to install (detailed instructions at conan docs)

     pip install conan
    
  2. Install the packages dependencies

     conan install
    
  3. Then build

     ./waf configure build
    

or

    conan build        

Usage

After building, a binary should be created at build/node.

  1. You can run it with the --help option to see the available options

     ./build/node --help    
    
  2. You need to run a first node that will bootstrap the dht:

     ./build/node
    

optionally specify a local port to bind:

    ./build/node --port 12345
  1. Then, you can run one or more nodes, bootstraping with one of the previous nodes:

Note: if you run then on same machine, remember to use different ports. Note 2: if you not set the port of bootstrap node it will use the default value

    ./build/node "someip" -p 10001
    ./build/node "otherip:10001" -p 10002
    ./build/node "otherip:10002"
    ...
  1. For each one node (except the first one), you can use the get and put commands:

     ... during execution
     put "some key" "my value"
     get "some key"
    

kademlia-sample's People

Stargazers

 avatar

Watchers

 avatar  avatar

kademlia-sample's Issues

I hava a question about DavidKeller's lib.

Hello!
I saw your project by accident.I used his lib just like u did.But ,I have some questions about his lib.When I use his lib to search or save peer,it doesn't run async_save() function or async_load() function.

My code

save function

QFile file("D:/qt_code/222.txt");
    if(!file.open(QFile::ReadOnly)){
        qDebug()<<"open file error!";
        return;
    }
    QByteArray block;
    block = file.readAll();
    file.close();

    std::string data = block.data();
    auto on_save = [=](std::error_code const& failure){
        qDebug()<<block.data();
        if(failure)
            qDebug()<<QString::fromStdString(failure.message());
    };
    std::string key("key");
    s->async_save(asBinary(key),asBinary(data),on_save);

save function

std::string key("key");
    auto on_load = [=](std::error_code const& failure
            ,kademlia::session::data_type const& data)
    {
        FILE *fp;
        fp = fopen("55.txt","rb+");
        fprintf(fp,"%s",data.data());
        fclose(fp);
        if(failure)
            qDebug()<<QString::fromStdString(failure.message());
        else
            std::copy(data.begin(),data.end()
                      ,std::ostream_iterator<std::uint32_t>{std::cout," "});
    };

    s->async_load(asBinary(key),on_load);

My questions

The lambda functions on_load and on_save couldn't run.I don't know how to print the debug logs.Can u teach me?
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.