GithubHelp home page GithubHelp logo

yihuang / kademlia Goto Github PK

View Code? Open in Web Editor NEW

This project forked from serokell/kademlia

0.0 3.0 0.0 357 KB

A haskell library implementing the Kademlia DHT

License: BSD 3-Clause "New" or "Revised" License

Haskell 94.01% Shell 5.23% Nix 0.76%

kademlia's Introduction

kademlia

kademlia is a haskell libraray implementing the Kademlia distributed hash table.

It aims to be flexible and handle all the low-level work, in order to allow for easy integration of the DHT-technology into applications.

The library is built after the original Kademlia Paper.

For more information, take a look at the libraries hackage page.

Implementation note (to understand some parts of code)

Flow to find nodes by key:

lookupNode => runLookup go inst nid : create chan replyChan, launch go

go:

  1. send signal
  2. expect registration (reg, replyChan, timeoutTid) for this (signal, nodeId)
  3. wait for reply on reg, continue if needed (we handle nodes we know now and check whether we want to query more neighbors)

To wait for reply on (reg, replyChan, timeoutTid) we listen to replyChan

How incoming requests are dispatched, workers:

  1. Network.Kademlia.Networking.startRcvProcess:

      read `(signal, nodeId)` from UDP socket, combine it to reply `reply` (pure operation)
      write `reply` to `timeoutChan`
    
  2. Network.Kademlia.Instance.receivingProcess:

     read `reply` from `timeoutChan`
     (`notResponse` || `expectedReply`):
         check either:
           * there was a registration `reg` for our `reply`
           * `reply` is a request (not response)
         if call `receivingProcessDo` which calls `dispatch`
    

    Network.Kademlia.ReplyQueue.dispatch:

         * we check whether there is registration corresponding to `reply`
           + if there is registrartion `(reg, replyChan, timeoutTid)` then we
                 kill timeout thread by it's id `timeoutTid`
                 write `reply` to `replyChan` // futher it would be handled by thread which sent `signal` and was waiting for reply
           + if there is no registration // note, that this may happen only for requests
                 write `reply` to `defaultChan`
    
  3. Network.Kademlia.Instance.backgraoundProcess:

     read `reply` from `defaultChan` //note that only requests can get here
     `handleCommand` for `reply`
    

kademlia's People

Contributors

adinapoli-iohk avatar avieth avatar bergmark avatar chshersh avatar domenkozar avatar froozen avatar georgeee avatar gromakovsky avatar martoon-00 avatar pva701 avatar rockbmb avatar vincenthz avatar volhovm avatar yihuang avatar zakharvoit avatar

Watchers

 avatar  avatar  avatar

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.