Documentation ¶
Overview ¶
Package proposal implements a store for network update proposals.
Index ¶
- Constants
- Variables
- type FileSaver
- func (s *FileSaver) AddRequest(ctx context.Context, r *Request) error
- func (s *FileSaver) AddVote(ctx context.Context, v *Vote) error
- func (s *FileSaver) List(ctx context.Context) ([]*Request, error)
- func (s *FileSaver) Load(ctx context.Context) error
- func (s *FileSaver) Remove(ctx context.Context, peerID peer.ID) error
- func (s *FileSaver) Save(ctx context.Context) error
- type InMemoryStore
- func (s *InMemoryStore) AddRequest(ctx context.Context, r *Request) error
- func (s *InMemoryStore) AddVote(ctx context.Context, v *Vote) error
- func (s *InMemoryStore) Get(ctx context.Context, peerID peer.ID) (*Request, error)
- func (s *InMemoryStore) GetVotes(ctx context.Context, peerID peer.ID) ([]*Vote, error)
- func (s *InMemoryStore) List(ctx context.Context) ([]*Request, error)
- func (s *InMemoryStore) MarshalJSON() ([]byte, error)
- func (s *InMemoryStore) Remove(ctx context.Context, peerID peer.ID) error
- func (s *InMemoryStore) UnmarshalJSON(data []byte) error
- type Request
- type Store
- type Type
- type Vote
Constants ¶
const ( // DefaultExpiration expires requests after a week. DefaultExpiration = 24 * 7 * time.Hour )
Variables ¶
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.
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 ¶
AddRequest adds a new request and saves to disk.
func (*FileSaver) List ¶
List all the pending requests and saves to disk (because expired requests need to be removed).
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 ¶
MarshalJSON marshals the request to JSON.
func (*Request) ToUpdateProposal ¶
func (r *Request) ToUpdateProposal() *pb.UpdateProposal
ToUpdateProposal converts to a protobuf format.
func (*Request) UnmarshalJSON ¶
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.
type Vote ¶
Vote for a network update.
func (*Vote) FromProtoVote ¶
FromProtoVote converts from a protobuf message.
func (*Vote) MarshalJSON ¶
MarshalJSON marshals the vote to JSON.
func (*Vote) ToProtoVote ¶
ToProtoVote converts to a protobuf message.
func (*Vote) UnmarshalJSON ¶
UnmarshalJSON unmarshals the vote from JSON.