packets

package
v0.7.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2019 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeNodeJoinClaim = ClaimType(iota + 1)
	TypeNodeAnnounceClaim
	TypeCapabilityPollingAndActivation
	TypeNodeViolationBlame
	TypeNodeBroadcast
	TypeNodeLeaveClaim
	TypeChangeNetworkClaim
)
View Source
const (
	Phase1 = PacketType(iota + 1)
	Phase2
	Phase3
)
View Source
const (
	TypeNodeJoinSupplementaryVote = VoteType(iota + 1)
	TypeStateFraudNodeSupplementaryVote
	TypeNodeListSupplementaryVote
	TypeMissingNodeSupplementaryVote
	TypeMissingNode
)
View Source
const HashLength = 64
View Source
const HeaderSize = 2
View Source
const NodeListHashLength = 32
View Source
const PublicKeyLength = 64
View Source
const ReferenceLength = 64
View Source
const SignatureLength = 66

Variables

View Source
var (
	// ErrBitSetOutOfRange is returned when index passed to IndexToRef function is out of range (ERROR)
	ErrBitSetOutOfRange = errors.New("index out of range")
	// ErrBitSetNodeIsMissing is returned in IndexToRef when we have no information about the node on specified index (SPECIAL CASE)
	ErrBitSetNodeIsMissing = errors.New("no information about node on specified index")
	// ErrBitSetIncorrectNode is returned when an incorrect node is passed to RefToIndex (ERROR)
	ErrBitSetIncorrectNode = errors.New("incorrect node ID")
)

Possible errors in BitSetMapper

Functions

This section is empty.

Types

type BitSet

type BitSet interface {
	Serialize() ([]byte, error)
	// GetCells get buckets of bitset
	GetCells(mapper BitSetMapper) ([]BitSetCell, error)
	// ApplyChanges returns copy of the current bitset with changes applied
	ApplyChanges(changes []BitSetCell, mapper BitSetMapper) error
}

BitSet is interface

func DeserializeBitSet

func DeserializeBitSet(data io.Reader) (BitSet, error)

func NewBitSet

func NewBitSet(size int) (BitSet, error)

NewBitSet creates bitset from a set of buckets and the mapper. Size == cells count.

type BitSetCell

type BitSetCell struct {
	NodeID core.RecordRef
	State  TriState
}

BitSetCell is structure that contains the state of the node

type BitSetMapper

type BitSetMapper interface {
	// IndexToRef get ID of the node that is stored on the specified internal index
	IndexToRef(index int) (core.RecordRef, error)
	// RefToIndex get bitset internal index where the specified node state is stored
	RefToIndex(nodeID core.RecordRef) (int, error)
	// Length returns required length of the bitset
	Length() int
}

BitSetMapper contains the mapping from bitset index to node ID (and vice versa)

type CapabilityPoolingAndActivation

type CapabilityPoolingAndActivation struct {
	PollingFlags   uint16
	CapabilityType uint16
	CapabilityRef  [ReferenceLength]byte
}

CapabilityPoolingAndActivation is a type 3.

func (*CapabilityPoolingAndActivation) Deserialize

func (cpa *CapabilityPoolingAndActivation) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*CapabilityPoolingAndActivation) Serialize

func (cpa *CapabilityPoolingAndActivation) Serialize() ([]byte, error)

Serialize implements interface method

func (*CapabilityPoolingAndActivation) Type

type ChangeNetworkClaim

type ChangeNetworkClaim struct {
}

ChangeNetworkClaim uses to change network state.

func (*ChangeNetworkClaim) Type

func (cnc *ChangeNetworkClaim) Type() ClaimType

type ClaimType

type ClaimType uint8

type ConsensusPacket

type ConsensusPacket interface {
	HeaderSkipDeserializer
	Serializer
	PacketRoutable
}

func ExtractPacket

func ExtractPacket(reader io.Reader) (ConsensusPacket, error)

type HeaderSkipDeserializer

type HeaderSkipDeserializer interface {
	DeserializeWithoutHeader(data io.Reader, header *PacketHeader) error
}

type MissingNode

type MissingNode struct {
	NodeIndex uint16
}

func (*MissingNode) Deserialize

func (mn *MissingNode) Deserialize(data io.Reader) error

func (*MissingNode) Serialize

func (mn *MissingNode) Serialize() ([]byte, error)

func (*MissingNode) Type

func (mn *MissingNode) Type() VoteType

type MissingNodeSupplementaryVote

type MissingNodeSupplementaryVote struct {
	NodePulseProof NodePulseProof
}

func (*MissingNodeSupplementaryVote) Deserialize

func (v *MissingNodeSupplementaryVote) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*MissingNodeSupplementaryVote) Serialize

func (v *MissingNodeSupplementaryVote) Serialize() ([]byte, error)

Serialize implements interface method

func (*MissingNodeSupplementaryVote) Type

type NodeAnnounceClaim

type NodeAnnounceClaim struct {
	NodeJoinClaim

	NodeIndex uint16
	NodeCount uint16
}

NodeJoinClaim is a type 5, len == 272.

func (*NodeAnnounceClaim) Deserialize added in v0.7.5

func (nac *NodeAnnounceClaim) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*NodeAnnounceClaim) Serialize added in v0.7.5

func (nac *NodeAnnounceClaim) Serialize() ([]byte, error)

Serialize implements interface method

func (*NodeAnnounceClaim) Type

func (nac *NodeAnnounceClaim) Type() ClaimType

type NodeBroadcast

type NodeBroadcast struct {
	EmergencyLevel uint8
}

NodeBroadcast is a broadcast of info. Must be brief and only one entry per node. Type 4.

func (*NodeBroadcast) Deserialize

func (nb *NodeBroadcast) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*NodeBroadcast) Serialize

func (nb *NodeBroadcast) Serialize() ([]byte, error)

Serialize implements interface method

func (*NodeBroadcast) Type

func (nb *NodeBroadcast) Type() ClaimType

type NodeJoinClaim

type NodeJoinClaim struct {
	ShortNodeID             core.ShortNodeID
	RelayNodeID             core.ShortNodeID
	ProtocolVersionAndFlags uint32
	JoinsAfter              uint32
	NodeRoleRecID           uint32
	NodeRef                 core.RecordRef
	NodePK                  [PublicKeyLength]byte
	Signature               [SignatureLength]byte
}

NodeJoinClaim is a type 1, len == 272.

func (*NodeJoinClaim) Deserialize

func (njc *NodeJoinClaim) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*NodeJoinClaim) Serialize

func (njc *NodeJoinClaim) Serialize() ([]byte, error)

Serialize implements interface method

func (*NodeJoinClaim) SerializeWithoutSign added in v0.7.5

func (njc *NodeJoinClaim) SerializeWithoutSign() ([]byte, error)

func (*NodeJoinClaim) Type

func (njc *NodeJoinClaim) Type() ClaimType

type NodeJoinSupplementaryVote

type NodeJoinSupplementaryVote struct {
}

func (*NodeJoinSupplementaryVote) Deserialize

func (v *NodeJoinSupplementaryVote) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*NodeJoinSupplementaryVote) Serialize

func (v *NodeJoinSupplementaryVote) Serialize() ([]byte, error)

Serialize implements interface method

func (*NodeJoinSupplementaryVote) Type

type NodeLeaveClaim

type NodeLeaveClaim struct {
}

NodeLeaveClaim can be the only be issued by the node itself and must be the only claim record. Should be executed with the next pulse. Type 1, len == 0.

func (*NodeLeaveClaim) Deserialize

func (nlc *NodeLeaveClaim) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*NodeLeaveClaim) Serialize

func (nlc *NodeLeaveClaim) Serialize() ([]byte, error)

Serialize implements interface method

func (*NodeLeaveClaim) Type

func (nlc *NodeLeaveClaim) Type() ClaimType

type NodeListSupplementaryVote

type NodeListSupplementaryVote struct {
	NodeListCount uint16
	NodeListHash  [32]byte
}

func (*NodeListSupplementaryVote) Deserialize

func (v *NodeListSupplementaryVote) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*NodeListSupplementaryVote) Serialize

func (v *NodeListSupplementaryVote) Serialize() ([]byte, error)

Serialize implements interface method

func (*NodeListSupplementaryVote) Type

type NodePulseProof

type NodePulseProof struct {
	NodeStateHash [HashLength]byte
	NodeSignature [SignatureLength]byte
}

func (*NodePulseProof) Deserialize

func (npp *NodePulseProof) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*NodePulseProof) Serialize

func (npp *NodePulseProof) Serialize() ([]byte, error)

Serialize implements interface method

func (*NodePulseProof) Signature

func (npp *NodePulseProof) Signature() []byte

func (*NodePulseProof) StateHash

func (npp *NodePulseProof) StateHash() []byte

type NodeViolationBlame

type NodeViolationBlame struct {
	BlameNodeID   uint32
	TypeViolation uint8
}

NodeViolationBlame is a type 2.

func (*NodeViolationBlame) Deserialize

func (nvb *NodeViolationBlame) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*NodeViolationBlame) Serialize

func (nvb *NodeViolationBlame) Serialize() ([]byte, error)

Serialize implements interface method

func (*NodeViolationBlame) Type

func (nvb *NodeViolationBlame) Type() ClaimType

type PacketHeader

type PacketHeader struct {
	PacketT    PacketType
	HasRouting bool

	Pulse uint32
	//-----------------
	OriginNodeID core.ShortNodeID
	TargetNodeID core.ShortNodeID
	// contains filtered or unexported fields
}

func (*PacketHeader) Deserialize

func (ph *PacketHeader) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*PacketHeader) Serialize

func (ph *PacketHeader) Serialize() ([]byte, error)

Serialize implements interface method

type PacketRoutable

type PacketRoutable interface {
	// SetPacketHeader set routing information for transport level.
	SetPacketHeader(header *RoutingHeader) error
	// GetPacketHeader get routing information from transport level.
	GetPacketHeader() (*RoutingHeader, error)
}

type PacketType

type PacketType uint8

type Phase1Packet

type Phase1Packet struct {

	// --------------------
	// signature contains signature of Header + Section 1 + Section 2
	Signature [SignatureLength]byte
	// contains filtered or unexported fields
}

func NewPhase1Packet

func NewPhase1Packet() *Phase1Packet

func (*Phase1Packet) AddClaim

func (p1p *Phase1Packet) AddClaim(claim ReferendumClaim) bool

AddClaim adds claim if phase1Packet has space for it and returns true, otherwise returns false

func (*Phase1Packet) Deserialize

func (p1p *Phase1Packet) Deserialize(data io.Reader) error

func (*Phase1Packet) DeserializeWithoutHeader

func (p1p *Phase1Packet) DeserializeWithoutHeader(data io.Reader, header *PacketHeader) error

func (*Phase1Packet) GetClaims

func (p1p *Phase1Packet) GetClaims() []ReferendumClaim

func (*Phase1Packet) GetPacketHeader

func (p1p *Phase1Packet) GetPacketHeader() (*RoutingHeader, error)

func (*Phase1Packet) GetPulse

func (p1p *Phase1Packet) GetPulse() core.Pulse

func (*Phase1Packet) GetPulseNumber

func (p1p *Phase1Packet) GetPulseNumber() core.PulseNumber

func (*Phase1Packet) GetPulseProof

func (p1p *Phase1Packet) GetPulseProof() *NodePulseProof

func (*Phase1Packet) RawBytes

func (p1p *Phase1Packet) RawBytes() ([]byte, error)

func (*Phase1Packet) Serialize

func (p1p *Phase1Packet) Serialize() ([]byte, error)

func (*Phase1Packet) SetPacketHeader

func (p1p *Phase1Packet) SetPacketHeader(header *RoutingHeader) error

func (*Phase1Packet) SetPulseProof

func (p1p *Phase1Packet) SetPulseProof(proofStateHash, proofSignature []byte) error

SetPulseProof sets PulseProof and check struct fields len, returns error if invalid len

type Phase2Packet

type Phase2Packet struct {
	SignatureHeaderSection1 [SignatureLength]byte

	SignatureHeaderSection2 [SignatureLength]byte
	// contains filtered or unexported fields
}

func (*Phase2Packet) AddVote added in v0.7.5

func (p2p *Phase2Packet) AddVote(vote ReferendumVote)

func (*Phase2Packet) ContainsRequests added in v0.7.5

func (p2p *Phase2Packet) ContainsRequests() bool

func (*Phase2Packet) Deserialize

func (p2p *Phase2Packet) Deserialize(data io.Reader) error

func (*Phase2Packet) DeserializeWithoutHeader

func (p2p *Phase2Packet) DeserializeWithoutHeader(data io.Reader, header *PacketHeader) error

func (*Phase2Packet) GetBitSet

func (p2p *Phase2Packet) GetBitSet() BitSet

func (*Phase2Packet) GetGlobuleHashSignature

func (p2p *Phase2Packet) GetGlobuleHashSignature() []byte

func (*Phase2Packet) GetPacketHeader

func (p2p *Phase2Packet) GetPacketHeader() (*RoutingHeader, error)

func (*Phase2Packet) GetPulseNumber

func (p2p *Phase2Packet) GetPulseNumber() core.PulseNumber

func (*Phase2Packet) GetVotes added in v0.7.5

func (p2p *Phase2Packet) GetVotes() []ReferendumVote

func (*Phase2Packet) RawFirstPart

func (p2p *Phase2Packet) RawFirstPart() ([]byte, error)

func (*Phase2Packet) RawSecondPart

func (p2p *Phase2Packet) RawSecondPart() ([]byte, error)

func (*Phase2Packet) Serialize

func (p2p *Phase2Packet) Serialize() ([]byte, error)

func (*Phase2Packet) SetBitSet added in v0.7.5

func (p2p *Phase2Packet) SetBitSet(bitset BitSet)

func (*Phase2Packet) SetGlobuleHashSignature

func (p2p *Phase2Packet) SetGlobuleHashSignature(globuleHashSignature []byte) error

func (*Phase2Packet) SetPacketHeader

func (p2p *Phase2Packet) SetPacketHeader(header *RoutingHeader) error

type Phase3Packet

type Phase3Packet struct {
	SignatureHeaderSection1 [SignatureLength]byte
	// contains filtered or unexported fields
}

func NewPhase3Packet

func NewPhase3Packet(globuleHash [SignatureLength]byte, bitSet BitSet) Phase3Packet

func (*Phase3Packet) Deserialize

func (p3p *Phase3Packet) Deserialize(data io.Reader) error

func (*Phase3Packet) DeserializeWithoutHeader

func (p3p *Phase3Packet) DeserializeWithoutHeader(data io.Reader, header *PacketHeader) error

func (*Phase3Packet) GetBitset

func (p3p *Phase3Packet) GetBitset() BitSet

func (*Phase3Packet) GetPacketHeader

func (p3p *Phase3Packet) GetPacketHeader() (*RoutingHeader, error)

GetPacketHeader get routing information from transport level.

func (*Phase3Packet) RawBytes

func (p3p *Phase3Packet) RawBytes() ([]byte, error)

func (*Phase3Packet) Serialize

func (p3p *Phase3Packet) Serialize() ([]byte, error)

func (*Phase3Packet) SetPacketHeader

func (p3p *Phase3Packet) SetPacketHeader(header *RoutingHeader) error

SetPacketHeader set routing information for transport level.

type PulseData

type PulseData struct {
	PulseNumber uint32
	Data        PulseDataExt
}

PulseData is a pulse data.

func (*PulseData) Deserialize

func (pd *PulseData) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*PulseData) Serialize

func (pd *PulseData) Serialize() ([]byte, error)

Serialize implements interface method

type PulseDataExt

type PulseDataExt struct {
	NextPulseDelta uint16
	PrevPulseDelta uint16
	OriginID       [16]byte
	EpochPulseNo   uint32
	PulseTimestamp uint32
	Entropy        core.Entropy
}

PulseDataExt is a pulse data extension.

func (*PulseDataExt) Deserialize

func (pde *PulseDataExt) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*PulseDataExt) Serialize

func (pde *PulseDataExt) Serialize() ([]byte, error)

Serialize implements interface method

type ReferendumClaim

type ReferendumClaim interface {
	Serializer
	Type() ClaimType
}

type ReferendumVote

type ReferendumVote interface {
	Serializer
	Type() VoteType
}

type RoutingHeader

type RoutingHeader struct {
	OriginID   core.ShortNodeID
	TargetID   core.ShortNodeID
	PacketType types.PacketType
}

type Serializer

type Serializer interface {
	Serialize() ([]byte, error)
	Deserialize(data io.Reader) error
}

type StateFraudNodeSupplementaryVote

type StateFraudNodeSupplementaryVote struct {
	Node1PulseProof NodePulseProof
	Node2PulseProof NodePulseProof
	PulseData       PulseData // optional
}

func (*StateFraudNodeSupplementaryVote) Deserialize

func (v *StateFraudNodeSupplementaryVote) Deserialize(data io.Reader) error

Deserialize implements interface method

func (*StateFraudNodeSupplementaryVote) Serialize

func (v *StateFraudNodeSupplementaryVote) Serialize() ([]byte, error)

Serialize implements interface method

func (*StateFraudNodeSupplementaryVote) Type

type TriState

type TriState uint8

TriState is state of the communicating node

const (
	// Legit is bit indicating OK data from node
	Legit TriState = iota + 1
	// TimedOut is bit indicating that timeout occurred when communicating with node
	TimedOut
	// Fraud is bit indicating that the node is malicious (fraud)
	Fraud
)

type TriStateBitSet

type TriStateBitSet struct {
	CompressedSet bool
	// contains filtered or unexported fields
}

TriStateBitSet bitset implementation.

func NewTriStateBitSet

func NewTriStateBitSet(size int) (*TriStateBitSet, error)

NewTriStateBitSet creates and returns a tristatebitset.

func (*TriStateBitSet) ApplyChanges

func (dbs *TriStateBitSet) ApplyChanges(changes []BitSetCell, mapper BitSetMapper) error

func (*TriStateBitSet) GetCells

func (dbs *TriStateBitSet) GetCells(mapper BitSetMapper) ([]BitSetCell, error)

func (*TriStateBitSet) Serialize

func (dbs *TriStateBitSet) Serialize() ([]byte, error)

type VoteType

type VoteType uint8

Jump to

Keyboard shortcuts

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