Giter Club home page Giter Club logo

node-dht-peer-crawler's Introduction

node-dht-peer-crawler

Travis Build Status Coverage Status MIT licensed npm version Downloads

A fast and stable DHT crawler.

Installation

$ npm install dht-peer-crawler

Usage

import Crawler from 'dht-peer-crawler'

const crawler = new Crawler()

crawler.on('announce_peer', (infoHashStr, addressStr) => {
  console.log(`got a peer ${addressStr} on ${infoHashStr}`)
})

crawler.start().then(() => {
  console.log('start crawler success')
}, (error) => {
  console.error(`start crawler failed: ${error}`)
})

const signalTraps = ['SIGTERM', 'SIGINT', 'SIGUSR2']

signalTraps.map(type => {
  process.once(type, async () => {
    try {
      await crawler.stop()
      console.log('stop crawler success')
    } finally {
      process.kill(process.pid, type)
    }
  })
})

run with the command:

$ node --experimental-specifier-resolution=node app.js

Test

$ npm test

API

crawler = new Crawler(listenPort)

Create a new crawler instance.

crawler.announcePeers(infoHashStr, port)

announce the peer.

crawler.on('announce_peer', [infoHashStr, addressStr, impliedPort, torrent])

Emitted when received an announce_peer message.

crawler.on('new_info_hash', [infoHashStr])

Emitted when find a new info_hash.

node-dht-peer-crawler's People

Contributors

covertness avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

node-dht-peer-crawler's Issues

doesn't work with node 18

I get an error about a directory missing from node modules.

I created the directory, and still get an error:

➜  scrapers git:(master) ✗ 
$ node dht-crawler.js                               
node:internal/errors:466
    ErrorCaptureStackTrace(err);
    ^

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import '/home/ettinger/src/scrapers/node_modules/dht-peer-crawler/lib/network' is not supported resolving ES modules imported from /home/ettinger/src/scrapers/node_modules/dht-peer-crawler/lib/crawler.mjs
    at new NodeError (node:internal/errors:377:5)
    at finalizeResolution (node:internal/modules/esm/resolve:401:17)
    at moduleResolve (node:internal/modules/esm/resolve:966:10)
    at defaultResolve (node:internal/modules/esm/resolve:1174:11)
    at ESMLoader.resolve (node:internal/modules/esm/loader:605:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:318:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:80:40)
    at link (node:internal/modules/esm/module_job:78:36) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///home/ettinger/src/scrapers/node_modules/dht-peer-crawler/lib/network'
}

Node.js v18.3.0

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.