policy

package
v0.2.97 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoPolicyFile error = fmt.Errorf("no policy file given")

Error definitions

Functions

This section is empty.

Types

type ErrCreatePolicy

type ErrCreatePolicy string

func (ErrCreatePolicy) Error

func (e ErrCreatePolicy) Error() string

type ErrNotAValidPublicKey

type ErrNotAValidPublicKey string

func (ErrNotAValidPublicKey) Error

func (e ErrNotAValidPublicKey) Error() string

type ErrReloadPolicy

type ErrReloadPolicy string

func (ErrReloadPolicy) Error

func (e ErrReloadPolicy) Error() string

type Policy

type Policy struct {
	ReserveOnchainMsat uint64   `` /* 200-byte string literal not displayed */
	PeerAllowlist      []string `` /* 131-byte string literal not displayed */
	SuspiciousPeerList []string `` /* 137-byte string literal not displayed */
	AcceptAllPeers     bool     `` /* 160-byte string literal not displayed */

	// MinSwapAmountMsat is the minimum swap amount in msat that is needed to
	// perform a swap. Below this amount it might be uneconomical to do a swap
	// due to the on-chain costs.
	// TODO: This can not be set in the policy by now but this is the place
	// where this value belongs. Eventually we might want to make this value
	// editable as a policy setting.
	MinSwapAmountMsat uint64 `json:"min_swap_amount_msat"`

	// AllowNewSwaps can be used to disallow any new swaps. This can be useful
	// when we want to upgrade the node and do not want to allow for any new
	// swap request from the peer or the node operator.
	AllowNewSwaps bool `json:"allow_new_swaps" long:"allow_new_swaps" description:"If set to false, disables all swap requests, defaults to true."`
	// contains filtered or unexported fields
}

PolicyConfig will ensure that a swap request is only performed if the policy is matched. In this case this means that the requesting peer is part of the allowlist and that the tank reserve is respected.

func CreateFromFile

func CreateFromFile(path string) (*Policy, error)

CreateFromFile returns a policy based on a DefaultPolicy and a ini file with a policy configuration. If the path to the policy file (ini notation) is empty, the default policy is used.

func DefaultPolicy

func DefaultPolicy() *Policy

DefaultPolicy returns a policy struct made from the default values.

func (*Policy) AddToAllowlist

func (p *Policy) AddToAllowlist(pubkey string) error

AddToAllowlist adds a peer to the policy file in runtime. The pubkey is expected to be hex encoded.

func (*Policy) AddToSuspiciousPeerList

func (p *Policy) AddToSuspiciousPeerList(pubkey string) error

AddToSuspiciousPeerList adds a peer as a suspicious peer to the policy file in runtime. The pubkey is expected to be hex encoded.

func (*Policy) DisableSwaps

func (p *Policy) DisableSwaps() error

DisableSwaps sets the AllowNewSwaps field to false. This persists in the policy.conf.

func (*Policy) EnableSwaps

func (p *Policy) EnableSwaps() error

EnableSwaps sets the AllowNewSwaps field to true. This persists in the policy.conf.

func (*Policy) Get

func (p *Policy) Get() Policy

func (*Policy) GetMinSwapAmountMsat

func (p *Policy) GetMinSwapAmountMsat() uint64

GetMinSwapAmountMsat returns the minimum swap amount in msat that is needed to perform a swap.

func (*Policy) GetReserveOnchainMsat

func (p *Policy) GetReserveOnchainMsat() uint64

GetReserveOnchainMsat returns the amount of msats that should be keept in the wallet when receiving a peerswap request.

func (*Policy) IsPeerAllowed

func (p *Policy) IsPeerAllowed(peer string) bool

IsPeerAllowed returns if a peer or node is part of the allowlist.

func (*Policy) IsPeerSuspicious

func (p *Policy) IsPeerSuspicious(peer string) bool

IsPeerSuspicious returns true if the peer is on the list of suspicious peers.

func (*Policy) NewSwapsAllowed

func (p *Policy) NewSwapsAllowed() bool

NewSwapsAllowed returns the boolean value of AllowNewSwaps.

func (*Policy) ReloadFile

func (p *Policy) ReloadFile() error

ReloadFile reloads and and sets the policy to the policy file. This might be because the policy file changed and the runtime should use the new policy.

func (*Policy) RemoveFromAllowlist

func (p *Policy) RemoveFromAllowlist(pubkey string) error

RemoveFromAllowlist removes the pubkey of a node from the policy allowlisted_peers list. If a pubkey is removed from the allowlist the node corresponding to the pubkey is no longer allowed to request swaps. The pubkey is expected to be hex encoded.

func (*Policy) RemoveFromSuspiciousPeerList

func (p *Policy) RemoveFromSuspiciousPeerList(pubkey string) error

RemoveFromSuspiciousPeerList removes the pubkey of a node from the policy suspicious_peers list. The pubkey is expected to be hex encoded.

func (*Policy) String

func (p *Policy) String() string

Jump to

Keyboard shortcuts

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