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 ¶
- func StandardCircuit() []byte
- type CircuitCache
- type Data
- type Manager
- func (sm *Manager) AddLocalNodeAddress(addr *netip.AddrPort)
- func (sm *Manager) AddLocalNodeAddresses(addr []*netip.AddrPort)
- func (sm *Manager) AddNodes(nn ...*node.Node)
- func (sm *Manager) AddPendingPayment(np *payments.Payment)
- func (sm *Manager) AddServiceToLocalNode(s *services.Service) (e error)
- func (sm *Manager) AddSession(s *sessions.Data)
- func (sm *Manager) ClearPendingPayments()
- func (sm *Manager) ClearSessions()
- func (sm *Manager) DecSession(id crypto.PubBytes, msats int, sender bool, typ string) bool
- func (sm *Manager) DeleteNodeAndSessions(id nonce.ID)
- func (sm *Manager) DeleteNodeByAddrPort(ip *netip.AddrPort) (e error)
- func (sm *Manager) DeleteNodeByID(ii nonce.ID) (e error)
- func (sm *Manager) DeletePendingPayment(preimage sha256.Hash)
- func (sm *Manager) DeleteSession(id crypto.PubBytes)
- func (sm *Manager) FindCloaked(clk crypto.CloakedPubKey) (hdr *crypto.Prv, pld *crypto.Prv, sess *sessions.Data, identity bool)
- func (sm *Manager) FindNodeByAddrPort(id *netip.AddrPort) (no *node.Node)
- func (sm *Manager) FindNodeByID(i nonce.ID) (no *node.Node)
- func (sm *Manager) FindNodeByIdentity(id *crypto.Pub) (no *node.Node)
- func (sm *Manager) FindNodeByIndex(i int) (no *node.Node)
- func (sm *Manager) FindPendingPayment(id nonce.ID) (pp *payments.Payment)
- func (sm *Manager) FindPendingPreimage(pi sha256.Hash) (pp *payments.Payment)
- func (sm *Manager) FindSessionByHeader(prvKey *crypto.Prv) *sessions.Data
- func (sm *Manager) FindSessionByHeaderPub(pubKey *crypto.Pub) *sessions.Data
- func (sm *Manager) FindSessionByPubkey(id crypto.PubBytes) *sessions.Data
- func (sm *Manager) FindSessionPreimage(pr sha256.Hash) *sessions.Data
- func (sm *Manager) ForEachNode(fn func(n *node.Node) bool)
- func (sm *Manager) GetLocalNode() *node.Node
- func (sm *Manager) GetLocalNodeAddress() (addr *netip.AddrPort)
- func (sm *Manager) GetLocalNodeAddressString() (s string)
- func (sm *Manager) GetLocalNodeAddresses() (addr []*netip.AddrPort)
- func (sm *Manager) GetLocalNodeIdentityBytes() (ident crypto.PubBytes)
- func (sm *Manager) GetLocalNodeIdentityPrv() (ident *crypto.Prv)
- func (sm *Manager) GetLocalNodePaymentChan() payments.PayChan
- func (sm *Manager) GetLocalNodeRelayRate() (rate uint32)
- func (sm *Manager) GetNodeCircuit(id nonce.ID) (sce *sessions.Circuit, exists bool)
- func (sm *Manager) GetSessionByIndex(i int) (s *sessions.Data)
- func (sm *Manager) GetSessionsAtHop(hop byte) (s sessions.Sessions)
- func (sm *Manager) IncSession(id crypto.PubBytes, msats lnwire.MilliSatoshi, sender bool, typ string)
- func (sm *Manager) IterateSessionCache(fn func(n *node.Node, c *sessions.Circuit) bool)
- func (sm *Manager) IterateSessions(fn func(s *sessions.Data) bool)
- func (sm *Manager) MatchesLocalNodeAddress(ap *netip.AddrPort) (is bool)
- func (sm *Manager) NodesLen() int
- func (sm *Manager) ReceiveToLocalNode() <-chan slice.Bytes
- func (sm *Manager) RemoveLocalNodeAddress(addr *netip.AddrPort)
- func (sm *Manager) SelectHops(hops []byte, alreadyHave sessions.Sessions, note string) (so sessions.Sessions)
- func (sm *Manager) SelectUnusedCircuit() (c [5]*node.Node)
- func (sm *Manager) Send(addr *netip.AddrPort, s *splice.Splice)
- func (sm *Manager) SendFromLocalNode(port uint16, b slice.Bytes) (e error)
- func (sm *Manager) SendWithOneHook(ap []*netip.AddrPort, res *Data, responseHook responses.Callback, ...)
- func (sm *Manager) SetLocalNode(n *node.Node)
- func (sm *Manager) UpdateSessionCache()
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 ¶
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 ¶
func (sc CircuitCache) Add(s *sessions.Data) CircuitCache
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
AddLocalNodeAddress changes the local node address.
func (*Manager) AddLocalNodeAddresses ¶ added in v0.1.19
AddLocalNodeAddresses changes the local node address.
func (*Manager) AddPendingPayment ¶
AddPendingPayment adds a received incoming payment message to await the session keys.
func (*Manager) AddServiceToLocalNode ¶
AddServiceToLocalNode adds a service to the local node.
func (*Manager) AddSession ¶
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 ¶
DecSession decrements credit (mSat) on a session.
func (*Manager) DeleteNodeAndSessions ¶
DeleteNodeAndSessions deletes a node and all the sessions for it.
func (*Manager) DeleteNodeByAddrPort ¶
DeleteNodeByAddrPort deletes a node identified by a netip.AddrPort.
func (*Manager) DeleteNodeByID ¶
DeleteNodeByID deletes a node identified by an Keys.
func (*Manager) DeletePendingPayment ¶
DeletePendingPayment deletes a pending payment by the preimage hash.
func (*Manager) DeleteSession ¶
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 ¶
FindNodeByAddrPort searches for a Node by netip.AddrPort.
func (*Manager) FindNodeByID ¶
FindNodeByID searches for a Node by Keys.
func (*Manager) FindNodeByIdentity ¶
FindNodeByIdentity searches for a Node by netip.AddrPort.
func (*Manager) FindNodeByIndex ¶
FindNodeByIndex returns the node at a given position in the array.
func (*Manager) FindPendingPayment ¶
FindPendingPayment searches for a pending payment with the matching ID.
func (*Manager) FindPendingPreimage ¶
FindPendingPreimage searches for a pending payment with e matching preimage.
func (*Manager) FindSessionByHeader ¶
FindSessionByHeader searches for a session with a matching header private key.
func (*Manager) FindSessionByHeaderPub ¶
FindSessionByHeaderPub searches for a session with a matching header public key.
func (*Manager) FindSessionByPubkey ¶
FindSessionByPubkey searches for a session with a matching public key.
func (*Manager) FindSessionPreimage ¶
FindSessionPreimage searches for a session with a matching preimage hash.
func (*Manager) ForEachNode ¶
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 ¶
GetLocalNode returns the engine's local Node.
func (*Manager) GetLocalNodeAddress ¶
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 ¶
GetLocalNodeAddressString returns the string form of the local node address.
func (*Manager) GetLocalNodeAddresses ¶ added in v0.1.20
GetLocalNodeAddresses returns the addresses of the local node.
func (*Manager) GetLocalNodeIdentityBytes ¶
GetLocalNodeIdentityBytes returns the public key bytes of the local node.
func (*Manager) GetLocalNodeIdentityPrv ¶
GetLocalNodeIdentityPrv returns the identity private key of the local node.
func (*Manager) GetLocalNodePaymentChan ¶
GetLocalNodePaymentChan returns the engine's local Node PayChan.
func (*Manager) GetLocalNodeRelayRate ¶
GetLocalNodeRelayRate returns the relay rate for the local node.
func (*Manager) GetNodeCircuit ¶
GetNodeCircuit gets the set of 5 sessions associated with a node with a given ID.
func (*Manager) GetSessionByIndex ¶
GetSessionByIndex returns the session with the given index in the main session cache.
func (*Manager) GetSessionsAtHop ¶
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 ¶
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 ¶
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 (*Manager) ReceiveToLocalNode ¶
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
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 ¶
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) SendFromLocalNode ¶
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 ¶
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.