Documentation
¶
Overview ¶
Package proto contains DHT RPC protocol struct.
Index ¶
- Constants
- Variables
- type AccountAddress
- func (z *AccountAddress) DatabaseID() (d DatabaseID)
- func (z *AccountAddress) MarshalHash() (o []byte, err error)
- func (z AccountAddress) MarshalJSON() ([]byte, error)
- func (z AccountAddress) MarshalYAML() (interface{}, error)
- func (z *AccountAddress) Msgsize() (s int)
- func (z AccountAddress) String() string
- func (z *AccountAddress) UnmarshalJSON(data []byte) error
- func (z *AccountAddress) UnmarshalYAML(unmarshal func(interface{}) error) error
- type AddrAndGas
- type DatabaseID
- type Envelope
- func (e *Envelope) GetContext() context.Context
- func (e *Envelope) GetExpire() time.Duration
- func (e *Envelope) GetNodeID() *RawNodeID
- func (e *Envelope) GetTTL() time.Duration
- func (e *Envelope) GetVersion() string
- func (e *Envelope) SetContext(ctx context.Context)
- func (e *Envelope) SetExpire(exp time.Duration)
- func (e *Envelope) SetNodeID(nodeID *RawNodeID)
- func (e *Envelope) SetTTL(ttl time.Duration)
- func (e *Envelope) SetVersion(ver string)
- type EnvelopeAPI
- type FindNeighborReq
- type FindNeighborResp
- type FindNodeReq
- type FindNodeResp
- type Node
- type NodeID
- type NodeKey
- type Peers
- type PeersHeader
- type PingReq
- type PingResp
- type RawNodeID
- type ServerRole
- type ServerRoles
- type UploadMetricsReq
- type UploadMetricsResp
Constants ¶
const ( // NodeIDLen is the NodeID length. NodeIDLen = 2 * hash.HashSize )
Variables ¶
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 ¶
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) 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 ¶
GetContext returns context from envelop which is set in server Accept.
func (*Envelope) GetVersion ¶
GetVersion implements EnvelopeAPI.GetVersion.
func (*Envelope) SetContext ¶
SetContext set a ctx in envelope.
func (*Envelope) SetVersion ¶
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 ¶
FindNeighborResp is FindNeighbor RPC response.
type FindNodeReq ¶
FindNodeReq is FindNode RPC request.
type FindNodeResp ¶
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.
type NodeID ¶
type NodeID string
NodeID is the Hex of RawNodeID.
func (*NodeID) Difficulty ¶
Difficulty returns NodeID difficulty, returns -1 on length mismatch or any error.
func (*NodeID) MarshalBinary ¶
MarshalBinary does the serialization.
func (*NodeID) ToRawNodeID ¶
ToRawNodeID converts NodeID to RawNodeID.
func (*NodeID) UnmarshalBinary ¶
UnmarshalBinary does the deserialization.
type NodeKey ¶
type NodeKey RawNodeID
NodeKey is node key on consistent hash ring, generate from Hash(NodeID).
type Peers ¶
type Peers struct { PeersHeader verifier.DefaultHashSignVerifierImpl }
Peers defines the peers configuration.
func (*Peers) Sign ¶
func (p *Peers) Sign(signer *asymmetric.PrivateKey) (err error)
Sign generates signature.
type PeersHeader ¶
PeersHeader defines the header for miner peers.
type RawNodeID ¶
RawNodeID is node name, will be generated from Hash(nodePublicKey) RawNodeID length should be 32 bytes normally.
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 ¶
UploadMetricsReq is UploadMetrics RPC request.
type UploadMetricsResp ¶
UploadMetricsResp is UploadMetrics RPC response.