Documentation
¶
Overview ¶
Package ouroboros implements support for interacting with Cardano nodes using the Ouroboros network protocol.
The Ouroboros network protocol consists of a muxer and multiple mini-protocols that provide various functions. A handshake and protocol versioning are used to ensure peer compatibility.
This package is the main entry point into this library. The other packages can be used outside of this one, but it's not a primary design goal.
Index ¶
- Constants
- Variables
- type Connection
- func (c *Connection) BlockFetch() *blockfetch.BlockFetch
- func (c *Connection) ChainSync() *chainsync.ChainSync
- func (c *Connection) Close() error
- func (c *Connection) Dial(proto string, address string) error
- func (c *Connection) DialTimeout(proto string, address string, timeout time.Duration) error
- func (c *Connection) ErrorChan() chan error
- func (c *Connection) Handshake() *handshake.Handshake
- func (c *Connection) Id() ConnectionId
- func (c *Connection) KeepAlive() *keepalive.KeepAlive
- func (c *Connection) LeiosFetch() *leiosfetch.LeiosFetch
- func (c *Connection) LeiosNotify() *leiosnotify.LeiosNotify
- func (c *Connection) LocalMessageNotification() *localmessagenotification.LocalMessageNotification
- func (c *Connection) LocalMessageSubmission() *localmessagesubmission.LocalMessageSubmission
- func (c *Connection) LocalStateQuery() *localstatequery.LocalStateQuery
- func (c *Connection) LocalTxMonitor() *localtxmonitor.LocalTxMonitor
- func (c *Connection) LocalTxSubmission() *localtxsubmission.LocalTxSubmission
- func (c *Connection) Muxer() *muxer.Muxer
- func (c *Connection) PeerSharing() *peersharing.PeerSharing
- func (c *Connection) ProtocolVersion() (uint16, protocol.VersionData)
- func (c *Connection) QueryReplyVersionMap() protocol.ProtocolVersionMap
- func (c *Connection) TxSubmission() *txsubmission.TxSubmission
- type ConnectionId
- type ConnectionOptionFunc
- func WithBlockFetchConfig(cfg blockfetch.Config) ConnectionOptionFunc
- func WithChainSyncConfig(cfg chainsync.Config) ConnectionOptionFunc
- func WithConnection(conn net.Conn) ConnectionOptionFunc
- func WithDMQ(useDMQ bool) ConnectionOptionFunc
- func WithDelayMuxerStart(delayMuxerStart bool) ConnectionOptionFunc
- func WithDelayProtocolStart(delayProtocolStart bool) ConnectionOptionFunc
- func WithErrorChan(errorChan chan error) ConnectionOptionFunc
- func WithFullDuplex(fullDuplex bool) ConnectionOptionFunc
- func WithKeepAlive(keepAlive bool) ConnectionOptionFunc
- func WithKeepAliveConfig(cfg keepalive.Config) ConnectionOptionFunc
- func WithLeiosFetchConfig(cfg leiosfetch.Config) ConnectionOptionFunc
- func WithLeiosNotifyConfig(cfg leiosnotify.Config) ConnectionOptionFunc
- func WithLocalMessageNotificationConfig(cfg localmessagenotification.Config) ConnectionOptionFunc
- func WithLocalMessageSubmissionConfig(cfg localmessagesubmission.Config) ConnectionOptionFunc
- func WithLocalStateQueryConfig(cfg localstatequery.Config) ConnectionOptionFunc
- func WithLocalTxMonitorConfig(cfg localtxmonitor.Config) ConnectionOptionFunc
- func WithLocalTxSubmissionConfig(cfg localtxsubmission.Config) ConnectionOptionFunc
- func WithLogger(logger *slog.Logger) ConnectionOptionFunc
- func WithNetwork(network Network) ConnectionOptionFunc
- func WithNetworkMagic(networkMagic uint32) ConnectionOptionFunc
- func WithNodeToNode(nodeToNode bool) ConnectionOptionFunc
- func WithPeerSharing(peerSharing bool) ConnectionOptionFunc
- func WithPeerSharingConfig(cfg peersharing.Config) ConnectionOptionFunc
- func WithQueryMode(queryMode bool) ConnectionOptionFunc
- func WithServer(server bool) ConnectionOptionFunc
- func WithTxSubmissionConfig(cfg txsubmission.Config) ConnectionOptionFunc
- type Network
- type NetworkAccessPoint
- type NetworkBootstrapPeer
- type NetworkPublicRoot
Constants ¶
const ( // Default connection timeout DefaultConnectTimeout = 30 * time.Second )
Variables ¶
var ( NetworkCardanoMainnet = Network{ Id: common.AddressNetworkMainnet, Name: "mainnet", NetworkMagic: 764824073, BootstrapPeers: []NetworkBootstrapPeer{ { Address: "backbone.cardano.iog.io", Port: 3001, }, { Address: "backbone.mainnet.emurgornd.com", Port: 3001, }, { Address: "backbone.mainnet.cardanofoundation.org", Port: 3001, }, }, } NetworkCardanoPreprod = Network{ Id: common.AddressNetworkTestnet, Name: "preprod", NetworkMagic: 1, BootstrapPeers: []NetworkBootstrapPeer{ { Address: "preprod-node.play.dev.cardano.org", Port: 3001, }, }, } NetworkCardanoPreview = Network{ Id: common.AddressNetworkTestnet, Name: "preview", NetworkMagic: 2, BootstrapPeers: []NetworkBootstrapPeer{ { Address: "preview-node.play.dev.cardano.org", Port: 3001, }, }, } NetworkCardanoSancho = Network{ Id: common.AddressNetworkTestnet, Name: "sanchonet", NetworkMagic: 4, BootstrapPeers: []NetworkBootstrapPeer{ { Address: "sancho-testnet.able-pool.io", Port: 6002, }, }, } // NetworkPrimeMainnet intentionally shares the same NetworkMagic as NetworkCardanoMainnet // because both networks use unaltered cardano-node binaries. Network differentiation // occurs through the bootstrap peers configuration. NetworkPrimeMainnet = Network{ Id: common.AddressNetworkMainnet, Name: "prime-mainnet", NetworkMagic: 764824073, BootstrapPeers: []NetworkBootstrapPeer{ { Address: "bootstrap.prime.mainnet.apexfusion.org", Port: 5521, }, }, PublicRoots: []NetworkPublicRoot{ { AccessPoints: []NetworkAccessPoint{ { Address: "relay-g1.prime.mainnet.apexfusion.org", Port: 5521, }, { Address: "relay-g2.prime.mainnet.apexfusion.org", Port: 5521, }, }, Advertise: true, Valency: 1, }, }, } NetworkPrimeTestnet = Network{ Id: common.AddressNetworkTestnet, Name: "prime-testnet", NetworkMagic: 3311, PublicRoots: []NetworkPublicRoot{ { AccessPoints: []NetworkAccessPoint{ { Address: "relay-0.prime.testnet.apexfusion.org", Port: 5521, }, { Address: "relay-1.prime.testnet.apexfusion.org", Port: 5521, }, }, Advertise: true, Valency: 1, }, }, } NetworkDevnet = Network{ Id: common.AddressNetworkTestnet, Name: "devnet", NetworkMagic: 42, } // Compatibility assignments (deprecated: use NetworkCardano* variants) NetworkMainnet = NetworkCardanoMainnet NetworkPreprod = NetworkCardanoPreprod NetworkPreview = NetworkCardanoPreview NetworkSancho = NetworkCardanoSancho )
Network definitions
Functions ¶
This section is empty.
Types ¶
type Connection ¶ added in v0.40.0
type Connection struct {
// contains filtered or unexported fields
}
The Connection type is a wrapper around a net.Conn object that handles communication using the Ouroboros network protocol over that connection
func New ¶
func New(options ...ConnectionOptionFunc) (*Connection, error)
New is an alias to NewConnection for backward compatibility
func NewConnection ¶ added in v0.40.0
func NewConnection(options ...ConnectionOptionFunc) (*Connection, error)
NewConnection returns a new Connection object with the specified options. If a connection is provided, the handshake will be started. An error will be returned if the handshake fails
func (*Connection) BlockFetch ¶ added in v0.40.0
func (c *Connection) BlockFetch() *blockfetch.BlockFetch
BlockFetch returns the block-fetch protocol handler
func (*Connection) ChainSync ¶ added in v0.40.0
func (c *Connection) ChainSync() *chainsync.ChainSync
ChainSync returns the chain-sync protocol handler
func (*Connection) Close ¶ added in v0.40.0
func (c *Connection) Close() error
Close will shutdown the Ouroboros connection
func (*Connection) Dial ¶ added in v0.40.0
func (c *Connection) Dial(proto string, address string) error
Dial will establish a connection using the specified protocol and address. It works the same as [DialTimeout], except that it provides a default connect timeout
func (*Connection) DialTimeout ¶ added in v0.68.0
DialTimeout will establish a connection using the specified protocol, address, and timeout. These parameters are passed to the net.DialTimeout func. The handshake will be started when a connection is established. An error will be returned if the connection fails, a connection was already established, or the handshake fails
func (*Connection) ErrorChan ¶ added in v0.40.0
func (c *Connection) ErrorChan() chan error
ErrorChan returns the channel for asynchronous errors
func (*Connection) Handshake ¶ added in v0.40.0
func (c *Connection) Handshake() *handshake.Handshake
Handshake returns the handshake protocol handler
func (*Connection) Id ¶ added in v0.78.0
func (c *Connection) Id() ConnectionId
Id returns the connection ID
func (*Connection) KeepAlive ¶ added in v0.40.0
func (c *Connection) KeepAlive() *keepalive.KeepAlive
KeepAlive returns the keep-alive protocol handler
func (*Connection) LeiosFetch ¶ added in v0.137.0
func (c *Connection) LeiosFetch() *leiosfetch.LeiosFetch
LeiosFetch returns the leios-fetch protocol handler
func (*Connection) LeiosNotify ¶ added in v0.136.0
func (c *Connection) LeiosNotify() *leiosnotify.LeiosNotify
LeiosNotify returns the leios-notify protocol handler
func (*Connection) LocalMessageNotification ¶ added in v0.167.0
func (c *Connection) LocalMessageNotification() *localmessagenotification.LocalMessageNotification
LocalMessageNotification returns the DMQ local-message-notification protocol handler. Only non-nil on a Connection constructed with WithDMQ(true).
func (*Connection) LocalMessageSubmission ¶ added in v0.167.0
func (c *Connection) LocalMessageSubmission() *localmessagesubmission.LocalMessageSubmission
LocalMessageSubmission returns the DMQ local-message-submission protocol handler. Only non-nil on a Connection constructed with WithDMQ(true).
func (*Connection) LocalStateQuery ¶ added in v0.40.0
func (c *Connection) LocalStateQuery() *localstatequery.LocalStateQuery
LocalStateQuery returns the local-state-query protocol handler
func (*Connection) LocalTxMonitor ¶ added in v0.40.0
func (c *Connection) LocalTxMonitor() *localtxmonitor.LocalTxMonitor
LocalTxMonitor returns the local-tx-monitor protocol handler
func (*Connection) LocalTxSubmission ¶ added in v0.40.0
func (c *Connection) LocalTxSubmission() *localtxsubmission.LocalTxSubmission
LocalTxSubmission returns the local-tx-submission protocol handler
func (*Connection) Muxer ¶ added in v0.40.0
func (c *Connection) Muxer() *muxer.Muxer
Muxer returns the muxer object for the Ouroboros connection
func (*Connection) PeerSharing ¶ added in v0.41.0
func (c *Connection) PeerSharing() *peersharing.PeerSharing
PeerSharing returns the peer-sharing protocol handler
func (*Connection) ProtocolVersion ¶ added in v0.77.0
func (c *Connection) ProtocolVersion() (uint16, protocol.VersionData)
ProtocolVersion returns the negotiated protocol version and the version data from the remote peer
func (*Connection) QueryReplyVersionMap ¶ added in v0.164.0
func (c *Connection) QueryReplyVersionMap() protocol.ProtocolVersionMap
QueryReplyVersionMap returns the version map received in response to a handshake query, or nil if a query was not performed
func (*Connection) TxSubmission ¶ added in v0.40.0
func (c *Connection) TxSubmission() *txsubmission.TxSubmission
TxSubmission returns the tx-submission protocol handler
type ConnectionId ¶ added in v0.78.0
type ConnectionId = connection.ConnectionId
type ConnectionOptionFunc ¶ added in v0.40.0
type ConnectionOptionFunc func(*Connection)
ConnectionOptionFunc is a type that represents functions that modify the Connection config
func WithBlockFetchConfig ¶
func WithBlockFetchConfig(cfg blockfetch.Config) ConnectionOptionFunc
WithBlockFetchConfig specifies BlockFetch protocol config
func WithChainSyncConfig ¶
func WithChainSyncConfig(cfg chainsync.Config) ConnectionOptionFunc
WithChainSyncConfig secifies ChainSync protocol config
func WithConnection ¶
func WithConnection(conn net.Conn) ConnectionOptionFunc
WithConnection specifies an existing connection to use. If none is provided, the Dial() function can be used to create one later
func WithDMQ ¶ added in v0.167.0
func WithDMQ(useDMQ bool) ConnectionOptionFunc
WithDMQ enables CIP-0137 DMQ node-to-client mode. The connection negotiates the DMQ N2C handshake (NodeToClientV_1, bit-12 encoded) using the configured network magic as the DMQ topic identifier, and exposes only the LocalMessageSubmission and LocalMessageNotification mini- protocols. Mutually exclusive with WithNodeToNode.
func WithDelayMuxerStart ¶
func WithDelayMuxerStart(delayMuxerStart bool) ConnectionOptionFunc
WithDelayMuxerStart specifies whether to delay the muxer start. This is useful if you need to take some custom actions before the muxer starts processing messages, generally when acting as a server
func WithDelayProtocolStart ¶ added in v0.41.0
func WithDelayProtocolStart(delayProtocolStart bool) ConnectionOptionFunc
WithDelayProtocolStart specifies whether to delay the start of the relevant mini-protocols. This is useful if you are maintaining lots of connections and want to reduce resource overhead by only starting particular protocols
func WithErrorChan ¶
func WithErrorChan(errorChan chan error) ConnectionOptionFunc
WithErrorChan specifies the error channel to use. If none is provided, one will be created
func WithFullDuplex ¶
func WithFullDuplex(fullDuplex bool) ConnectionOptionFunc
WithFullDuplex specifies whether to enable full-duplex mode when acting as a client
func WithKeepAlive ¶
func WithKeepAlive(keepAlive bool) ConnectionOptionFunc
WithKeepAlives specifies whether to use keep-alives. This is disabled by default
func WithKeepAliveConfig ¶
func WithKeepAliveConfig(cfg keepalive.Config) ConnectionOptionFunc
WithKeepAliveConfig specifies KeepAlive protocol config
func WithLeiosFetchConfig ¶ added in v0.152.0
func WithLeiosFetchConfig(cfg leiosfetch.Config) ConnectionOptionFunc
WithLeiosFetchConfig specifies LeiosFetch protocol config
func WithLeiosNotifyConfig ¶ added in v0.152.0
func WithLeiosNotifyConfig(cfg leiosnotify.Config) ConnectionOptionFunc
WithLeiosNotifyConfig specifies LeiosNotify protocol config
func WithLocalMessageNotificationConfig ¶ added in v0.167.0
func WithLocalMessageNotificationConfig( cfg localmessagenotification.Config, ) ConnectionOptionFunc
WithLocalMessageNotificationConfig specifies LocalMessageNotification protocol config (CIP-0137 DMQ N2C). Only effective when WithDMQ(true) is also set.
func WithLocalMessageSubmissionConfig ¶ added in v0.167.0
func WithLocalMessageSubmissionConfig( cfg localmessagesubmission.Config, ) ConnectionOptionFunc
WithLocalMessageSubmissionConfig specifies LocalMessageSubmission protocol config (CIP-0137 DMQ N2C). Only effective when WithDMQ(true) is also set.
func WithLocalStateQueryConfig ¶
func WithLocalStateQueryConfig( cfg localstatequery.Config, ) ConnectionOptionFunc
WithLocalStateQueryConfig specifies LocalStateQuery protocol config
func WithLocalTxMonitorConfig ¶ added in v0.73.0
func WithLocalTxMonitorConfig( cfg localtxmonitor.Config, ) ConnectionOptionFunc
WithLocalTxMonitorConfig specifies LocalTxMonitor protocol config
func WithLocalTxSubmissionConfig ¶
func WithLocalTxSubmissionConfig( cfg localtxsubmission.Config, ) ConnectionOptionFunc
WithLocalTxSubmissionConfig specifies LocalTxSubmission protocol config
func WithLogger ¶ added in v0.97.0
func WithLogger(logger *slog.Logger) ConnectionOptionFunc
WithLogger specifies the slog.Logger to use. This is empty by default
func WithNetwork ¶
func WithNetwork(network Network) ConnectionOptionFunc
WithNetwork specifies the network
func WithNetworkMagic ¶
func WithNetworkMagic(networkMagic uint32) ConnectionOptionFunc
WithNetworkMagic specifies the network magic value
func WithNodeToNode ¶
func WithNodeToNode(nodeToNode bool) ConnectionOptionFunc
WithNodeToNode specifies whether to use the node-to-node protocol. The default is to use node-to-client
func WithPeerSharing ¶ added in v0.75.0
func WithPeerSharing(peerSharing bool) ConnectionOptionFunc
WithPeerSharing specifies whether to enable peer sharing. This affects both the protocol handshake and whether the PeerSharing protocol is enabled
func WithPeerSharingConfig ¶ added in v0.41.0
func WithPeerSharingConfig(cfg peersharing.Config) ConnectionOptionFunc
WithPeerSharingConfig specifies PeerSharing protocol config
func WithQueryMode ¶ added in v0.164.0
func WithQueryMode(queryMode bool) ConnectionOptionFunc
WithQueryMode specifies whether to enable handshake query mode. When enabled, a ProposeVersions message with the query flag set is sent. The remote peer replies with all supported versions via MsgQueryReply and terminates the connection. Use Connection.QueryReplyVersionMap() to access the reply after a successful connection setup.
func WithServer ¶
func WithServer(server bool) ConnectionOptionFunc
WithServer specifies whether to act as a server
func WithTxSubmissionConfig ¶
func WithTxSubmissionConfig(cfg txsubmission.Config) ConnectionOptionFunc
WithTxSubmissionConfig specifies TxSubmission protocol config
type Network ¶
type Network struct {
Id uint8 // network ID used for addresses
Name string
NetworkMagic uint32
BootstrapPeers []NetworkBootstrapPeer
PublicRoots []NetworkPublicRoot
}
Network represents a Cardano network
func NetworkById ¶
NetworkById returns a predefined network by ID
func NetworkByName ¶
NetworkByName returns a predefined network by name
func NetworkByNetworkMagic ¶
NetworkByNetworkMagic returns a predefined network by network magic This will return NetworkCardanoMainnet and not NetworkPrimeMainnet for magic 764824073
type NetworkAccessPoint ¶ added in v0.143.0
type NetworkBootstrapPeer ¶ added in v0.101.0
type NetworkPublicRoot ¶ added in v0.143.0
type NetworkPublicRoot struct {
AccessPoints []NetworkAccessPoint
Advertise bool
Valency int
}
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cbor provides CBOR encoding/decoding utilities for Cardano data structures.
|
Package cbor provides CBOR encoding/decoding utilities for Cardano data structures. |
|
Package consensus provides Cardano consensus primitives for Ouroboros Praos.
|
Package consensus provides Cardano consensus primitives for Ouroboros Praos. |
|
byron
Package byron provides Ouroboros BFT (Byzantine Fault Tolerant) consensus implementation for the Byron era.
|
Package byron provides Ouroboros BFT (Byzantine Fault Tolerant) consensus implementation for the Byron era. |
|
genesis
Package genesis provides the Ouroboros Genesis chain selection rule.
|
Package genesis provides the Ouroboros Genesis chain selection rule. |
|
internal
|
|
|
bench
Package bench provides benchmark utilities and test fixtures for memory profiling.
|
Package bench provides benchmark utilities and test fixtures for memory profiling. |
|
Package kes implements Key-Evolving Signatures (KES) as used in Cardano's Praos consensus protocol.
|
Package kes implements Key-Evolving Signatures (KES) as used in Cardano's Praos consensus protocol. |
|
common
Package common provides shared types, interfaces, and utilities for all Cardano eras.
|
Package common provides shared types, interfaces, and utilities for all Cardano eras. |
|
Package muxer implements the muxer/demuxer that allows multiple mini-protocols to run over a single connection.
|
Package muxer implements the muxer/demuxer that allows multiple mini-protocols to run over a single connection. |
|
Package pipeline provides a concurrent block processing pipeline for Cardano blocks.
|
Package pipeline provides a concurrent block processing pipeline for Cardano blocks. |
|
Package protocol provides the common functionality for mini-protocols
|
Package protocol provides the common functionality for mini-protocols |
|
blockfetch
Package blockfetch implements the Ouroboros Block Fetch mini-protocol.
|
Package blockfetch implements the Ouroboros Block Fetch mini-protocol. |
|
chainsync
Package chainsync implements the Ouroboros chain-sync protocol
|
Package chainsync implements the Ouroboros chain-sync protocol |
|
common
The common package contains types used by multiple mini-protocols
|
The common package contains types used by multiple mini-protocols |
|
handshake
Package handshake implements the Ouroboros handshake protocol
|
Package handshake implements the Ouroboros handshake protocol |
|
keepalive
Package keepalive implements the Ouroboros KeepAlive mini-protocol, which is used to detect and maintain liveness between nodes in a network.
|
Package keepalive implements the Ouroboros KeepAlive mini-protocol, which is used to detect and maintain liveness between nodes in a network. |
|
localmessagenotification
Package localmessagenotification implements the Ouroboros local-message-notification protocol (CIP-0137)
|
Package localmessagenotification implements the Ouroboros local-message-notification protocol (CIP-0137) |
|
localmessagesubmission
Package localmessagesubmission implements the Ouroboros local-message-submission protocol (CIP-0137)
|
Package localmessagesubmission implements the Ouroboros local-message-submission protocol (CIP-0137) |
|
localstatequery
Package localstatequery implements the Ouroboros local state query mini-protocol.
|
Package localstatequery implements the Ouroboros local state query mini-protocol. |
|
localtxmonitor
Package localtxmonitor implements the Ouroboros local-tx-monitor protocol
|
Package localtxmonitor implements the Ouroboros local-tx-monitor protocol |
|
localtxsubmission
Package localtxsubmission implements the Ouroboros local-tx-submission protocol
|
Package localtxsubmission implements the Ouroboros local-tx-submission protocol |
|
messagesubmission
Package messagesubmission implements the Ouroboros message-submission protocol (CIP-0137)
|
Package messagesubmission implements the Ouroboros message-submission protocol (CIP-0137) |
|
peersharing
Package peersharing implements the Ouroboros PeerSharing protocol
|
Package peersharing implements the Ouroboros PeerSharing protocol |
|
txsubmission
Package txsubmission implements the Ouroboros TxSubmission protocol
|
Package txsubmission implements the Ouroboros TxSubmission protocol |
|
Package vrf implements ECVRF-ED25519-SHA512-Elligator2 as specified in IETF draft-irtf-cfrg-vrf-03, which is used in Cardano's Praos consensus protocol for leader election.
|
Package vrf implements ECVRF-ED25519-SHA512-Elligator2 as specified in IETF draft-irtf-cfrg-vrf-03, which is used in Cardano's Praos consensus protocol for leader election. |