Documentation ¶
Index ¶
- Variables
- func RegisterProvider(providerName string, factory ProviderFactory)
- type AuthService
- type BackupInfo
- type BackupRequest
- type DataPreparer
- type Error
- type FileInfo
- type FileProp
- type FilePropStats
- type GoogleDriveProvider
- func (p *GoogleDriveProvider) AvailableSnapshots() ([]SnapshotInfo, error)
- func (p *GoogleDriveProvider) DownloadBackupFiles(nodeID, backupID string) ([]string, error)
- func (p *GoogleDriveProvider) GetProviderTimestamp(nodeID string) (time.Time, error)
- func (p *GoogleDriveProvider) SetTor(torConfig *tor.TorConfig)
- func (p *GoogleDriveProvider) TestAuth() error
- func (p *GoogleDriveProvider) UploadBackupFiles(file string, nodeID string, encryptionType string, timestamp time.Time) (string, error)
- type ListFileResponse
- type Manager
- func (b *Manager) AvailableSnapshots() ([]SnapshotInfo, error)
- func (b *Manager) Download(nodeID string) ([]string, error)
- func (b *Manager) EnsureLatestBackup(nodeID string) (bool, error)
- func (b *Manager) GetProvider() Provider
- func (b *Manager) IsSafeToRunNode(nodeID string) (bool, error)
- func (b *Manager) LatestBackupTime() (time.Time, error)
- func (b *Manager) RequestAppDataBackup()
- func (b *Manager) RequestCommitmentChangedBackup()
- func (b *Manager) RequestFullBackup()
- func (b *Manager) RequestNodeBackup()
- func (b *Manager) Restore(nodeID string, key []byte) ([]string, error)
- func (b *Manager) SetBackupProvider(providerName, authData string) error
- func (b *Manager) SetEncryptionKey(encKey []byte, encryptionType string) error
- func (b *Manager) SetLatestBackupTime(time time.Time, nodeID string) error
- func (b *Manager) SetProvider(p Provider)
- func (b *Manager) SetTorConfig(torConfig *tor.TorConfig)
- func (b *Manager) Start() error
- func (b *Manager) Stop() error
- func (b *Manager) UpdateLatestBackupTime(nodeID string) error
- type Provider
- type ProviderData
- type ProviderError
- type ProviderFactory
- type ProviderFactoryInfo
- type RemoteServerProvider
- func (n *RemoteServerProvider) AvailableSnapshots() ([]SnapshotInfo, error)
- func (n *RemoteServerProvider) DownloadBackupFiles(nodeID, backupID string) ([]string, error)
- func (n *RemoteServerProvider) GetProviderTimestamp(nodeID string) (time.Time, error)
- func (n *RemoteServerProvider) SetTor(torConfig *tor.TorConfig)
- func (n *RemoteServerProvider) TestAuth() (err error)
- func (n *RemoteServerProvider) UploadBackupFiles(file string, nodeID string, encryptionType string, timestamp time.Time) (string, error)
- type Service
- type SnapshotInfo
- type TokenSource
- type WebdavClient
- func (c *WebdavClient) Delete(path string) error
- func (c *WebdavClient) DirectoryExists(path string) bool
- func (c *WebdavClient) Download(path string) ([]byte, error)
- func (c *WebdavClient) ListDir(path string) (*ListFileResponse, error)
- func (c *WebdavClient) Mkdir(path string) error
- func (c *WebdavClient) Upload(src []byte, dest string) error
- type WebdavRequestError
Constants ¶
This section is empty.
Variables ¶
var (
ErrorNoProvider = errors.New("Provider is not set")
)
Functions ¶
func RegisterProvider ¶
func RegisterProvider(providerName string, factory ProviderFactory)
RegisterProvider registers a backup provider with a unique name
Types ¶
type AuthService ¶
AuthService is the interface that the backup provider needs in order to function. Because the authentication can be in many forms (also multiple platforms) it can't be implemented as part of the backup provider but rather should be passed from the running app/platform. For example in Android the authentication would be done by using the AccountManager API.
type BackupInfo ¶
type BackupInfo struct { BackupDir string Info *SnapshotInfo }
type BackupRequest ¶
type DataPreparer ¶
DataPreparer should be responsible to prepare the data needed to be backed up. The data contains the file paths and the nodeID.
type Error ¶
type Error struct { // Exception contains the type of the exception returned by // the server. Exception string `xml:"exception"` // Message contains the error message string from the server. Message string `xml:"message"` }
Error type encapsulates the returned error messages from the server.
type FileInfo ¶
type FileInfo struct { XMLName xml.Name `xml:"response"` Href string `xml:"href"` Path string Stat FilePropStats `xml:"propstat"` }
type FilePropStats ¶
type GoogleDriveProvider ¶
type GoogleDriveProvider struct {
// contains filtered or unexported fields
}
GoogleDriveProvider is an implementation of backup.Provider interface. It uses app data in google drive as a storage mechanism. Backups are stored in the following manner:
- Nodes backup will be saved directly under "appDataFolder", which is the user data directory in google drive. Folders will be named by the convention: "snapshot-<node_id>".
- When a request for backup lands, this provider will do the following: 2.1 Create a nested folder under the node folder. 2.2 Save all the backup files under this created folder. 2.3 Update the "activeBackupFolderProperty" metadata property of the node folder to be the newly created folder id. 2.4 Delete stale backup folder that are not in use anymore for this node id.
- When a request for restore (download) lands, this provider will do the following: 3.1 Identify the "active backup folder" by reading the metadata property of the node folder. 3.2 Download the files 3.3 Mark this backup as "restored by this instance" by assign the value "backupID" to the node metadata property "backupIDProperty". This value will be used to detect the problematic case where two nodes are running the same backup...
func NewGoogleDriveProvider ¶
func NewGoogleDriveProvider(authService AuthService, log btclog.Logger) (*GoogleDriveProvider, error)
NewGoogleDriveProvider creates a new instance of GoogleDriveProvider. It needs AuthService that will provide the access token, and refresh access token functionality It implements the backup.Provider interface by using google drive as storage.
func (*GoogleDriveProvider) AvailableSnapshots ¶
func (p *GoogleDriveProvider) AvailableSnapshots() ([]SnapshotInfo, error)
AvailableSnapshots fetches all existing backup snapshots that exist in the user app data. There is only one snapshot per node id.
func (*GoogleDriveProvider) DownloadBackupFiles ¶
func (p *GoogleDriveProvider) DownloadBackupFiles(nodeID, backupID string) ([]string, error)
DownloadBackupFiles is responsible for download a specific node backup and updating. that this backup was now restored by this instance represented by "backupID"
func (*GoogleDriveProvider) GetProviderTimestamp ¶
func (p *GoogleDriveProvider) GetProviderTimestamp(nodeID string) (time.Time, error)
GetProviderTimestamp edits the timestamp metadata for the given node's file and returns a time if successfull.
func (*GoogleDriveProvider) SetTor ¶
func (p *GoogleDriveProvider) SetTor(torConfig *tor.TorConfig)
func (*GoogleDriveProvider) TestAuth ¶
func (p *GoogleDriveProvider) TestAuth() error
func (*GoogleDriveProvider) UploadBackupFiles ¶
func (p *GoogleDriveProvider) UploadBackupFiles(file string, nodeID string, encryptionType string, timestamp time.Time) (string, error)
UploadBackupFiles uploads the backup files related to a specific node to google drive. It does the following:
- Creates a fresh new folder under the node folder.
- Uploads all files to the newly created folder.
- update the node folder metadata property "activeBackupFolderProperty" to contain the id of the new folder.
type ListFileResponse ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager holds the data needed for the backup to execute its work.
func NewManager ¶
func NewManager( providerName string, authService AuthService, onServiceEvent func(event data.NotificationEvent), prepareData DataPreparer, config *config.Config, log btclog.Logger) (*Manager, error)
NewManager creates a new Manager
func (*Manager) AvailableSnapshots ¶
func (b *Manager) AvailableSnapshots() ([]SnapshotInfo, error)
AvailableSnapshots returns a list of snsapshot that the backup provider reports it has. Every snapshot is for a specific node id.
func (*Manager) Download ¶
Download handles all the download process: 1. Downloading the backed up files for a specific node id.
func (*Manager) EnsureLatestBackup ¶
EnsureLatestBackup checks whenever a given local state is newer than our snapshot. if there is no local state, it returns true.
func (*Manager) GetProvider ¶
func (*Manager) IsSafeToRunNode ¶
IsSafeToRunNode checks if it is safe for this breez instance to run a specific node. It is considered safe if we don't know of another instance which is the last to restore this node (nodeID)
func (*Manager) LatestBackupTime ¶
LatestBackupInfo returns the latest backup time which is saved locally. If the file does not exist, it returns the zero time and an error.
func (*Manager) RequestAppDataBackup ¶
func (b *Manager) RequestAppDataBackup()
func (*Manager) RequestCommitmentChangedBackup ¶
func (b *Manager) RequestCommitmentChangedBackup()
RequestCommitmentChangedBackup is called when the commitment transaction of the channel is changed. We add a small delay because we know such changes are coming in batch
func (*Manager) RequestFullBackup ¶
func (b *Manager) RequestFullBackup()
func (*Manager) RequestNodeBackup ¶
func (b *Manager) RequestNodeBackup()
RequestBackup push a request for the backup files of breez
func (*Manager) Restore ¶
Restore handles all the restoring process: 1. Downloading the backed up files for a specific node id. 2. Put the backed up files in the right place according to the configuration
func (*Manager) SetBackupProvider ¶
func (*Manager) SetEncryptionKey ¶
SetEncryptionKey sets the key which should be used to encrypt the backup files
func (*Manager) SetLatestBackupTime ¶
SetLatestBackupTime takes two pararms time.Time, nodeID and saves it locally. If the file already exists it overwrite it.
func (*Manager) SetProvider ¶
func (*Manager) SetTorConfig ¶
func (*Manager) Start ¶
Start is the main go routine that listens to backup requests and is resopnsible for executing it.
func (*Manager) UpdateLatestBackupTime ¶
type Provider ¶
type Provider interface { UploadBackupFiles(file string, nodeID string, encryptionType string, timestamp time.Time) (string, error) AvailableSnapshots() ([]SnapshotInfo, error) DownloadBackupFiles(nodeID, backupID string) ([]string, error) SetTor(t *tor.TorConfig) GetProviderTimestamp(nodeID string) (time.Time, error) TestAuth() error }
Provider represents the functionality needed to be implemented for any backend backup storage provider. This provider will be used and inststiated by the service.
type ProviderData ¶
type ProviderError ¶
ProviderError is the error that is used by the Provider to tell the BackupService about the error happened and if there was an error in the authentication.
type ProviderFactory ¶
type ProviderFactory func(providerFactoryInfo ProviderFactoryInfo) (Provider, error)
ProviderFactory is a factory for create a specific provider. This is the function needed to be implemented for a new provider to be registered and used.
type ProviderFactoryInfo ¶
type ProviderFactoryInfo struct {
// contains filtered or unexported fields
}
type RemoteServerProvider ¶
type RemoteServerProvider struct {
// contains filtered or unexported fields
}
func NewRemoteServerProvider ¶
func NewRemoteServerProvider( authData ProviderData, log btclog.Logger, torConfig *tor.TorConfig, ) (*RemoteServerProvider, error)
func (*RemoteServerProvider) AvailableSnapshots ¶
func (n *RemoteServerProvider) AvailableSnapshots() ([]SnapshotInfo, error)
func (*RemoteServerProvider) DownloadBackupFiles ¶
func (n *RemoteServerProvider) DownloadBackupFiles(nodeID, backupID string) ([]string, error)
func (*RemoteServerProvider) GetProviderTimestamp ¶
func (n *RemoteServerProvider) GetProviderTimestamp(nodeID string) (time.Time, error)
Upload a mock file to the breez server in order to be able to use the timestamp for the backup.
func (*RemoteServerProvider) SetTor ¶
func (n *RemoteServerProvider) SetTor(torConfig *tor.TorConfig)
func (*RemoteServerProvider) TestAuth ¶
func (n *RemoteServerProvider) TestAuth() (err error)
func (*RemoteServerProvider) UploadBackupFiles ¶
type Service ¶
type Service interface { RequestBackup() Restore(nodeID string) error AvailableSnapshots() ([]SnapshotInfo, error) }
Service is the interface to expose from this package as Backup Service API. These functions will be used from the application layer.
type SnapshotInfo ¶
type SnapshotInfo struct { NodeID string BackupID string Encrypted bool EncryptionType string ModifiedTime time.Time }
SnapshotInfo is an existing backup information for a specific node id.
type TokenSource ¶
type TokenSource struct {
// contains filtered or unexported fields
}
TokenSource is a structure that implements the auth2.TokenSource interface to be used by GoogleDriveBackupProvider
type WebdavClient ¶
A client represents a client connection to a {own|next}cloud
func Dial ¶
func Dial(host, username, password string) (*WebdavClient, error)
Dial connects to an {own|next}Cloud instance at the specified address using the given credentials.
func (*WebdavClient) Delete ¶
func (c *WebdavClient) Delete(path string) error
Delete removes the specified folder from the cloud.
func (*WebdavClient) DirectoryExists ¶
func (c *WebdavClient) DirectoryExists(path string) bool
func (*WebdavClient) Download ¶
func (c *WebdavClient) Download(path string) ([]byte, error)
Download downloads a file from the specified path.
func (*WebdavClient) ListDir ¶
func (c *WebdavClient) ListDir(path string) (*ListFileResponse, error)
func (*WebdavClient) Mkdir ¶
func (c *WebdavClient) Mkdir(path string) error
Mkdir creates a new directory on the cloud with the specified name.
type WebdavRequestError ¶
type WebdavRequestError struct {
StatusCode int
}
func (*WebdavRequestError) Error ¶
func (m *WebdavRequestError) Error() string