Documentation
¶
Index ¶
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func DefaultConfig()
- func Equal(a, b UUID) bool
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func Greater(a, b UUID) bool
- func Less(a, b UUID) bool
- func NewError(err string) error
- func Warn(v ...interface{})
- func Warnf(format string, v ...interface{})
- type Application
- type Chord
- func (c *Chord) CloseDB(dbName string)
- func (c *Chord) Count() int
- func (c *Chord) DBDel(dbName string, key []byte) error
- func (c *Chord) DBGet(dbName string, key []byte) ([]byte, error)
- func (c *Chord) DBSet(dbName string, key, value []byte) error
- func (c *Chord) Decode(dataBuf *bytes.Buffer, v interface{}) error
- func (c *Chord) Del(key []byte) error
- func (c *Chord) DropDB(dbName string)
- func (c *Chord) Encode(dataBuf *bytes.Buffer, v interface{}) error
- func (c *Chord) FindPredecessor(key UUID) (*Node, error)
- func (c *Chord) FindSuccessor(key UUID) (*Node, error)
- func (c *Chord) FixFingers()
- func (c *Chord) Get(key []byte) ([]byte, error)
- func (c *Chord) InstallApp(cfg *icfg.Config, app Application) error
- func (c *Chord) Join(nodes ...*Node) error
- func (c *Chord) Leave(nodes ...*Node) error
- func (c *Chord) List() ([]*Node, error)
- func (c *Chord) Listen(ln net.Listener) error
- func (c *Chord) Maintain()
- func (c *Chord) Node() Node
- func (c *Chord) Notify(n *Node) (*Message, error)
- func (c *Chord) Ping(node *Node) bool
- func (c *Chord) RegisterDB(dbName string, db KvDb)
- func (c *Chord) Route(key UUID) (*Node, error)
- func (c *Chord) SendMsg(msg *Message) (*Message, error)
- func (c *Chord) SendTo(node *Node, data []byte) error
- func (c *Chord) Set(key, value []byte) error
- func (c *Chord) SetDefaultDB(db KvDb)
- func (c *Chord) ShowFingers() []Finger
- func (c *Chord) Stabilize() error
- func (c *Chord) Sync()
- func (c *Chord) UninstallApp(id UUID) error
- type ChordAPI
- type Coder
- type ConnPool
- func (cp *ConnPool) AddConn(id UUID, conn net.Conn) bool
- func (cp *ConnPool) Close() (err error)
- func (cp *ConnPool) DelConn(id UUID)
- func (cp *ConnPool) ReadFrom(id UUID) (data []byte, err error)
- func (cp *ConnPool) SRMsg(id UUID, req *Message) (resp *Message, err error)
- func (cp *ConnPool) SendTo(id UUID, data []byte) (n int, err error)
- type Decoder
- type Encoder
- type Finger
- type FingerTable
- type GobCoder
- type JsonCoder
- type KvDb
- type LogApp
- func (la *LogApp) ID() UUID
- func (la *LogApp) OnDeliver(msg *Message)
- func (la *LogApp) OnError(err error)
- func (la *LogApp) OnForward(msg *Message, node *Node) bool
- func (la *LogApp) OnHeartbeat(node *Node)
- func (la *LogApp) OnNodeExit(node *Node)
- func (la *LogApp) OnNodeJoin(node *Node)
- func (la *LogApp) ShutDown() error
- func (la *LogApp) Startup(cfg *icfg.Config) error
- type MemKvDb
- type Message
- func (msg *Message) Body() []byte
- func (msg *Message) DecodeBody(coder Coder, v interface{}) error
- func (msg *Message) Hops() int
- func (msg *Message) Key() UUID
- func (msg *Message) Purpose() Purpose
- func (msg *Message) Sender() Node
- func (msg *Message) String() string
- func (msg *Message) Target() *Node
- type Node
- type Purpose
- type UUID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultConfig ¶
func DefaultConfig()
Types ¶
type Application ¶
type Application interface {
ID() UUID
Startup(args *icfg.Config) error
ShutDown() error
// When a error occurs in the functionality of the DHT
OnError(err error)
// Receive a message intended for the self node
OnDeliver(msg *Message)
// Received a message that needs to be routed onwards
OnForward(msg *Message, node *Node) bool // return False if chord should not forward
// A new node has joined the network
OnNodeJoin(node *Node)
// A node has left the network
OnNodeExit(node *Node)
// Received a heartbeat signal from a peer
OnHeartbeat(node *Node)
}
type Chord ¶
type Chord struct {
// contains filtered or unexported fields
}
func (*Chord) FixFingers ¶
func (c *Chord) FixFingers()
func (*Chord) Get ¶
Set,Get,Del操作首先令k=hash(key), 生成maxCopies个hash, (k+i*maxHash/maxCopies) mod maxHash, 找出负责节点,去重,并存入 hashCircleCache里,过期时间从配置中读取
func (*Chord) InstallApp ¶
func (c *Chord) InstallApp(cfg *icfg.Config, app Application) error
func (*Chord) RegisterDB ¶
func (*Chord) SetDefaultDB ¶
func (*Chord) ShowFingers ¶
func (*Chord) UninstallApp ¶
type ChordAPI ¶
type ChordAPI interface {
//Encode and decode the message
Encode(dataBuf *bytes.Buffer, v interface{}) error
Decode(dataBuf *bytes.Buffer, v interface{}) error
//Operate the default db, default is map
Set(key, value []byte) error
Get(key []byte) ([]byte, error)
Del(key []byte) error
//Set to a specify db
DBSet(dbName string, key, value []byte) error
// Get from a specify db
DBGet(dbName string, key []byte) ([]byte, error)
//Del from a specify db
DBDel(dbName string, key []byte) error
// set default db to replace the default map
SetDefaultDB(db KvDb)
//add new kv db
RegisterDB(dbName string, db KvDb)
//close a db and remove from list
CloseDB(dbName string)
//close a db and remove it, it's dangerous
DropDB(dbName string)
//Install an app to handle messages
InstallApp(cfg *icfg.Config, app Application) error
//Uninstall an app
UninstallApp(id UUID) error
Node() Node
//Ping is used to detect a node is connectable or not
Ping(node *Node) bool
//SendTo a node with []byte format data
SendTo(node *Node, data []byte) error
//SendMsg a message and find receiver from the message
SendMsg(msg *Message) (*Message, error)
//Listen will hold on a listener and accept connections then handle it.
Listen(l net.Listener) error
// maintain will periodically perform maintenance operations
Maintain()
//Sync is used to check local data replications number periodically and if not then send that data to other nodes
Sync()
//Count statistics how many nodes in the network
Count() int
//Join will use self uuid to ask specify nodes or build-in public node to initialize node
Join(node ...*Node) error
//Leave tells the specify node or the public nodes I will offline, update network states and re-sync data
Leave(node ...*Node) error
//Route find the node that stored this key or should store this key
Route(key UUID) (*Node, error)
//FindSuccessor returns the first successor for the given key
FindSuccessor(key UUID) (*Node, error)
//FindPredecessor returns the first predecessor for the given key
FindPredecessor(key UUID) (*Node, error)
//List returns an array contains all stored nodes' info
List() ([]*Node, error)
//Stabilize successor/predecessor pointers
Stabilize() error
//Notify a Node of our existence
Notify(n *Node) (*Message, error)
//FixFingers table
FixFingers()
//ShowFingers table
ShowFingers() []Finger
}
type Coder ¶
A coder for coding ghord messages
func NewGobCoder ¶
func NewGobCoder() Coder
func NewJsonCoder ¶
func NewJsonCoder() Coder
type ConnPool ¶
type ConnPool struct {
// contains filtered or unexported fields
}
type Decoder ¶
type Decoder interface {
// Decode into the given interface, or error
Decode(v interface{}) error
}
Standard decoder interface, usually created from an io.Reader Important: Needs to be stateless, in that each call to Decode() must act the same as any other call
type Encoder ¶
type Encoder interface {
// Encode given interface, or error
Encode(v interface{}) error
}
Standard encoder interface, usually created from an io.Writer Important: Needs to be stateless, in that each call to Encode() must act the same as any other call
type FingerTable ¶
func (*FingerTable) ShowTable ¶
func (ft *FingerTable) ShowTable() []Finger
type LogApp ¶
type LogApp struct {
// contains filtered or unexported fields
}
func (*LogApp) OnHeartbeat ¶
func (*LogApp) OnNodeExit ¶
func (*LogApp) OnNodeJoin ¶
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Represents a message in the DHT network
func NewMessage ¶
Create a new message
func (*Message) DecodeBody ¶
Extract the message body into the given value (must be a pointer), using the provided coder
type Node ¶
func (*Node) IsResponsible ¶
Returns true if this node is responsible for the given UUID
type Purpose ¶
type Purpose int
const ( NodeJoin Purpose // A node is joining the network NodeLeave // A node is leaving the network HeartBeat // Heartbeat signal NodeNotify // Notified of node existence NodeAnn // A node has been announced SucReq // A request for a nodes successor PreReq // A request for a nodes predecessor StatusError // Response indicating an error StatusOk // Simple status OK response )
Message types