xrpl

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2019 License: Apache-2.0 Imports: 18 Imported by: 2

README

xrpl go module

WARNING: this is unstable and the API is likely to change, use at your own risk

GoDoc

Initially this module/package is simply to support some admin tooling for running XRPL nodes and validating nodes.

see: rbh - rippled ban hammer

Documentation

Index

Constants

View Source
const (
	Good     = "good"    // our defintiion
	Old      = "old"     // our definition
	Unstable = "unknown" // from the ledger data
	Insane   = "insane"  // from the ledger data
)

These constants define the stability nature of an XRPL peer

Variables

View Source
var DefaultStabilityChecker = &PeerList{}

DefaultStabilityChecker is the packages own opintionated check function for use with a peers StableWith method.

View Source
var MinVersion = semver.Must(semver.NewVersion("1.2.4"))

MinVersion is another opinion but it can be set at runtime...

Functions

This section is empty.

Types

type Command

type Command struct {
	Command       string `json:"command"`
	AdminUser     string `json:"admin_user,omitempty"`
	AdminPassword string `json:"admin_password,omitempty"`
}

Command is a rippled admin command

func (*Command) JSON

func (c *Command) JSON() []byte

JSON implements the RPCCommand interface in admin commands

func (*Command) Name

func (c *Command) Name() string

Name returns the commands string name e.g. "peers"

type Node

type Node struct {
	Addr string
	Port string
	// contains filtered or unexported fields
}

Node is an XRPL proxy or validator node

func NewNode

func NewNode(addr, port string, tls bool) *Node

NewNode creates a new XRPL node representation

func (*Node) DoCommand

func (n *Node) DoCommand(cmd RPCCommand) *WsMessage

DoCommand runs a single command

func (*Node) RepeatCommand

func (n *Node) RepeatCommand(ctx context.Context, cmd RPCCommand, repeat int) chan *WsMessage

RepeatCommand dials the ws/wss RPC endpoint for admin commands then repeats a command periodically

type Peer

type Peer struct {
	Address         string `json:"address"`
	CompleteLedgers string `json:"complete_ledgers,omitempty"`
	Inbound         bool   `json:"inbound,omitempty"`
	Latency         int    `json:"latency"`
	Ledger          string `json:"ledger,omitempty"`
	Load            int    `json:"load"`
	PublicKey       string `json:"public_key"`
	Uptime          int    `json:"uptime"`
	Version         string `json:"version"`
	Sanity          string `json:"sanity,omitempty"`
	Cluster         bool   `json:"cluster,omitempty"`
}

Peer defines a validator/stock peer node

func (Peer) IP

func (p Peer) IP() net.IP

IP returns the network IP address of the peer

func (*Peer) SemVer

func (p *Peer) SemVer() (*semver.Version, error)

SemVer returns the semantic version of the node software, if the version string is unrecognised e.g. not 'rippled-x.x.x' it returns a nil version and error

func (*Peer) StableWith

func (p *Peer) StableWith(checker StabilityChecker) bool

StableWith checks the stability of a node with a StabilityChecker

func (*Peer) TooOld added in v0.0.6

func (p *Peer) TooOld() bool

TooOld reports if the version is too far behind opinionated acceptence

type PeerCommand

type PeerCommand struct {
	*Command
}

PeerCommand is a "peers" rpc admin command

func NewPeerCommand

func NewPeerCommand() *PeerCommand

NewPeerCommand creates a new "peers" command

type PeerList

type PeerList struct {
	Result struct {
		Peers  []*Peer `json:"peers"`
		Status string  `json:"status"`
	} `json:"result"`
}

PeerList represents the output from the 'peers' admin commnad

func UnmarshalPeers

func UnmarshalPeers(peerList string) (*PeerList, error)

UnmarshalPeers is a convenience function to marshal a JSON peer list into a *PeerList

func (*PeerList) Anonymise

func (pl *PeerList) Anonymise()

Anonymise (randomise) the IP's of a peerlist - for testing / CI purposes... public keys are obviously in the public domain but lets be polite about the IP's

func (*PeerList) Check

func (pl *PeerList) Check(p *Peer) bool

Check is an opinionated view of the peers stability based on the reported sanity field, the version and the connected uptime. This checker returns true only if the peer is sane, is a recent version of rippled, and has been connected long enough to decide on it's sanity.

func (*PeerList) Peers

func (pl *PeerList) Peers() []*Peer

Peers returns the list of conntected peers in the peer list

func (*PeerList) Stable

func (pl *PeerList) Stable() []*Peer

Stable returns a list of peers that are not reporting unknown or insane values. If you need to examine the state further you can use custom stability rules using the Peer.StableWith() method

func (*PeerList) Unstable

func (pl *PeerList) Unstable() []*Peer

Unstable returns unkown or insane peers, typically you would want to further check individual peers for uptime and/or old rippled versions before you take action. You can use the Peer.StableWith() method to test the peer further.

type RPCCommand

type RPCCommand interface {
	JSON() []byte
}

RPCCommand defines commands that can be sent to the nodes

type StabilityChecker

type StabilityChecker interface {
	Check(peer *Peer) bool
}

StabilityChecker is the interface that a peer can consumer to check the stability of a peer against some custom rules.

type Toml added in v0.0.8

type Toml struct {
	METADATA   *TomlMetadata
	VALIDATORS []*TomlValidator
	PRINCIPLES []*TomlPrinciple
	SERVERS    []*TomlServer
}

Toml is a representation of /.well-known/srp-ledger.toml

func (*Toml) Encode added in v0.0.8

func (t *Toml) Encode(w io.Writer) error

Encode writes the toml to the io.Writer provided

type TomlMetadata added in v0.0.8

type TomlMetadata struct {
	Modified string
}

TomlMetadata represents the [[METADATA]] entry

type TomlPrinciple added in v0.0.8

type TomlPrinciple struct {
	Name string
	// contains filtered or unexported fields
}

TomlPrinciple represents an dentry in the [[PRINCIPLES]] toml list

type TomlServer added in v0.0.8

type TomlServer struct {
	Peer    string
	Network string
	Port    int
}

TomlServer represents an dentry in the [[SERVERS]] toml list

type TomlValidator added in v0.0.8

type TomlValidator struct {
	PubKey        string
	Network       string
	OwnerCountry  string
	ServerCountry string
	UNL           string
}

TomlValidator represents an entry in the [[VALIDATORS]] toml list

type WsMessage

type WsMessage struct {
	MsgType int
	Msg     []byte
	Err     error
}

WsMessage encapsulates a websocket txt/binary message

Jump to

Keyboard shortcuts

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