responses

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Unlicense Imports: 8 Imported by: 0

Documentation

Overview

Package responses handles waiting for and responding to received responses, including tracking the session billing and custom callback hooks when responses arrive.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(id nonce.ID, ifc interface{}, b slice.Bytes) (e error)

Callback is a function signature of the callback hook to be added to the dispatch parameters that is intended to be called when the response arrives. This is distinct from the billing callbacks, this is application-specific.

type Pending

type Pending struct {

	// This data must not be read and written concurrently.
	sync.Mutex
	// contains filtered or unexported fields
}

Pending is a mutex protected data structure for storing pending Response data.

func (*Pending) Add

func (p *Pending) Add(pr ResponseParams)

Add a new response using the ResponseParams.

func (*Pending) Find

func (p *Pending) Find(id nonce.ID) (pr *Response)

Find the response with the matching nonce.ID.

func (*Pending) FindOlder

func (p *Pending) FindOlder(t time.Time) (r []*Response)

FindOlder returns all Response data that is is older than a specified time.

func (*Pending) GetOldestPending

func (p *Pending) GetOldestPending() (pr *Response)

GetOldestPending returns the oldest pending response. In fact, this is just the last one with the lowest index, because they are not sorted and are always added in chronological order.

New items are always added to the end, and so the first index is the oldest in the slice.

func (*Pending) ProcessAndDelete

func (p *Pending) ProcessAndDelete(id nonce.ID, ifc interface{},
	b slice.Bytes) (found bool, e error)

ProcessAndDelete runs the callback and post accounting function list and deletes the pending response.

Returns true if it found and deleted a pending response.

type Response

type Response struct {

	// ID is an internal reference code for associating data together.
	ID nonce.ID

	// SentSize is the number of bytes total in the outgoing message (before
	// padding).
	SentSize int

	// Port is the destination port of the service the Exit or other reply-enabling
	// onion is intended for.
	Port uint16

	// Billable is a list of the public keys of the sessions that are used in the
	// circuit.
	Billable []crypto.PubBytes

	// Return is the last hop return session used for this message.
	Return crypto.PubBytes

	// PostAcct is a slice of functions that action the balance adjustment of the
	// message for each of the hops in the circuit. This enables the engine to
	// contact the relays in a circuit in outbound order to both correctly update the
	// session balance and diagnose which peer the message did not get to (due to
	// being offline or congested).
	PostAcct []func()

	// Sessions that were used in the circuit.
	sessions.Sessions

	// Callback is a hook added to the dispatch for the message that will be executed with the reassembled response packet.
	Callback Callback

	// Time records the time this message was dispatched.
	Time time.Time

	// Success channel is closed when the transmission is successful. todo: nothing is actually using this?
	Success qu.C
}

Response is a record stored in anticipation of a response coming back from the peer processing an Exit or message for a service available at a relay.

type ResponseParams

type ResponseParams struct {
	ID       nonce.ID
	SentSize int
	S        sessions.Sessions
	Billable []crypto.PubBytes
	Ret      crypto.PubBytes
	Port     uint16
	Callback Callback
	PostAcct []func()
}

ResponseParams is the inputs required to construct a Response.

Jump to

Keyboard shortcuts

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