- Notifications
You must be signed in to change notification settings - Fork1
Go implementation of Chord Protocolhttps://en.wikipedia.org/wiki/Chord_(peer-to-peer), can be used to build DHT
wang502/chord
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
An Go implementation of Chord P2P Protocol
Get the package
$ go get github.com/wang502/chordImport the package
import"github.com/wang502/chord"
Add aconfig.json file in your source folder
{"Host": ,"HashBits": ,"NumNodes": ,}- Host: the host name of ip of the local server that wants to join the Chord ring
- HashBits: the number of bits in the hash bits to apply consistent hashing.
- NumNodes: the max number of nodes to participate in Chord ring.
2^(HashBits) = NumNodes
Initialize config
- Initialize default congiguration with
HashBits=3 NumNodes=8by passing only the host name
host="localhost:3000"config:=chord.DefaultConfig(host)
import ("github.com/gorilla/mux""github.com/wang502/chord")transporter:=chord.NewTransporter()chordServer:=chord.NewServer("chord1",config,transporter)transporter.Install(server,mux.NewRouter())
Chord servers can communicate with each other using an HTTP transporter. And after transporter installs chord server, following url paths are mapped to respective handlers:
- "/findSuccessor": path to handle incoming request to find successor of an given id
- "/getPredecessor": path to return the predecessor of this chord node
- "/getSuccessor": path to return the successor of this chord node
- "/getFingerTable": path to return the finger table of this chord node
- "/notify": path to handle the notify request
- "/join": path to handle a join request sent from a Chord server
- "/start": path to start this Chord server
- "/stop": path to stop this Chord server
By knowing the host name of another server that is participating in the Chord ring, this server can join the Chor ring as wellThis example joins a Chord ring consisting ahttp://localhost:4000 host.
err:=chordServer.Join("http://localhost:4000")iferr!=nil {// handle error}
succReq:=NewFindSuccessorRequest(id,host)succResp,err:=chord.FindSuccessor(succReq)
About
Go implementation of Chord Protocolhttps://en.wikipedia.org/wiki/Chord_(peer-to-peer), can be used to build DHT
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.