ouroboros_mock

package module
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

README

ouroboros-mock

Go library and CLI framework for mocking Ouroboros connections

Documentation

Index

Constants

View Source
const (
	MockNetworkMagic       uint32 = 999999
	MockProtocolVersionNtC uint16 = (14 + protocol.ProtocolVersionNtCOffset)
	MockProtocolVersionNtN uint16 = 13
	MockKeepAliveCookie    uint16 = 999
)

Variables

View Source
var ConversationEntryHandshakeNtCResponse = ConversationEntryOutput{
	ProtocolId: handshake.ProtocolId,
	IsResponse: true,
	Messages: []protocol.Message{
		handshake.NewMsgAcceptVersion(
			MockProtocolVersionNtC,
			protocol.VersionDataNtC9to14(MockNetworkMagic),
		),
	},
}

ConversationEntryHandshakeNtCResponse is a pre-defined conversation entry for a server NtC handshake response

View Source
var ConversationEntryHandshakeNtNResponse = ConversationEntryOutput{
	ProtocolId: handshake.ProtocolId,
	IsResponse: true,
	Messages: []protocol.Message{
		handshake.NewMsgAcceptVersion(
			MockProtocolVersionNtN,
			protocol.VersionDataNtN13andUp{
				VersionDataNtN11to12: protocol.VersionDataNtN11to12{
					CborNetworkMagic:                       MockNetworkMagic,
					CborInitiatorAndResponderDiffusionMode: protocol.DiffusionModeInitiatorOnly,
					CborPeerSharing:                        protocol.PeerSharingModeNoPeerSharing,
					CborQuery:                              protocol.QueryModeDisabled,
				},
			},
		),
	},
}

ConversationEntryHandshakeNtNResponse is a pre-defined conversation entry for a server NtN handshake response

View Source
var ConversationEntryHandshakeRequestGeneric = ConversationEntryInput{
	ProtocolId:  handshake.ProtocolId,
	MessageType: handshake.MessageTypeProposeVersions,
}

ConversationEntryHandshakeRequestGeneric is a pre-defined conversation event that matches a generic handshake request from a client

View Source
var ConversationEntryKeepAliveRequest = ConversationEntryInput{
	ProtocolId:      keepalive.ProtocolId,
	Message:         keepalive.NewMsgKeepAlive(MockKeepAliveCookie),
	MsgFromCborFunc: keepalive.NewMsgFromCbor,
}

ConversationEntryKeepAliveRequest is a pre-defined conversation entry for a keep-alive request

View Source
var ConversationEntryKeepAliveResponse = ConversationEntryOutput{
	ProtocolId: keepalive.ProtocolId,
	IsResponse: true,
	Messages: []protocol.Message{
		keepalive.NewMsgKeepAliveResponse(MockKeepAliveCookie),
	},
}

ConversationEntryKeepAliveResponse is a pre-defined conversation entry for a keep-alive response

ConversationKeepAlive is a pre-defined conversation with a NtN handshake and repeated keep-alive requests and responses

ConversationKeepAliveClose is a pre-defined conversation with a NtN handshake that will close the connection after receiving a keep-alive request

Functions

func NewConnection

func NewConnection(
	protocolRole ProtocolRole,
	conversation []ConversationEntry,
) net.Conn

NewConnection returns a new Connection with the provided conversation entries

Types

type Connection

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

Connection mocks an Ouroboros connection

func (*Connection) Close

func (c *Connection) Close() error

Close closes both sides of the connection. This is needed to satisfy the net.Conn interface

func (*Connection) ErrorChan added in v0.2.0

func (c *Connection) ErrorChan() <-chan error

func (*Connection) LocalAddr

func (c *Connection) LocalAddr() net.Addr

LocalAddr provides a proxy to the client-side connection's LocalAddr function. This is needed to satisfy the net.Conn interface

func (*Connection) Read

func (c *Connection) Read(b []byte) (n int, err error)

Read provides a proxy to the client-side connection's Read function. This is needed to satisfy the net.Conn interface

func (*Connection) RemoteAddr

func (c *Connection) RemoteAddr() net.Addr

RemoteAddr provides a proxy to the client-side connection's RemoteAddr function. This is needed to satisfy the net.Conn interface

func (*Connection) SetDeadline

func (c *Connection) SetDeadline(t time.Time) error

SetDeadline provides a proxy to the client-side connection's SetDeadline function. This is needed to satisfy the net.Conn interface

func (*Connection) SetReadDeadline

func (c *Connection) SetReadDeadline(t time.Time) error

SetReadDeadline provides a proxy to the client-side connection's SetReadDeadline function. This is needed to satisfy the net.Conn interface

func (*Connection) SetWriteDeadline

func (c *Connection) SetWriteDeadline(t time.Time) error

SetWriteDeadline provides a proxy to the client-side connection's SetWriteDeadline function. This is needed to satisfy the net.Conn interface

func (*Connection) Write

func (c *Connection) Write(b []byte) (n int, err error)

Write provides a proxy to the client-side connection's Write function. This is needed to satisfy the net.Conn interface

type ConversationEntry

type ConversationEntry interface {
	// contains filtered or unexported methods
}

type ConversationEntryClose added in v0.2.0

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

type ConversationEntryInput added in v0.2.0

type ConversationEntryInput struct {
	ProtocolId      uint16
	IsResponse      bool
	Message         protocol.Message
	MessageType     uint
	MsgFromCborFunc protocol.MessageFromCborFunc
	// contains filtered or unexported fields
}

type ConversationEntryOutput added in v0.2.0

type ConversationEntryOutput struct {
	ProtocolId uint16
	IsResponse bool
	Messages   []protocol.Message
	// contains filtered or unexported fields
}

type ConversationEntrySleep added in v0.2.0

type ConversationEntrySleep struct {
	Duration time.Duration
	// contains filtered or unexported fields
}

type MockAddr added in v0.3.0

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

func (MockAddr) Network added in v0.3.0

func (m MockAddr) Network() string

func (MockAddr) String added in v0.3.0

func (m MockAddr) String() string

type ProtocolRole

type ProtocolRole uint

ProtocolRole is an enum of the protocol roles

const (
	ProtocolRoleNone   ProtocolRole = 0 // Default (invalid) protocol role
	ProtocolRoleClient ProtocolRole = 1 // Client protocol role
	ProtocolRoleServer ProtocolRole = 2 // Server protocol role
)

Protocol roles

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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