peersharing

package
v0.89.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

Package peersharing implements the Ouroboros PeerSharing protocol

Index

Constants

View Source
const (
	MessageTypeShareRequest = 0
	MessageTypeSharePeers   = 1
	MessageTypeDone         = 2
)

Message types

View Source
const (
	ProtocolName = "peer-sharing"
	ProtocolId   = 10
)

Protocol identifiers

Variables

View Source
var StateMap = protocol.StateMap{
	// contains filtered or unexported fields
}

PeerSharing protocol state machine

Functions

func NewMsgFromCbor

func NewMsgFromCbor(msgType uint, data []byte) (protocol.Message, error)

NewMsgFromCbor parses a PeerSharing message from CBOR

Types

type CallbackContext added in v0.78.0

type CallbackContext struct {
	ConnectionId connection.ConnectionId
	Client       *Client
	Server       *Server
}

Callback context

type Client

type Client struct {
	*protocol.Protocol
	// contains filtered or unexported fields
}

Client implements the PeerSharing client

func NewClient

func NewClient(protoOptions protocol.ProtocolOptions, cfg *Config) *Client

NewClient returns a new PeerSharing client object

func (*Client) GetPeers

func (c *Client) GetPeers(amount uint8) ([]PeerAddress, error)

type Config

type Config struct {
	ShareRequestFunc ShareRequestFunc
	Timeout          time.Duration
}

Config is used to configure the PeerSharing protocol instance

func NewConfig

func NewConfig(options ...PeerSharingOptionFunc) Config

NewConfig returns a new PeerSharing config object with the provided options

type MsgDone

type MsgDone struct {
	protocol.MessageBase
}

func NewMsgDone

func NewMsgDone() *MsgDone

type MsgSharePeers

type MsgSharePeers struct {
	protocol.MessageBase
	PeerAddresses []PeerAddress
}

func NewMsgSharePeers

func NewMsgSharePeers(peerAddresses []PeerAddress) *MsgSharePeers

type MsgShareRequest

type MsgShareRequest struct {
	protocol.MessageBase
	Amount uint8
}

func NewMsgShareRequest

func NewMsgShareRequest(amount uint8) *MsgShareRequest

type PeerAddress added in v0.75.0

type PeerAddress struct {
	IP   net.IP
	Port uint16
}

func (*PeerAddress) UnmarshalCBOR added in v0.75.0

func (p *PeerAddress) UnmarshalCBOR(cborData []byte) error

type PeerSharing

type PeerSharing struct {
	Client *Client
	Server *Server
}

PeerSharing is a wrapper object that holds the client and server instances

func New

func New(protoOptions protocol.ProtocolOptions, cfg *Config) *PeerSharing

New returns a new PeerSharing object

type PeerSharingOptionFunc

type PeerSharingOptionFunc func(*Config)

PeerSharingOptionFunc represents a function used to modify the PeerSharing protocol config

func WithShareRequestFunc added in v0.76.0

func WithShareRequestFunc(
	shareRequestFunc ShareRequestFunc,
) PeerSharingOptionFunc

WithShareRequestFunc specifies the ShareRequest callback function

func WithTimeout

func WithTimeout(timeout time.Duration) PeerSharingOptionFunc

WithTimeout specifies the timeout for the handshake operation

type Server

type Server struct {
	*protocol.Protocol
	// contains filtered or unexported fields
}

Server implements the PeerSharing server

func NewServer

func NewServer(protoOptions protocol.ProtocolOptions, cfg *Config) *Server

NewServer returns a new PeerSharing server object

type ShareRequestFunc added in v0.76.0

type ShareRequestFunc func(CallbackContext, int) ([]PeerAddress, error)

Callback function types

Jump to

Keyboard shortcuts

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