Go implementation of Chord Protocol https://en.wikipedia.org/wiki/Chord_(peer-to-peer), can be used to build DHT
An Go implementation of Chord P2P Protocol
Get the package
$ go get github.com/wang502/chord
Import the package
import "github.com/wang502/chord"
Add a config.json
file in your source folder
{
"Host": ,
"HashBits": ,
"NumNodes": ,
}
2^(HashBits) = NumNodes
Initialize config
HashBits=3 NumNodes=8
by 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:
By knowing the host name of another server that is participating in the Chord ring, this server can join the Chor ring as well
This example joins a Chord ring consisting a http://localhost:4000
host.
err := chordServer.Join("http://localhost:4000")
if err != nil {
// handle error
}
succReq := NewFindSuccessorRequest(id, host)
succResp, err := chord.FindSuccessor(succReq)