sess

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: 20 Imported by: 0

Documentation

Overview

Package sess provides the Session Manager, which keeps track of a client's sessions.

This package provides access to subsystems related to it such as pending payments, handles accounting to attempt to keep clients and relays session balances in sync without any unnecessary communication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StandardCircuit

func StandardCircuit() []byte

StandardCircuit is a slice defining a standard circuit (5 is the return session).

Types

type CircuitCache

type CircuitCache map[nonce.ID]*sessions.Circuit

A CircuitCache stores each of the 5 hops of a peer node. Ideally a client puts equal balance on these and selects them randomly in each of their hops.

todo: hop 2, the exit, kinda has a different semantic, in that it pays for

exit fees primarily.

func (CircuitCache) Add

Add a session to a CircuitCache.

type Data

type Data struct {

	// B is the bytes of data that were sent out.
	B slice.Bytes

	// Sessions are the list of sessions in the circuit.
	Sessions sessions.Sessions

	// Billable is the public keys of the sessions used in the circuit.
	//
	// todo: is this actually used???
	Billable []crypto.PubBytes

	// Ret is the return session, which isn't billable.
	Ret crypto.PubBytes

	// ID is the transmission nonce.ID, as found in PendingResponses.
	ID nonce.ID

	// Port is the well-known port designating the protocol of the message.
	Port uint16

	// PostAcct is a collection of hooks that are to be run on the successful
	// receiving of the response or confirmation and the completion of all relaying
	// from source back to source.
	PostAcct []func()
}

Data is a data structure returned from engine.PostAcctOnion that tracks the information related to the use of a session.

type Manager

type Manager struct {

	// PendingPayments are tracked by the Manager as these should correlate to
	// incoming Session onions giving the keys.
	PendingPayments payments.PendingPayments

	// Sessions that the Manager is managing.
	sessions.Sessions

	// CircuitCache is an index that groups Sessions together by the peer they relate
	// to.
	CircuitCache

	Protocols protocols.NetworkProtocols

	// This is concurrently accessed, so it needs locking.
	sync.Mutex
	// contains filtered or unexported fields
}

Manager is a session manager for Indra, handling sessions and services.

func NewSessionManager

func NewSessionManager(protocols protocols.NetworkProtocols,
	n *node.Node) *Manager

NewSessionManager creates a new session manager.

func (*Manager) AddLocalNodeAddress added in v0.1.19

func (sm *Manager) AddLocalNodeAddress(addr *netip.AddrPort)

AddLocalNodeAddress changes the local node address.

func (*Manager) AddLocalNodeAddresses added in v0.1.19

func (sm *Manager) AddLocalNodeAddresses(addr []*netip.AddrPort)

AddLocalNodeAddresses changes the local node address.

func (*Manager) AddNodes

func (sm *Manager) AddNodes(nn ...*node.Node)

AddNodes adds a Node to a Nodes.

func (*Manager) AddPendingPayment

func (sm *Manager) AddPendingPayment(np *payments.Payment)

AddPendingPayment adds a received incoming payment message to await the session keys.

func (*Manager) AddServiceToLocalNode

func (sm *Manager) AddServiceToLocalNode(s *services.Service) (e error)

AddServiceToLocalNode adds a service to the local node.

func (*Manager) AddSession

func (sm *Manager) AddSession(s *sessions.Data)

AddSession adds a session to the session cache.

func (*Manager) ClearPendingPayments

func (sm *Manager) ClearPendingPayments()

ClearPendingPayments is used only for debugging, removing all pending payments, making the engine forget about payments it received.

func (*Manager) ClearSessions

func (sm *Manager) ClearSessions()

ClearSessions is used only for debugging, removing all but the first session, which is the engine's initial return session.

func (*Manager) DecSession

func (sm *Manager) DecSession(id crypto.PubBytes, msats int, sender bool,
	typ string) bool

DecSession decrements credit (mSat) on a session.

func (*Manager) DeleteNodeAndSessions

func (sm *Manager) DeleteNodeAndSessions(id nonce.ID)

DeleteNodeAndSessions deletes a node and all the sessions for it.

func (*Manager) DeleteNodeByAddrPort

func (sm *Manager) DeleteNodeByAddrPort(ip *netip.AddrPort) (e error)

DeleteNodeByAddrPort deletes a node identified by a netip.AddrPort.

func (*Manager) DeleteNodeByID

func (sm *Manager) DeleteNodeByID(ii nonce.ID) (e error)

DeleteNodeByID deletes a node identified by an Keys.

func (*Manager) DeletePendingPayment

func (sm *Manager) DeletePendingPayment(preimage sha256.Hash)

DeletePendingPayment deletes a pending payment by the preimage hash.

func (*Manager) DeleteSession

func (sm *Manager) DeleteSession(id crypto.PubBytes)

func (*Manager) FindCloaked

func (sm *Manager) FindCloaked(clk crypto.CloakedPubKey) (hdr *crypto.Prv,
	pld *crypto.Prv, sess *sessions.Data, identity bool)

FindCloaked searches the client identity key and the sessions for a match. It returns the session as well, though not all users of this function will need this.

func (*Manager) FindNodeByAddrPort

func (sm *Manager) FindNodeByAddrPort(id *netip.AddrPort) (no *node.Node)

FindNodeByAddrPort searches for a Node by netip.AddrPort.

func (*Manager) FindNodeByID

func (sm *Manager) FindNodeByID(i nonce.ID) (no *node.Node)

FindNodeByID searches for a Node by Keys.

func (*Manager) FindNodeByIdentity

func (sm *Manager) FindNodeByIdentity(id *crypto.Pub) (no *node.Node)

FindNodeByIdentity searches for a Node by netip.AddrPort.

func (*Manager) FindNodeByIndex

func (sm *Manager) FindNodeByIndex(i int) (no *node.Node)

FindNodeByIndex returns the node at a given position in the array.

func (*Manager) FindPendingPayment

func (sm *Manager) FindPendingPayment(id nonce.ID) (pp *payments.Payment)

FindPendingPayment searches for a pending payment with the matching ID.

func (*Manager) FindPendingPreimage

func (sm *Manager) FindPendingPreimage(pi sha256.Hash) (pp *payments.Payment)

FindPendingPreimage searches for a pending payment with e matching preimage.

func (*Manager) FindSessionByHeader

func (sm *Manager) FindSessionByHeader(prvKey *crypto.Prv) *sessions.Data

FindSessionByHeader searches for a session with a matching header private key.

func (*Manager) FindSessionByHeaderPub

func (sm *Manager) FindSessionByHeaderPub(pubKey *crypto.Pub) *sessions.Data

FindSessionByHeaderPub searches for a session with a matching header public key.

func (*Manager) FindSessionByPubkey

func (sm *Manager) FindSessionByPubkey(id crypto.PubBytes) *sessions.Data

FindSessionByPubkey searches for a session with a matching public key.

func (*Manager) FindSessionPreimage

func (sm *Manager) FindSessionPreimage(pr sha256.Hash) *sessions.Data

FindSessionPreimage searches for a session with a matching preimage hash.

func (*Manager) ForEachNode

func (sm *Manager) ForEachNode(fn func(n *node.Node) bool)

ForEachNode runs a function over the slice of nodes with the mutex locked, and terminates when the function returns true.

Do not call any Manager methods above inside this function or there will be a mutex double locking panic, except GetLocalNode.

func (*Manager) GetLocalNode

func (sm *Manager) GetLocalNode() *node.Node

GetLocalNode returns the engine's local Node.

func (*Manager) GetLocalNodeAddress

func (sm *Manager) GetLocalNodeAddress() (addr *netip.AddrPort)

GetLocalNodeAddress returns an Address of the local node. This is done randomly. Only addresses of the types configured in the manager (default is the same as the default gateway's interfaces. IPv4 and maybe IPv6.

func (*Manager) GetLocalNodeAddressString

func (sm *Manager) GetLocalNodeAddressString() (s string)

GetLocalNodeAddressString returns the string form of the local node address.

func (*Manager) GetLocalNodeAddresses added in v0.1.20

func (sm *Manager) GetLocalNodeAddresses() (addr []*netip.AddrPort)

GetLocalNodeAddresses returns the addresses of the local node.

func (*Manager) GetLocalNodeIdentityBytes

func (sm *Manager) GetLocalNodeIdentityBytes() (ident crypto.PubBytes)

GetLocalNodeIdentityBytes returns the public key bytes of the local node.

func (*Manager) GetLocalNodeIdentityPrv

func (sm *Manager) GetLocalNodeIdentityPrv() (ident *crypto.Prv)

GetLocalNodeIdentityPrv returns the identity private key of the local node.

func (*Manager) GetLocalNodePaymentChan

func (sm *Manager) GetLocalNodePaymentChan() payments.PayChan

GetLocalNodePaymentChan returns the engine's local Node PayChan.

func (*Manager) GetLocalNodeRelayRate

func (sm *Manager) GetLocalNodeRelayRate() (rate uint32)

GetLocalNodeRelayRate returns the relay rate for the local node.

func (*Manager) GetNodeCircuit

func (sm *Manager) GetNodeCircuit(id nonce.ID) (sce *sessions.Circuit,
	exists bool)

GetNodeCircuit gets the set of 5 sessions associated with a node with a given ID.

func (*Manager) GetSessionByIndex

func (sm *Manager) GetSessionByIndex(i int) (s *sessions.Data)

GetSessionByIndex returns the session with the given index in the main session cache.

func (*Manager) GetSessionsAtHop

func (sm *Manager) GetSessionsAtHop(hop byte) (s sessions.Sessions)

GetSessionsAtHop returns all of the sessions designated for a given hop in the circuit.

func (*Manager) IncSession

func (sm *Manager) IncSession(id crypto.PubBytes, msats lnwire.MilliSatoshi,
	sender bool, typ string)

IncSession adds an amount of mSat to the balance of a session.

func (*Manager) IterateSessionCache

func (sm *Manager) IterateSessionCache(fn func(n *node.Node,
	c *sessions.Circuit) bool)

IterateSessionCache calls a function for each entry in the CircuitCache that provides also access to the related node.

Do not call Manager methods within this function.

func (*Manager) IterateSessions

func (sm *Manager) IterateSessions(fn func(s *sessions.Data) bool)

IterateSessions calls a function for each entry in the Sessions slice.

Do not call Manager methods within this function.

func (*Manager) MatchesLocalNodeAddress added in v0.1.20

func (sm *Manager) MatchesLocalNodeAddress(ap *netip.AddrPort) (is bool)

func (*Manager) NodesLen

func (sm *Manager) NodesLen() int

NodesLen returns the length of a Nodes.

func (*Manager) ReceiveToLocalNode

func (sm *Manager) ReceiveToLocalNode() <-chan slice.Bytes

ReceiveToLocalNode returns a channel that will receive messages for the local node, that arrived from the internet.

func (*Manager) RemoveLocalNodeAddress added in v0.1.19

func (sm *Manager) RemoveLocalNodeAddress(addr *netip.AddrPort)

RemoveLocalNodeAddress removes a local node address.

func (*Manager) SelectHops

func (sm *Manager) SelectHops(hops []byte, alreadyHave sessions.Sessions,
	note string) (so sessions.Sessions)

SelectHops picks out a set of sessions to use in a circuit.

func (*Manager) SelectUnusedCircuit

func (sm *Manager) SelectUnusedCircuit() (c [5]*node.Node)

SelectUnusedCircuit accepts an array of 5 Node entries where all or some are empty and picks nodes for the remainder that do not have a hop at that position.

func (*Manager) Send

func (sm *Manager) Send(addr *netip.AddrPort, s *splice.Splice)

Send a message to a peer via their Addresses.

func (*Manager) SendFromLocalNode

func (sm *Manager) SendFromLocalNode(port uint16,
	b slice.Bytes) (e error)

SendFromLocalNode delivers a message to a local service.

func (*Manager) SendWithOneHook

func (sm *Manager) SendWithOneHook(ap []*netip.AddrPort,
	res *Data, responseHook responses.Callback, p *responses.Pending)

SendWithOneHook is used for onions with only one confirmation hook. Usually as returned from PostAcctOnion this is the last, confirmation or response layer in an onion.Skins.

func (*Manager) SetLocalNode

func (sm *Manager) SetLocalNode(n *node.Node)

SetLocalNode sets the engine's local Node.

func (*Manager) UpdateSessionCache

func (sm *Manager) UpdateSessionCache()

UpdateSessionCache reads the main Sessions cache and populates the CircuitCache where circuits are aggregated.

Jump to

Keyboard shortcuts

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