Documentation ¶
Overview ¶
Package protocol implements the network bootstrapping protocols. It contains the node-to-node communication layer to administer private networks.
Index ¶
- Variables
- func Disconnect(ctx context.Context, host ihost.Host, peerID peer.ID)
- func DisconnectUnauthorized(ctx context.Context, host ihost.Host, networkConfig protector.NetworkConfig)
- type CoordinatedHandler
- func (h *CoordinatedHandler) Accept(ctx context.Context, peerID peer.ID) error
- func (h *CoordinatedHandler) AddNode(ctx context.Context, peerID peer.ID, addr multiaddr.Multiaddr, info []byte) error
- func (h *CoordinatedHandler) Close(ctx context.Context)
- func (h *CoordinatedHandler) CompleteBootstrap(context.Context) error
- func (h *CoordinatedHandler) HandleConfigUpdate(ctx context.Context, span *monitoring.Span, stream inet.Stream, ...) error
- func (h *CoordinatedHandler) HandlePropose(ctx context.Context, span *monitoring.Span, stream inet.Stream, ...) error
- func (h *CoordinatedHandler) Handshake(ctx context.Context) error
- func (h *CoordinatedHandler) Reject(ctx context.Context, peerID peer.ID) error
- func (h *CoordinatedHandler) RemoveNode(ctx context.Context, peerID peer.ID) error
- type CoordinatorHandler
- func (h *CoordinatorHandler) Accept(ctx context.Context, peerID peer.ID) error
- func (h *CoordinatorHandler) AddNode(ctx context.Context, peerID peer.ID, addr multiaddr.Multiaddr, info []byte) error
- func (h *CoordinatorHandler) Close(ctx context.Context)
- func (h *CoordinatorHandler) CompleteBootstrap(ctx context.Context) error
- func (h *CoordinatorHandler) HandleHandshake(ctx context.Context, span *monitoring.Span, stream inet.Stream, ...) error
- func (h *CoordinatorHandler) HandlePropose(ctx context.Context, span *monitoring.Span, stream inet.Stream, ...) error
- func (h *CoordinatorHandler) HandleVote(ctx context.Context, span *monitoring.Span, stream inet.Stream, ...) error
- func (h *CoordinatorHandler) Handshake(ctx context.Context) error
- func (h *CoordinatorHandler) Reject(ctx context.Context, peerID peer.ID) error
- func (h *CoordinatorHandler) RemoveNode(ctx context.Context, peerID peer.ID) error
- func (h *CoordinatorHandler) SendNetworkConfig(ctx context.Context)
- func (h *CoordinatorHandler) SendProposal(ctx context.Context, req *proposal.Request)
- func (h *CoordinatorHandler) ValidateSender(ctx context.Context, peerID peer.ID) error
- type Handler
- type PublicNetworkHandler
- func (h *PublicNetworkHandler) Accept(context.Context, peer.ID) error
- func (h *PublicNetworkHandler) AddNode(context.Context, peer.ID, multiaddr.Multiaddr, []byte) error
- func (h *PublicNetworkHandler) Close(context.Context)
- func (h *PublicNetworkHandler) CompleteBootstrap(context.Context) error
- func (h *PublicNetworkHandler) Handshake(context.Context) error
- func (h *PublicNetworkHandler) Reject(context.Context, peer.ID) error
- func (h *PublicNetworkHandler) RemoveNode(context.Context, peer.ID) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidProtectionMode = errors.New("invalid protection mode") ErrInvalidOperation = errors.New("invalid operation") )
Errors returned by bootstrap.
var ( // PrivateCoordinatedConfigPID is the protocol for receiving network // configuration updates in a private network. // Network participants should implement this protocol. PrivateCoordinatedConfigPID = protocol.ID("/indigo/node/bootstrap/private/coordinated/config/v1.0.0") // PrivateCoordinatedProposePID is the protocol for receiving network update // proposals from peers. // Network participants should implement this protocol. PrivateCoordinatedProposePID = protocol.ID("/indigo/node/bootstrap/private/coordinated/propose/v1.0.0") )
var ( // PrivateCoordinatorHandshakePID is the protocol for handling handshake // messages and sending the network participants list. // Only the network coordinator should implement this protocol. PrivateCoordinatorHandshakePID = protocol.ID("/indigo/node/bootstrap/private/coordinator/handshake/v1.0.0") // PrivateCoordinatorProposePID is the protocol for receiving network update // proposals from peers. // Only the network coordinator should implement this protocol. PrivateCoordinatorProposePID = protocol.ID("/indigo/node/bootstrap/private/coordinator/propose/v1.0.0") // PrivateCoordinatorVotePID is the protocol for receiving votes // from network participants. // Only the network coordinator should implement this protocol. PrivateCoordinatorVotePID = protocol.ID("/indigo/node/bootstrap/private/coordinator/vote/v1.0.0") )
var (
ErrUnknownNode = errors.New("unknown node: no addresses available")
)
Errors used by the coordinator.
var ( Participants = &view.View{ Name: "indigo-node/views/bootstrap/participants", Description: "number of network participants", Measure: participants.Measure, Aggregation: view.LastValue(), } )
Views exposed by the bootstrap app.
Functions ¶
func Disconnect ¶
Disconnect disconnects from the given peer.
func DisconnectUnauthorized ¶
func DisconnectUnauthorized( ctx context.Context, host ihost.Host, networkConfig protector.NetworkConfig, )
DisconnectUnauthorized disconnects from all unauthorized peers.
Types ¶
type CoordinatedHandler ¶
type CoordinatedHandler struct {
// contains filtered or unexported fields
}
CoordinatedHandler is the handler for a non-coordinator node in a private network that has a coordinator.
func (*CoordinatedHandler) Accept ¶
func (h *CoordinatedHandler) Accept(ctx context.Context, peerID peer.ID) error
Accept broadcasts a signed message to accept a proposal to add or remove a node.
func (*CoordinatedHandler) AddNode ¶
func (h *CoordinatedHandler) AddNode(ctx context.Context, peerID peer.ID, addr multiaddr.Multiaddr, info []byte) error
AddNode sends a proposal to add the node to the coordinator. Only the coordinator is allowed to make changes to the network config.
func (*CoordinatedHandler) Close ¶
func (h *CoordinatedHandler) Close(ctx context.Context)
Close removes the protocol handlers.
func (*CoordinatedHandler) CompleteBootstrap ¶
func (h *CoordinatedHandler) CompleteBootstrap(context.Context) error
CompleteBootstrap can't be used by a coordinated node. Only the coordinator can complete the bootstrap phase.
func (*CoordinatedHandler) HandleConfigUpdate ¶
func (h *CoordinatedHandler) HandleConfigUpdate( ctx context.Context, span *monitoring.Span, stream inet.Stream, codec streamutil.Codec, ) error
HandleConfigUpdate receives updates to the network configuration.
func (*CoordinatedHandler) HandlePropose ¶
func (h *CoordinatedHandler) HandlePropose( ctx context.Context, span *monitoring.Span, stream inet.Stream, codec streamutil.Codec, ) error
HandlePropose handles an incoming network update proposal.
func (*CoordinatedHandler) Handshake ¶
func (h *CoordinatedHandler) Handshake(ctx context.Context) error
Handshake connects to the coordinator for the initial handshake. The node is expected to receive the network configuration during that handshake.
func (*CoordinatedHandler) Reject ¶
func (h *CoordinatedHandler) Reject(ctx context.Context, peerID peer.ID) error
Reject ignores a proposal to add or remove a node.
func (*CoordinatedHandler) RemoveNode ¶
func (h *CoordinatedHandler) RemoveNode(ctx context.Context, peerID peer.ID) error
RemoveNode sends a proposal to remove the node to the coordinator. The coordinator will notify each node that needs to sign their agreement. The node will then eventually be removed if enough participants agree.
type CoordinatorHandler ¶
type CoordinatorHandler struct {
// contains filtered or unexported fields
}
CoordinatorHandler is the handler for the coordinator of a private network.
func (*CoordinatorHandler) Accept ¶
func (h *CoordinatorHandler) Accept(ctx context.Context, peerID peer.ID) error
Accept accepts a proposal to add or remove a node and notifies network participants.
func (*CoordinatorHandler) AddNode ¶
func (h *CoordinatorHandler) AddNode(ctx context.Context, peerID peer.ID, addr multiaddr.Multiaddr, info []byte) error
AddNode adds the node to the network configuration and notifies network participants.
func (*CoordinatorHandler) Close ¶
func (h *CoordinatorHandler) Close(ctx context.Context)
Close removes the protocol handlers.
func (*CoordinatorHandler) CompleteBootstrap ¶
func (h *CoordinatorHandler) CompleteBootstrap(ctx context.Context) error
CompleteBootstrap completes the bootstrap phase and notifies white-listed network participants.
func (*CoordinatorHandler) HandleHandshake ¶
func (h *CoordinatorHandler) HandleHandshake( ctx context.Context, span *monitoring.Span, stream inet.Stream, codec streamutil.Codec, ) error
HandleHandshake handles an incoming handshake and responds with the network configuration if handshake succeeds.
func (*CoordinatorHandler) HandlePropose ¶
func (h *CoordinatorHandler) HandlePropose( ctx context.Context, span *monitoring.Span, stream inet.Stream, codec streamutil.Codec, ) error
HandlePropose handles an incoming network update proposal.
func (*CoordinatorHandler) HandleVote ¶
func (h *CoordinatorHandler) HandleVote( ctx context.Context, span *monitoring.Span, stream inet.Stream, codec streamutil.Codec, ) error
HandleVote handles an incoming vote.
func (*CoordinatorHandler) Handshake ¶
func (h *CoordinatorHandler) Handshake(ctx context.Context) error
Handshake sends the current network configuration to all participants.
func (*CoordinatorHandler) Reject ¶
func (h *CoordinatorHandler) Reject(ctx context.Context, peerID peer.ID) error
Reject ignores a proposal to add or remove a node.
func (*CoordinatorHandler) RemoveNode ¶
func (h *CoordinatorHandler) RemoveNode(ctx context.Context, peerID peer.ID) error
RemoveNode removes a node from the network configuration and notifies network participants.
func (*CoordinatorHandler) SendNetworkConfig ¶
func (h *CoordinatorHandler) SendNetworkConfig(ctx context.Context)
SendNetworkConfig sends the current network configuration to all white-listed participants. It logs errors but swallows them.
func (*CoordinatorHandler) SendProposal ¶
func (h *CoordinatorHandler) SendProposal(ctx context.Context, req *proposal.Request)
SendProposal sends a network update proposal to all participants. The proposal contains a random challenge and needs to be signed by participants to confirm their agreement.
func (*CoordinatorHandler) ValidateSender ¶
func (h *CoordinatorHandler) ValidateSender(ctx context.Context, peerID peer.ID) error
ValidateSender rejects unauthorized requests. This should already be done at the connection level by our protector component, but it's always better to have multi-level security.
type Handler ¶
type Handler interface { // Handshake performs a network handshake. // This should be done when the node starts. Handshake(context.Context) error // AddNode adds a node to the network. Depending on the underlying // protocol, adding the node might require other node's approval // or even be rejected. AddNode(context.Context, peer.ID, multiaddr.Multiaddr, []byte) error // RemoveNode removes a node from the network. // Depending on the underlying protocol, removing the node might require // other node's approval or even be rejected. RemoveNode(context.Context, peer.ID) error // Accept accepts a proposal to add or remove a node (identified // by its PeerID). Accept(context.Context, peer.ID) error // Reject rejects a proposal to add or remove a node (identified // by its PeerID). Reject(context.Context, peer.ID) error // CompleteBootstrap completes the network bootstrapping phase. CompleteBootstrap(context.Context) error // Close closes all resources used by the protocol handler. Close(context.Context) }
Handler defines the methods to bootstrap and administer a network.
func New ¶
func New( host ihost.Host, streamProvider streamutil.Provider, networkMode *protector.NetworkMode, networkConfig protector.NetworkConfig, store proposal.Store, ) (Handler, error)
New creates the right instance of the Handler interface depending on the network parameters. It will register protocols to handle network requests.
func NewCoordinatedHandler ¶
func NewCoordinatedHandler( host ihost.Host, streamProvider streamutil.Provider, networkMode *protector.NetworkMode, networkConfig protector.NetworkConfig, proposalStore proposal.Store, ) Handler
NewCoordinatedHandler returns a Handler for a non-coordinator node.
func NewCoordinatorHandler ¶
func NewCoordinatorHandler( host ihost.Host, streamProvider streamutil.Provider, networkConfig protector.NetworkConfig, proposalStore proposal.Store, ) Handler
NewCoordinatorHandler returns a Handler for a coordinator node.
type PublicNetworkHandler ¶
type PublicNetworkHandler struct{}
PublicNetworkHandler is the handler for public networks. Public networks are completely open, so this handler doesn't do anything.
func (*PublicNetworkHandler) Accept ¶
func (h *PublicNetworkHandler) Accept(context.Context, peer.ID) error
Accept can't be used in a public network. You can directly connect to any node freely.
func (*PublicNetworkHandler) AddNode ¶
func (h *PublicNetworkHandler) AddNode(context.Context, peer.ID, multiaddr.Multiaddr, []byte) error
AddNode can't be used in a public network. You can directly connect to any node freely.
func (*PublicNetworkHandler) Close ¶
func (h *PublicNetworkHandler) Close(context.Context)
Close doesn't do anything.
func (*PublicNetworkHandler) CompleteBootstrap ¶
func (h *PublicNetworkHandler) CompleteBootstrap(context.Context) error
CompleteBootstrap can't be used in a public network. There is no bootstrapping phase in such networks.
func (*PublicNetworkHandler) Handshake ¶
func (h *PublicNetworkHandler) Handshake(context.Context) error
Handshake can't be used in a public network. You can directly connect to any node freely.
func (*PublicNetworkHandler) Reject ¶
func (h *PublicNetworkHandler) Reject(context.Context, peer.ID) error
Reject can't be used in a public network. You can directly connect to any node freely.
func (*PublicNetworkHandler) RemoveNode ¶
func (h *PublicNetworkHandler) RemoveNode(context.Context, peer.ID) error
RemoveNode can't be used in a public network. You can directly connect to any node freely.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package mockprotocol is a generated GoMock package.
|
Package mockprotocol is a generated GoMock package. |
Package proposal implements a store for network update proposals.
|
Package proposal implements a store for network update proposals. |
mocks
Package mockproposal is a generated GoMock package.
|
Package mockproposal is a generated GoMock package. |