proto

package
v0.0.0-...-020e20f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package proto contains DHT RPC protocol struct.

Index

Constants

View Source
const (
	// NodeIDLen is the NodeID length.
	NodeIDLen = 2 * hash.HashSize
)

Variables

View Source
var (
	// NewNodeIDDifficulty is exposed for easy testing.
	NewNodeIDDifficulty = 40
	// NewNodeIDDifficultyTimeout is exposed for easy testing.
	NewNodeIDDifficultyTimeout = 60 * time.Second
)

Functions

This section is empty.

Types

type AccountAddress

type AccountAddress hash.Hash

AccountAddress is wallet address, will be generated from Hash(nodePublicKey).

func (*AccountAddress) DatabaseID

func (z *AccountAddress) DatabaseID() (d DatabaseID)

DatabaseID converts AccountAddress to DatabaseID.

func (*AccountAddress) MarshalHash

func (z *AccountAddress) MarshalHash() (o []byte, err error)

MarshalHash marshals for hash.

func (AccountAddress) MarshalJSON

func (z AccountAddress) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (AccountAddress) MarshalYAML

func (z AccountAddress) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (*AccountAddress) Msgsize

func (z *AccountAddress) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message.

func (AccountAddress) String

func (z AccountAddress) String() string

String is a string variable.

func (*AccountAddress) UnmarshalJSON

func (z *AccountAddress) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*AccountAddress) UnmarshalYAML

func (z *AccountAddress) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type AddrAndGas

type AddrAndGas struct {
	AccountAddress AccountAddress
	RawNodeID      RawNodeID
	GasAmount      uint64
}

AddrAndGas records each node's address, node id and gas that node receives.

type DatabaseID

type DatabaseID string

DatabaseID is database name, will be generated from UUID.

func FromAccountAndNonce

func FromAccountAndNonce(accountAddress AccountAddress, nonce uint32) DatabaseID

FromAccountAndNonce generates databaseID from Account and its nonce.

func (*DatabaseID) AccountAddress

func (d *DatabaseID) AccountAddress() (a AccountAddress, err error)

AccountAddress converts DatabaseID to AccountAddress.

type Envelope

type Envelope struct {
	Version string        `json:"v"`
	TTL     time.Duration `json:"t"`
	Expire  time.Duration `json:"e"`
	NodeID  *RawNodeID    `json:"id"`
	// contains filtered or unexported fields
}

Envelope is the protocol header.

func (*Envelope) GetContext

func (e *Envelope) GetContext() context.Context

GetContext returns context from envelop which is set in server Accept.

func (*Envelope) GetExpire

func (e *Envelope) GetExpire() time.Duration

GetExpire implements EnvelopeAPI.GetExpire.

func (*Envelope) GetNodeID

func (e *Envelope) GetNodeID() *RawNodeID

GetNodeID implements EnvelopeAPI.GetNodeID.

func (*Envelope) GetTTL

func (e *Envelope) GetTTL() time.Duration

GetTTL implements EnvelopeAPI.GetTTL.

func (*Envelope) GetVersion

func (e *Envelope) GetVersion() string

GetVersion implements EnvelopeAPI.GetVersion.

func (*Envelope) SetContext

func (e *Envelope) SetContext(ctx context.Context)

SetContext set a ctx in envelope.

func (*Envelope) SetExpire

func (e *Envelope) SetExpire(exp time.Duration)

SetExpire implements EnvelopeAPI.SetExpire.

func (*Envelope) SetNodeID

func (e *Envelope) SetNodeID(nodeID *RawNodeID)

SetNodeID implements EnvelopeAPI.SetNodeID.

func (*Envelope) SetTTL

func (e *Envelope) SetTTL(ttl time.Duration)

SetTTL implements EnvelopeAPI.SetTTL.

func (*Envelope) SetVersion

func (e *Envelope) SetVersion(ver string)

SetVersion implements EnvelopeAPI.SetVersion.

type EnvelopeAPI

type EnvelopeAPI interface {
	GetVersion() string
	GetTTL() time.Duration
	GetExpire() time.Duration
	GetNodeID() *RawNodeID
	GetContext() context.Context

	SetVersion(string)
	SetTTL(time.Duration)
	SetExpire(time.Duration)
	SetNodeID(*RawNodeID)
	SetContext(context.Context)
}

EnvelopeAPI defines envelope access functions for rpc Request/Response.

type FindNeighborReq

type FindNeighborReq struct {
	ID    NodeID
	Roles []ServerRole
	Count int
	Envelope
}

FindNeighborReq is FindNeighbor RPC request.

type FindNeighborResp

type FindNeighborResp struct {
	Nodes []Node
	Msg   string
	Envelope
}

FindNeighborResp is FindNeighbor RPC response.

type FindNodeReq

type FindNodeReq struct {
	ID NodeID
	Envelope
}

FindNodeReq is FindNode RPC request.

type FindNodeResp

type FindNodeResp struct {
	Node *Node
	Msg  string
	Envelope
}

FindNodeResp is FindNode RPC response.

type Node

type Node struct {
	ID         NodeID                `yaml:"ID"`
	Role       ServerRole            `yaml:"Role"`
	Addr       string                `yaml:"Addr"`
	DirectAddr string                `yaml:"DirectAddr,omitempty"`
	PublicKey  *asymmetric.PublicKey `yaml:"PublicKey"`
	Nonce      mine.Uint256          `yaml:"Nonce"`
}

Node is all node info struct.

func NewNode

func NewNode() *Node

NewNode just return a new node struct.

func (*Node) InitNodeCryptoInfo

func (node *Node) InitNodeCryptoInfo(timeThreshold time.Duration) (err error)

InitNodeCryptoInfo generate Node asymmetric key pair and generate Node.NonceInfo. Node.ID = Node.NonceInfo.Hash.

type NodeID

type NodeID string

NodeID is the Hex of RawNodeID.

func (*NodeID) Difficulty

func (id *NodeID) Difficulty() (difficulty int)

Difficulty returns NodeID difficulty, returns -1 on length mismatch or any error.

func (*NodeID) IsEmpty

func (id *NodeID) IsEmpty() bool

IsEmpty test if a nodeID is empty.

func (*NodeID) IsEqual

func (id *NodeID) IsEqual(target *NodeID) bool

IsEqual returns if two node id is equal.

func (*NodeID) MarshalBinary

func (id *NodeID) MarshalBinary() (keyBytes []byte, err error)

MarshalBinary does the serialization.

func (*NodeID) ToRawNodeID

func (id *NodeID) ToRawNodeID() *RawNodeID

ToRawNodeID converts NodeID to RawNodeID.

func (*NodeID) UnmarshalBinary

func (id *NodeID) UnmarshalBinary(keyBytes []byte) (err error)

UnmarshalBinary does the deserialization.

type NodeKey

type NodeKey RawNodeID

NodeKey is node key on consistent hash ring, generate from Hash(NodeID).

func (*NodeKey) Less

func (k *NodeKey) Less(y *NodeKey) bool

Less return true if k is less than y.

type Peers

Peers defines the peers configuration.

func (*Peers) Clone

func (p *Peers) Clone() (copy Peers)

Clone makes a deep copy of Peers.

func (*Peers) Find

func (p *Peers) Find(key NodeID) (index int32, found bool)

Find finds the index of the server with the specified key in the server list.

func (*Peers) Sign

func (p *Peers) Sign(signer *asymmetric.PrivateKey) (err error)

Sign generates signature.

func (*Peers) Verify

func (p *Peers) Verify() (err error)

Verify verify signature.

type PeersHeader

type PeersHeader struct {
	Version uint64
	Term    uint64
	Leader  NodeID
	Servers []NodeID
}

PeersHeader defines the header for miner peers.

type PingReq

type PingReq struct {
	Node Node
	Envelope
}

PingReq is Ping RPC request.

type PingResp

type PingResp struct {
	Msg string
	Envelope
}

PingResp is Ping RPC response, i.e. Pong.

type RawNodeID

type RawNodeID struct {
	hash.Hash
}

RawNodeID is node name, will be generated from Hash(nodePublicKey) RawNodeID length should be 32 bytes normally.

func (*RawNodeID) ToNodeID

func (id *RawNodeID) ToNodeID() NodeID

ToNodeID converts RawNodeID to NodeID.

type ServerRole

type ServerRole int

ServerRole defines the role of node to be leader/coordinator in peer set.

const (
	// Unknown is the zero value
	Unknown ServerRole = iota
	// Leader is a server that have the ability to organize committing requests.
	Leader
	// Follower is a server that follow the leader log commits.
	Follower
	// Miner is a server that run sql database.
	Miner
	// Client is a client that send sql query to database>
	Client
)

func (ServerRole) MarshalYAML

func (s ServerRole) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (ServerRole) String

func (s ServerRole) String() string

String is a string variable of ServerRole.

func (*ServerRole) UnmarshalYAML

func (s *ServerRole) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type ServerRoles

type ServerRoles []ServerRole

ServerRoles is []ServerRole.

func (*ServerRoles) Contains

func (ss *ServerRoles) Contains(role ServerRole) bool

Contains returns if given role is in the ServerRoles>.

type UploadMetricsReq

type UploadMetricsReq struct {
	// MetricFamily Bytes array
	MFBytes [][]byte
	Envelope
}

UploadMetricsReq is UploadMetrics RPC request.

type UploadMetricsResp

type UploadMetricsResp struct {
	Msg string
	Envelope
}

UploadMetricsResp is UploadMetrics RPC response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL