proposal

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: AGPL-3.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package proposal implements a store for network update proposals.

Index

Constants

View Source
const (
	// DefaultExpiration expires requests after a week.
	DefaultExpiration = 24 * 7 * time.Hour
)

Variables

View Source
var (
	ErrInvalidPeerID   = errors.New("invalid peer ID")
	ErrInvalidPeerAddr = errors.New("invalid peer address")
	ErrMissingPeerAddr = errors.New("missing peer address")
	ErrMissingRequest  = errors.New("no request for the given peer ID")
)

Errors used by the request component.

View Source
var (
	ErrMissingChallenge   = errors.New("missing challenge")
	ErrMissingPrivateKey  = errors.New("missing private key")
	ErrInvalidRequestType = errors.New("invalid request type")
	ErrInvalidChallenge   = errors.New("invalid challenge")
	ErrInvalidSignature   = errors.New("invalid signature")
)

Errors used by the Vote struct.

Functions

This section is empty.

Types

type FileSaver

type FileSaver struct {
	Store
	// contains filtered or unexported fields
}

FileSaver saves the store data to a file when it changes.

func (*FileSaver) AddRequest

func (s *FileSaver) AddRequest(ctx context.Context, r *Request) error

AddRequest adds a new request and saves to disk.

func (*FileSaver) AddVote

func (s *FileSaver) AddVote(ctx context.Context, v *Vote) error

AddVote adds a new vote and saves to disk.

func (*FileSaver) List

func (s *FileSaver) List(ctx context.Context) ([]*Request, error)

List all the pending requests and saves to disk (because expired requests need to be removed).

func (*FileSaver) Load

func (s *FileSaver) Load(ctx context.Context) error

Load loads previous data.

func (*FileSaver) Remove

func (s *FileSaver) Remove(ctx context.Context, peerID peer.ID) error

Remove a request and saves to disk.

func (*FileSaver) Save

func (s *FileSaver) Save(ctx context.Context) error

Save saves the data to disk.

type InMemoryStore

type InMemoryStore struct {
	// contains filtered or unexported fields
}

InMemoryStore stores the requests in memory only.

func (*InMemoryStore) AddRequest

func (s *InMemoryStore) AddRequest(ctx context.Context, r *Request) error

AddRequest adds a new request.

func (*InMemoryStore) AddVote

func (s *InMemoryStore) AddVote(ctx context.Context, v *Vote) error

AddVote adds a vote to a request.

func (*InMemoryStore) Get

func (s *InMemoryStore) Get(ctx context.Context, peerID peer.ID) (*Request, error)

Get a request for a given PeerID.

func (*InMemoryStore) GetVotes

func (s *InMemoryStore) GetVotes(ctx context.Context, peerID peer.ID) ([]*Vote, error)

GetVotes gets the votes for a given PeerID.

func (*InMemoryStore) List

func (s *InMemoryStore) List(ctx context.Context) ([]*Request, error)

List all the pending requests.

func (*InMemoryStore) MarshalJSON

func (s *InMemoryStore) MarshalJSON() ([]byte, error)

MarshalJSON marshals the store's content to JSON.

func (*InMemoryStore) Remove

func (s *InMemoryStore) Remove(ctx context.Context, peerID peer.ID) error

Remove removes a request and its votes.

func (*InMemoryStore) UnmarshalJSON

func (s *InMemoryStore) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON content to the store.

type Request

type Request struct {
	Type     Type
	PeerID   peer.ID
	PeerAddr multiaddr.Multiaddr
	Info     []byte

	Challenge []byte
	Expires   time.Time
}

Request packages all the elements of a network update request.

func NewAddRequest

func NewAddRequest(nodeID *pb.NodeIdentity) (*Request, error)

NewAddRequest creates a request to add a node to the network.

func NewRemoveRequest

func NewRemoveRequest(nodeID *pb.NodeIdentity) (*Request, error)

NewRemoveRequest creates a request to remove a node from the network.

func (*Request) FromUpdateProposal

func (r *Request) FromUpdateProposal(p *pb.UpdateProposal) error

FromUpdateProposal converts from a protobuf format.

func (*Request) MarshalJSON

func (r *Request) MarshalJSON() ([]byte, error)

MarshalJSON marshals the request to JSON.

func (*Request) ToUpdateProposal

func (r *Request) ToUpdateProposal() *pb.UpdateProposal

ToUpdateProposal converts to a protobuf format.

func (*Request) UnmarshalJSON

func (r *Request) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the request from JSON.

type Store

type Store interface {
	// AddRequest adds a pending request.
	// If overwrites a previous request for that PeerID if there is one.
	AddRequest(context.Context, *Request) error

	// AddVote adds a vote to a request.
	AddVote(context.Context, *Vote) error

	// Remove removes a request (and partial votes).
	Remove(context.Context, peer.ID) error

	// Get a request for a given PeerID.
	Get(context.Context, peer.ID) (*Request, error)

	// GetVotes gets the votes for a given PeerID.
	GetVotes(context.Context, peer.ID) ([]*Vote, error)

	// List all the pending requests.
	List(context.Context) ([]*Request, error)
}

Store is used to store pending network updates until they have been approved.

func NewInMemoryStore

func NewInMemoryStore() Store

NewInMemoryStore returns a new store without disk backup.

func WrapWithSaver

func WrapWithSaver(ctx context.Context, s Store, path string) (Store, error)

WrapWithSaver wraps an existing Store and saves changes to a file. It loads existing data if present.

type Type

type Type int

Type defines the types of proposals supported.

const (
	// AddNode adds a node to the network.
	AddNode Type = 0
	// RemoveNode removes a node from the network.
	RemoveNode Type = 1
)

func (Type) String

func (t Type) String() string

String returns a friendly name for the type of proposal.

type Vote

type Vote struct {
	Type   Type
	PeerID peer.ID

	Challenge []byte
	Signature *crypto.Signature
}

Vote for a network update.

func NewVote

func NewVote(ctx context.Context, sk ic.PrivKey, r *Request) (*Vote, error)

NewVote votes for a given request.

func (*Vote) FromProtoVote

func (v *Vote) FromProtoVote(proto *pb.Vote) error

FromProtoVote converts from a protobuf message.

func (*Vote) MarshalJSON

func (v *Vote) MarshalJSON() ([]byte, error)

MarshalJSON marshals the vote to JSON.

func (*Vote) ToProtoVote

func (v *Vote) ToProtoVote() *pb.Vote

ToProtoVote converts to a protobuf message.

func (*Vote) UnmarshalJSON

func (v *Vote) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the vote from JSON.

func (*Vote) Verify

func (v *Vote) Verify(ctx context.Context, r *Request) error

Verify that vote is valid for the given request.

Directories

Path Synopsis
Package mockproposal is a generated GoMock package.
Package mockproposal is a generated GoMock package.

Jump to

Keyboard shortcuts

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