bufferedagent

package
v0.0.0-...-9190965 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package bufferedagent contains a rudimentary and experimental implementation of an agent that coordinates a TCP network connection, initial handshake, and channel opens, payments, and closes, and buffers outgoing payments, collapsing them down to a single payment.

The agent is intended for use in examples only at this point and is not intended to be stable or reliable.

Index

Constants

This section is empty.

Variables

View Source
var ErrBufferFull = errors.New("buffer full")

ErrBufferFull indicates that the payment buffer has reached it's maximum size as configured when the buffered agent was created.

Functions

This section is empty.

Types

type Agent

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

Agent coordinates a payment channel over a TCP connection, and buffers payments by collapsing them down into single payments while it waits for a chance to make the next payment.

All functions of the Agent are safe to call from multiple goroutines as they use an internal mutex.

func NewAgent

func NewAgent(c Config) *Agent

NewAgent constructs a new buffered agent with the given config.

func (*Agent) Close

func (a *Agent) Close() error

Close submits the close transaction to the network. DeclareClose must have been called by one of the participants before hand.

func (*Agent) ConnectTCP

func (a *Agent) ConnectTCP(addr string) error

ConnectTCP connects to the given address for establishing a single payment channel.

func (*Agent) DeclareClose

func (a *Agent) DeclareClose() error

DeclareClose starts the close process of the channel by submitting the latest declaration to the network, then coordinating an immediate close with the other participant. If an immediate close can be coordinated it will automatically occur, otherwise a participant must call Close after the observation period has passed to close the channel.

It is not possible to make new payments once called.

func (*Agent) MaxBufferSize

func (a *Agent) MaxBufferSize() int

MaxBufferSize returns the maximum buffer size that was configured at construction or changed with SetMaxBufferSize. The maximum buffer size is the maximum number of payments that can be buffered while waiting for the opportunity to include the buffered payments in an agreement.

func (*Agent) Open

func (a *Agent) Open(asset state.Asset) error

Open opens the channel for the given asset. The open is coordinated with the other participant. An immediate error may be indicated if the attempt to open was immediately unsuccessful. However, more likely any error will be returned on the events channel as the process involves the other participant.

func (*Agent) Payment

func (a *Agent) Payment(paymentAmount int64) (bufferID string, err error)

Payment is equivalent to calling PaymentWithMemo with an empty memo.

func (*Agent) PaymentWithMemo

func (a *Agent) PaymentWithMemo(paymentAmount int64, memo string) (bufferID string, err error)

PaymentWithMemo buffers a payment which will be paid in the next agreement. The identifier for the buffer is returned. An error may be returned immediately if the buffer is full. Any errors relating to the payment, and confirmation of the payment, will be returned asynchronously on the events channel.

func (*Agent) ServeTCP

func (a *Agent) ServeTCP(addr string) error

ServeTCP listens on the given address for a single incoming connection to start a payment channel.

func (*Agent) SetMaxBufferSize

func (a *Agent) SetMaxBufferSize(maxbufferSize int)

SetMaxBufferSize sets and changes the maximum buffer size.

func (*Agent) Wait

func (a *Agent) Wait()

Wait waits for sending of all buffered payments to complete and the buffer to be empty. It can be called multiple times, and it can be called in between sends of new payments.

type BufferedPayment

type BufferedPayment struct {
	Amount int64
	Memo   string
}

BufferedPayment contains the details of a payment that is buffered and transmitted in the memo of an agreement on the payment channel.

type BufferedPaymentsReceivedEvent

type BufferedPaymentsReceivedEvent struct {
	agent.PaymentReceivedEvent
	BufferID       string
	BufferByteSize int
	Payments       []BufferedPayment
}

BufferedPaymentReceivedEvent occurs when a payment is received that was buffered.

type BufferedPaymentsSentEvent

type BufferedPaymentsSentEvent struct {
	agent.PaymentSentEvent
	BufferID       string
	BufferByteSize int
	Payments       []BufferedPayment
}

BufferedPaymentSentEvent occurs when a payment is sent that was buffered.

type Config

type Config struct {
	Agent       *agent.Agent
	AgentEvents <-chan interface{}

	MaxBufferSize int

	LogWriter io.Writer

	Events chan<- interface{}
}

Config contains the information that can be supplied to configure the Agent at construction.

Jump to

Keyboard shortcuts

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