bitboxbase

package
v4.14.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2019 License: Apache-2.0 Imports: 14 Imported by: 9

README

BitBox Base Integration

The code in this directory contains the logic needed for integration of the desktop app with the BitBox Base. There are two ways to connect with a BitBox Base.

  • By connecting directly with the network address of the base
  • Automatically by mdns

The package mdns implements these two connection variants. Both variants attempt a connection with the TryMakeNewBase function, given an ip. TryMakeNewBase will attempt to create a new BitBoxBase instance with NewBitBoxBase, given a valid ip. NewBitBoxBase calls the Connect function from the rpcclient package. Here, the connection is first checked with an initial get request. Subsequently a websocket connection is spawned. A noise 'XX' three part handshake is performed through the websocket connection with the base. Once the noise handshake is done, the base checks if user verification of the noise channel's binding hash has to be done. If yes, an event is emitted containing the pairing channel hash that the user can then compare with the base. All traffic from and to the base should be noise encrypted hereafter. The websocket is then passed to a separate goroutine where it listens indefinitely and emits events when receiving data.

To orchestrate between multiple connections, the backend keeps a map of connected BitBox Bases, by mapping from a unique ID assigned to each Base on connection to their instantiation. It also creates a NewDetector and gives it function callbacks to register and deregister BitBox Bases. This detector instance listens for new BitBox Bases on the local network indefinitely. When a new one is found, it calls TryMakeNewBase, and the passed-in register callback. The callback then triggers an event letting the frontend know that a new BitBox Base is registered. The frontend then gets all the registered BitBox Bases's IDs and starts listening for events. The callback also subscribes the backend to any events that the websocket connection with the Base emits and passes these to the websocket in the handlers package.

The handler also exposes a http POST endpoint that allows for direct connection with the base. For this, it passes an ip to the backend's detector instance that then subsequently calls TryMakeNewBase.

When a detector, or bitboxbase is instantiated, a pointer to the backend's config is passed to them. This allows them to write new configurations to connect to the electrs server on the base. For this the handler exposes a 'connectelectrum' POST endpoint.

The communication between the BitBox Base and the wallet app is done with go's rpc package. Responses from rpc calls are written into data structures as defined in rpcclient.go. The rpcclient is also capable of receiving notifications. To this end a special notification byte is sent to the rpcclient's websocket and on receival triggers a corresponding rpc call.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BitBoxBase

type BitBoxBase struct {
	observable.Implementation
	// contains filtered or unexported fields
}

BitBoxBase provides the dictated bitboxbase api to communicate with the base

func NewBitBoxBase

func NewBitBoxBase(address string,
	id string,
	config *config.Config,
	bitboxBaseConfigDir string,
	onUnregister func(string),
	socksProxy socksproxy.SocksProxy) (*BitBoxBase, error)

NewBitBoxBase creates a new bitboxBase instance

func (*BitBoxBase) BackupHSMSecret

func (base *BitBoxBase) BackupHSMSecret() error

BackupHSMSecret backs up the lightning hsm_secret

func (*BitBoxBase) BackupSysconfig

func (base *BitBoxBase) BackupSysconfig() error

BackupSysconfig backs up the system config to the flashdrive

func (*BitBoxBase) BaseInfo

func (base *BitBoxBase) BaseInfo() (rpcmessages.GetBaseInfoResponse, error)

BaseInfo returns info about the Base contained in rpcmessages.GetBaseInfoResponse

func (*BitBoxBase) ChannelHash

func (base *BitBoxBase) ChannelHash() (string, bool)

ChannelHash returns the bitboxbase's rpcClient noise channel hash

func (*BitBoxBase) Close

func (base *BitBoxBase) Close()

Close implements a method to unset the bitboxBase

func (*BitBoxBase) ConnectElectrum

func (base *BitBoxBase) ConnectElectrum() error

ConnectElectrum connects to the electrs server on the base and configures the backend accordingly

func (*BitBoxBase) ConnectRPCClient

func (base *BitBoxBase) ConnectRPCClient() error

ConnectRPCClient starts the connection with the remote bitbox base middleware

func (*BitBoxBase) Deregister

func (base *BitBoxBase) Deregister() error

Deregister calls the backend's BitBoxBaseDeregister callback and sends a notification to the frontend, if bitboxbase is active. If bitboxbase is not active, an error is returned.

func (*BitBoxBase) EnableClearnetIBD

func (base *BitBoxBase) EnableClearnetIBD(toggleAction rpcmessages.ToggleSettingArgs) error

EnableClearnetIBD configures bitcoind to run over clearnet while in IBD with rpcmessages.ToggleSettingArgs Enable/Disable

func (*BitBoxBase) EnableRootLogin

func (base *BitBoxBase) EnableRootLogin(toggleAction rpcmessages.ToggleSettingArgs) error

EnableRootLogin enables/disables login via the root user/password with rpcmessages.ToggleSettingArgs Enable/Disable

func (*BitBoxBase) EnableTor

func (base *BitBoxBase) EnableTor(toggleAction rpcmessages.ToggleSettingArgs) error

EnableTor enables/disables Tor with rpcmessages.ToggleSettingArgs Enable/Disable

func (*BitBoxBase) EnableTorElectrs

func (base *BitBoxBase) EnableTorElectrs(toggleAction rpcmessages.ToggleSettingArgs) error

EnableTorElectrs enables/disables Tor for electrs with rpcmessages.ToggleSettingArgs Enable/Disable

func (*BitBoxBase) EnableTorMiddleware

func (base *BitBoxBase) EnableTorMiddleware(toggleAction rpcmessages.ToggleSettingArgs) error

EnableTorMiddleware enables/disables Tor for the middleware with rpcmessages.ToggleSettingArgs Enable/Disable

func (*BitBoxBase) EnableTorSSH

func (base *BitBoxBase) EnableTorSSH(toggleAction rpcmessages.ToggleSettingArgs) error

EnableTorSSH enables/disables Tor for SSH with rpcmessages.ToggleSettingArgs Enable/Disable

func (*BitBoxBase) GetRegisterTime

func (base *BitBoxBase) GetRegisterTime() time.Time

GetRegisterTime implements a getter for the timestamp of when the bitbox base was registered

func (*BitBoxBase) Identifier

func (base *BitBoxBase) Identifier() string

Identifier implements a getter for the bitboxBase ID

func (*BitBoxBase) MiddlewareInfo

func (base *BitBoxBase) MiddlewareInfo() (rpcmessages.SampleInfoResponse, error)

MiddlewareInfo returns the received MiddlewareInfo packet from the rpcClient

func (*BitBoxBase) Ping

func (base *BitBoxBase) Ping() (bool, error)

Ping sends a get requset to the bitbox base middleware root handler and returns true if successful

func (*BitBoxBase) RPCClient

func (base *BitBoxBase) RPCClient() *rpcclient.RPCClient

RPCClient returns ths current instance of the rpcClient

func (*BitBoxBase) RebootBase

func (base *BitBoxBase) RebootBase() error

RebootBase initiates a `reboot` call via the bbb-cmd.sh script

func (*BitBoxBase) ReindexBitcoin

func (base *BitBoxBase) ReindexBitcoin() error

ReindexBitcoin returns true if the chosen sync option was executed successfully

func (*BitBoxBase) RestoreHSMSecret

func (base *BitBoxBase) RestoreHSMSecret() error

RestoreHSMSecret restores the lightning hsm_secret

func (*BitBoxBase) RestoreSysconfig

func (base *BitBoxBase) RestoreSysconfig() error

RestoreSysconfig restores the system config from the flashdrive

func (*BitBoxBase) ResyncBitcoin

func (base *BitBoxBase) ResyncBitcoin() error

ResyncBitcoin returns true if the chosen sync option was executed successfully

func (*BitBoxBase) Self

func (base *BitBoxBase) Self() *BitBoxBase

Self returns the current bitbox base instance.

func (*BitBoxBase) ServiceInfo

func (base *BitBoxBase) ServiceInfo() (rpcmessages.GetServiceInfoResponse, error)

ServiceInfo returns info about the Base contained in rpcmessages.GetServiceInfoResponse

func (*BitBoxBase) SetHostname

func (base *BitBoxBase) SetHostname(hostname string) error

SetHostname sets the hostname of the bitboxbase

func (*BitBoxBase) SetRootPassword

func (base *BitBoxBase) SetRootPassword(password string) error

SetRootPassword sets the systems root password

func (*BitBoxBase) ShutdownBase

func (base *BitBoxBase) ShutdownBase() error

ShutdownBase initiates a `shutdown now` call via the bbb-cmd.sh script

func (*BitBoxBase) Status

func (base *BitBoxBase) Status() bitboxbasestatus.Status

Status returns the current state of the bitboxbase.

func (*BitBoxBase) UserAuthenticate

func (base *BitBoxBase) UserAuthenticate(username string, password string) error

UserAuthenticate returns if a given Username and Password are valid

func (*BitBoxBase) UserChangePassword

func (base *BitBoxBase) UserChangePassword(username string, password, newPassword string) error

UserChangePassword returns if the password change for a username was successful

func (*BitBoxBase) VerificationProgress

func (base *BitBoxBase) VerificationProgress() (rpcmessages.VerificationProgressResponse, error)

VerificationProgress returns the received VerificationProgress packet from the rpcClient

type Interface

type Interface interface {

	// Identifier returns the bitboxBaseID.
	Identifier() string

	// GetRPCClient returns the rpcClient so we can listen to its events.
	RPCClient() *rpcclient.RPCClient

	// Close tells the bitboxbase to close all connections.
	Close()

	// GetRegisterTime implements a getter for the timestamp of when the bitboxBase was registered
	GetRegisterTime() time.Time

	// MiddlewareInfo returns some blockchain information.
	MiddlewareInfo() (rpcmessages.SampleInfoResponse, error)

	// VerificationProgress returns the bitcoind verification progress.
	VerificationProgress() (rpcmessages.VerificationProgressResponse, error)

	// ConnectElectrum connects to the electrs server on the base and configures the backend accordingly
	ConnectElectrum() error

	// Ping sends a get requset to the bitbox base middleware root handler and returns true if successful
	Ping() (bool, error)

	// Self returns an instance of the base
	Self() *BitBoxBase

	// Status returns the current status of the base
	Status() bitboxbasestatus.Status

	// ChannelHash returns the hash of the noise channel
	ChannelHash() (string, bool)

	// Deregister calls the backend's BitBoxBase Deregister callback and sends a notification to the frontend, if bitboxbase is active.
	// If bitboxbase is not active, an error is returned.
	Deregister() error

	// ReindexBitcoin starts a bitcoin reindex on the base.
	ReindexBitcoin() error

	// ResyncBitcoin starts a bitcoin resync on the base.
	ResyncBitcoin() error

	// SetHostname sets the hostname of the BitBox Base
	SetHostname(string) error

	// UserChangePassword sets a new password for a given user
	UserChangePassword(string, string, string) error

	// UserAuthenticate returns is the authentication with a username and password was successful
	UserAuthenticate(string, string) error

	// BackupSysconfig backs up the system config to the flashdrive
	BackupSysconfig() error

	// BackupHSMSecret backs up the lightning hsm_secret
	BackupHSMSecret() error

	// RestoreSysconfig restores the system config from the flashdrive
	RestoreSysconfig() error

	// RestoreHSMSecret restores the lightning hsm_secret
	RestoreHSMSecret() error

	// EnableTor enables/disables Tor
	EnableTor(rpcmessages.ToggleSettingArgs) error

	// EnableTorMiddleware enables/disables Tor for the middleware
	EnableTorMiddleware(rpcmessages.ToggleSettingArgs) error

	// EnableTorElectrs enables/disables Tor for electrs
	EnableTorElectrs(rpcmessages.ToggleSettingArgs) error

	// EnableTorSSH enables/disables Tor for SSH
	EnableTorSSH(rpcmessages.ToggleSettingArgs) error

	// EnableClearnetIBD configures bitcoind to run over clearnet while in IBD
	EnableClearnetIBD(rpcmessages.ToggleSettingArgs) error

	// EnableRootLogin enables/disables login via the root user/password
	EnableRootLogin(rpcmessages.ToggleSettingArgs) error

	// SetRootPassword sets the systems root password
	SetRootPassword(string) error

	// ShutdownBase initiates a `shutdown now` call via the bbb-cmd.sh script
	ShutdownBase() error

	// RebootBase initiates a `reboot` call via the bbb-cmd.sh script
	RebootBase() error

	// BaseInfo returns information about the Base
	BaseInfo() (rpcmessages.GetBaseInfoResponse, error)

	// ServiceInfo returns information about the services running on the Base
	// As for example the bitcoind, electrs and ligthningd block height
	ServiceInfo() (rpcmessages.GetServiceInfoResponse, error)
}

Interface represents bitbox base.

type SyncOption

type SyncOption string

SyncOption is a user provided blockchain sync option during BBB initialization

const (
	SyncOptionPresynced            SyncOption = "preSynced"
	SyncOptionReindex              SyncOption = "reindex"
	SyncOptionInitialBlockDownload SyncOption = "initialBlockDownload"
)

SyncOption iota has three options: Accept pre-synchronized blockchain; delete the chainstate and reindex; resync bitcon from scratch with an IBD

Directories

Path Synopsis
Package mdns manages and/or registers new bitbox bases.
Package mdns manages and/or registers new bitbox bases.
Package rpcclient contains the API to the physical device.
Package rpcclient contains the API to the physical device.

Jump to

Keyboard shortcuts

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