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) 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) TxSubmission() *txsubmission.TxSubmission
- type ConnectionId
- type ConnectionManager
- func (c *ConnectionManager) AddConnection(conn *Connection)
- func (c *ConnectionManager) AddHost(address string, port uint, tags ...ConnectionManagerTag)
- func (c *ConnectionManager) AddHostsFromTopology(topology *TopologyConfig)
- func (c *ConnectionManager) GetConnectionById(connId ConnectionId) *ConnectionManagerConnection
- func (c *ConnectionManager) GetConnectionsByTags(tags ...ConnectionManagerTag) []*ConnectionManagerConnection
- func (c *ConnectionManager) RemoveConnection(connId ConnectionId)
- type ConnectionManagerConfig
- type ConnectionManagerConnClosedFunc
- type ConnectionManagerConnection
- type ConnectionManagerHost
- type ConnectionManagerTag
- type ConnectionOptionFunc
- func WithBlockFetchConfig(cfg blockfetch.Config) ConnectionOptionFunc
- func WithChainSyncConfig(cfg chainsync.Config) ConnectionOptionFunc
- func WithConnection(conn net.Conn) 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 WithLocalStateQueryConfig(cfg localstatequery.Config) ConnectionOptionFunc
- func WithLocalTxMonitorConfig(cfg localtxmonitor.Config) ConnectionOptionFunc
- func WithLocalTxSubmissionConfig(cfg localtxsubmission.Config) 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 WithServer(server bool) ConnectionOptionFunc
- func WithTxSubmissionConfig(cfg txsubmission.Config) ConnectionOptionFunc
- type Network
- type TopologyConfig
- type TopologyConfigLegacyProducer
- type TopologyConfigP2PAccessPoint
- type TopologyConfigP2PLocalRoot
- type TopologyConfigP2PPublicRoot
Constants ¶
const ( // Default connection timeout DefaultConnectTimeout = 30 * time.Second )
Variables ¶
var ( NetworkTestnet = Network{ Id: common.AddressNetworkTestnet, Name: "testnet", NetworkMagic: 1097911063, } NetworkMainnet = Network{ Id: common.AddressNetworkMainnet, Name: "mainnet", NetworkMagic: 764824073, PublicRootAddress: "backbone.cardano-mainnet.iohk.io", PublicRootPort: 3001, } NetworkPreprod = Network{ Id: common.AddressNetworkTestnet, Name: "preprod", NetworkMagic: 1, PublicRootAddress: "preprod-node.world.dev.cardano.org", PublicRootPort: 30000, } NetworkPreview = Network{ Id: common.AddressNetworkTestnet, Name: "preview", NetworkMagic: 2, PublicRootAddress: "preview-node.play.dev.cardano.org", PublicRootPort: 3001, } NetworkSancho = Network{ Id: common.AddressNetworkTestnet, Name: "sanchonet", NetworkMagic: 4, PublicRootAddress: "sanchonet-node.play.dev.cardano.org", PublicRootPort: 3001, } NetworkInvalid = Network{ Id: 0, Name: "invalid", NetworkMagic: 0, } // NetworkInvalid is used as a return value for lookup functions when a network isn't found )
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) 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) 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 ConnectionManager ¶ added in v0.65.0
type ConnectionManager struct {
// contains filtered or unexported fields
}
func NewConnectionManager ¶ added in v0.65.0
func NewConnectionManager(cfg ConnectionManagerConfig) *ConnectionManager
func (*ConnectionManager) AddConnection ¶ added in v0.65.0
func (c *ConnectionManager) AddConnection(conn *Connection)
func (*ConnectionManager) AddHost ¶ added in v0.65.0
func (c *ConnectionManager) AddHost( address string, port uint, tags ...ConnectionManagerTag, )
func (*ConnectionManager) AddHostsFromTopology ¶ added in v0.65.0
func (c *ConnectionManager) AddHostsFromTopology(topology *TopologyConfig)
func (*ConnectionManager) GetConnectionById ¶ added in v0.65.0
func (c *ConnectionManager) GetConnectionById( connId ConnectionId, ) *ConnectionManagerConnection
func (*ConnectionManager) GetConnectionsByTags ¶ added in v0.65.0
func (c *ConnectionManager) GetConnectionsByTags( tags ...ConnectionManagerTag, ) []*ConnectionManagerConnection
func (*ConnectionManager) RemoveConnection ¶ added in v0.66.0
func (c *ConnectionManager) RemoveConnection(connId ConnectionId)
type ConnectionManagerConfig ¶ added in v0.65.0
type ConnectionManagerConfig struct {
ConnClosedFunc ConnectionManagerConnClosedFunc
}
type ConnectionManagerConnClosedFunc ¶ added in v0.71.0
type ConnectionManagerConnClosedFunc func(ConnectionId, error)
ConnectionManagerConnClosedFunc is a function that takes a connection ID and an optional error
type ConnectionManagerConnection ¶ added in v0.65.0
type ConnectionManagerConnection struct { Conn *Connection Tags map[ConnectionManagerTag]bool }
func (*ConnectionManagerConnection) AddTags ¶ added in v0.65.0
func (c *ConnectionManagerConnection) AddTags(tags ...ConnectionManagerTag)
func (*ConnectionManagerConnection) RemoveTags ¶ added in v0.65.0
func (c *ConnectionManagerConnection) RemoveTags(tags ...ConnectionManagerTag)
type ConnectionManagerHost ¶ added in v0.65.0
type ConnectionManagerHost struct { Address string Port uint Tags map[ConnectionManagerTag]bool }
type ConnectionManagerTag ¶ added in v0.65.0
type ConnectionManagerTag uint16
ConnectionManagerTag represents the various tags that can be associated with a host or connection
const ( ConnectionManagerTagNone ConnectionManagerTag = iota ConnectionManagerTagHostProducer ConnectionManagerTagHostLocalRoot ConnectionManagerTagHostPublicRoot ConnectionManagerTagHostP2PLedger ConnectionManagerTagHostP2PGossip ConnectionManagerTagRoleInitiator ConnectionManagerTagRoleResponder )
func (ConnectionManagerTag) String ¶ added in v0.65.0
func (c ConnectionManagerTag) String() string
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 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 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 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 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 PublicRootAddress string PublicRootPort uint }
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
type TopologyConfig ¶ added in v0.62.0
type TopologyConfig struct { Producers []TopologyConfigLegacyProducer `json:"Producers"` LocalRoots []TopologyConfigP2PLocalRoot `json:"localRoots"` PublicRoots []TopologyConfigP2PPublicRoot `json:"publicRoots"` UseLedgerAfterSlot uint64 `json:"useLedgerAfterSlot"` }
TopologyConfig represents a Cardano node topology config
func NewTopologyConfigFromFile ¶ added in v0.62.0
func NewTopologyConfigFromFile(path string) (*TopologyConfig, error)
func NewTopologyConfigFromReader ¶ added in v0.62.0
func NewTopologyConfigFromReader(r io.Reader) (*TopologyConfig, error)
type TopologyConfigLegacyProducer ¶ added in v0.62.0
type TopologyConfigP2PAccessPoint ¶ added in v0.62.0
type TopologyConfigP2PLocalRoot ¶ added in v0.62.0
type TopologyConfigP2PLocalRoot struct { AccessPoints []TopologyConfigP2PAccessPoint `json:"accessPoints"` Advertise bool `json:"advertise"` Valency uint `json:"valency"` }
type TopologyConfigP2PPublicRoot ¶ added in v0.62.0
type TopologyConfigP2PPublicRoot struct { AccessPoints []TopologyConfigP2PAccessPoint `json:"accessPoints"` Advertise bool `json:"advertise"` Valency uint `json:"valency"` }
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package base58 provides an API for working with modified base58 and Base58Check encodings.
|
Package base58 provides an API for working with modified base58 and Base58Check encodings. |
Package bech32 provides a Go implementation of the bech32 format specified in BIP 173.
|
Package bech32 provides a Go implementation of the bech32 format specified in BIP 173. |
cmd
|
|
internal
|
|
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 protocol provides the common functionality for mini-protocols
|
Package protocol provides the common functionality for mini-protocols |
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 |
localstatequery
Package localstatequery implements the Ouroboros local-state-query protocol
|
Package localstatequery implements the Ouroboros local-state-query 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 |
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 |