Giter VIP home page Giter VIP logo

kdht's Introduction

kdht

kdht is an erlang DHT implementation. You can use this library to join a DHT network, and search torrent info-hash in the network.

Usage

  • Download this library source code

  • Compile it by erl in the library root directory:

      erl -make
    
  • Start erl and specify the module beam path:

      erl -pa ebin
    
  • Run test

      testdht:start().
    

Example

-module(testdht).
-include("vlog.hrl").
-export([start/0, stop/1, handle_event/2]).
-export([tell_more_nodes/1]).

start() ->
    vlog:start_link("kdht.txt", ?TRACE),
    random:seed(now()),
    kdht_sup:start_link("dhtstate.dat", 6882, ?MODULE, dht_id:random()).

stop(Pid) ->
    kdht_sup:stop(Pid).

handle_event(announce_peer, {InfoHash, _IP, _BTPort}) ->
    MagHash = dht_id:tohex(InfoHash),
    {ok, FP} = file:open("magnet-link.txt", [append]),
    io:format(FP, "~s~n", [MagHash]),
    file:close(FP);

handle_event(startup, {MyID}) ->
    spawn_link(?MODULE, tell_more_nodes, [MyID]).

tell_more_nodes(MyID) ->
    [search:get_peers(MyID, dht_id:random()) || _ <- lists:seq(1, 10)],
    ?I("tell more nodes done").

TODO

  • token implementation

kdht's People

Contributors

kevinlynx avatar

Watchers

 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.