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 ¶
- Variables
- type Agent
- func (a *Agent) Close() error
- func (a *Agent) ConnectTCP(addr string) error
- func (a *Agent) DeclareClose() error
- func (a *Agent) MaxBufferSize() int
- func (a *Agent) Open(asset state.Asset) error
- func (a *Agent) Payment(paymentAmount int64) (bufferID string, err error)
- func (a *Agent) PaymentWithMemo(paymentAmount int64, memo string) (bufferID string, err error)
- func (a *Agent) ServeTCP(addr string) error
- func (a *Agent) SetMaxBufferSize(maxbufferSize int)
- func (a *Agent) Wait()
- type BufferedPayment
- type BufferedPaymentsReceivedEvent
- type BufferedPaymentsSentEvent
- type Config
Constants ¶
This section is empty.
Variables ¶
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 (*Agent) Close ¶
Close submits the close transaction to the network. DeclareClose must have been called by one of the participants before hand.
func (*Agent) ConnectTCP ¶
ConnectTCP connects to the given address for establishing a single payment channel.
func (*Agent) DeclareClose ¶
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 ¶
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 ¶
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) PaymentWithMemo ¶
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 ¶
ServeTCP listens on the given address for a single incoming connection to start a payment channel.
func (*Agent) SetMaxBufferSize ¶
SetMaxBufferSize sets and changes the maximum buffer size.
type BufferedPayment ¶
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.