Giter Club home page Giter Club logo

dht's Introduction

DHT

分别使用 Chord 算法和 Kademlia 算法实现了分布式哈希表(DHT)。在此基础上制作了类似于 BitTorrent 的 P2P 文件分享系统 BiteTorrent。

Report

一些优化

myrpc 实现了支持 gracefully shutdown 的 RPC server 和支持 TCP 连接复用的 RPC client。

throttler 实现了可以限制并发数的 WaitGroup。

Chord

节点通过保存它的前驱与后继形成了一个环,finger table 存了倍增的列表来加速环上的定位。后继和前驱保证了正确性,finger table 降低了时间复杂度。

Force Quit 的处理:每个节点备份前驱的数据,同时维护一定长度的后继列表,使得后继列表中只有部分节点失效时环不会断裂。每个点检测到前驱失效时启用备份数据。

Kademlia

定义节点间的距离为 Node ID 的异或。每个节点使用 k-buckets 存放它的联系人,k-buckets 中也使用倍增的**存放了不同距离的联系人,以减少寻找节点的时间。

每个数据会在节点周围被保存多份,当节点失效时可以启用备份数据。这通过数据的 RepublishTime 和 ExpireTime 来控制。

BiteTorrent

参考了 Building a BitTorrent client from the ground up in Go

将文件切成小 Piece,把每个 PieceHash, Piece 作为键值对放入 DHT。种子存的是文件对应的 PieceHash 的列表,因此可以用种子来下载文件。种子本身也被放入 DHT,其 key 为种子的哈希。磁力链接保存的是种子的哈希,因此可以用一个比较简短的磁力链接获取到种子,进而下载文件。

dht's People

Contributors

1024th avatar

Watchers

 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.