sync

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AutoForgetCheckInterval = time.Hour
	AutoForgetWaitInterval  = 24 * time.Hour
)
View Source
const (
	RetryInterval   = 1 * time.Second
	RetryCount      = 60
	LargeRetryCount = 10 * 60

	PeriodicRefreshIntervalInSeconds = 2

	TmpFileSuffix = ".tmp"
)
View Source
const (
	DownloadBufferSize = 1 << 12
)
View Source
const (
	MockFileSize = 4096
)

Variables

This section is empty.

Functions

func IdleTimeoutCopy

func IdleTimeoutCopy(ctx context.Context, cancel context.CancelFunc, src io.ReadCloser, dst io.WriteSeeker, updater ProgressUpdater) (copied int64, err error)

IdleTimeoutCopy relies on ctx of the reader/src or a separate timer to interrupt the processing.

func NewDownloadHttpClient added in v1.5.4

func NewDownloadHttpClient() http.Client

func NewRouter

func NewRouter(service *Service) *mux.Router

NewRouter creates and configures a mux router

func NewServer

func NewServer(parentCtx context.Context, listenAddr string, handler Handler) error

func RequestBackingImageSending

func RequestBackingImageSending(filePath, receiverAddress string) error

Types

type HTTPHandler

type HTTPHandler struct{}

func (*HTTPHandler) DownloadFromURL

func (h *HTTPHandler) DownloadFromURL(ctx context.Context, url, filePath string, updater ProgressUpdater) (written int64, err error)

func (*HTTPHandler) GetSizeFromURL

func (h *HTTPHandler) GetSizeFromURL(url string) (size int64, err error)

type Handler

type Handler interface {
	GetSizeFromURL(url string) (fileSize int64, err error)
	DownloadFromURL(ctx context.Context, url, filePath string, updater ProgressUpdater) (written int64, err error)
}

type MockHandler

type MockHandler struct{}

func (*MockHandler) DownloadFromURL

func (mh *MockHandler) DownloadFromURL(ctx context.Context, url, filePath string, updater ProgressUpdater) (written int64, err error)

func (*MockHandler) GetSizeFromURL

func (mh *MockHandler) GetSizeFromURL(url string) (fileSize int64, err error)

type ProgressUpdater

type ProgressUpdater interface {
	UpdateProgress(size int64)
}

type Sender

type Sender func(string, string) error

type Service

type Service struct {
	// contains filtered or unexported fields
}

func InitService

func InitService(ctx context.Context, listenAddr string, handler Handler) (*Service, error)

func (*Service) Delete

func (s *Service) Delete(writer http.ResponseWriter, request *http.Request)

func (*Service) DownloadFromURL

func (s *Service) DownloadFromURL(writer http.ResponseWriter, request *http.Request)

func (*Service) DownloadToDst

func (s *Service) DownloadToDst(writer http.ResponseWriter, request *http.Request)

func (*Service) Fetch

func (s *Service) Fetch(writer http.ResponseWriter, request *http.Request)

func (*Service) Forget

func (s *Service) Forget(writer http.ResponseWriter, request *http.Request)

Forget should be invoked by the caller when the file syncing is done

func (*Service) Get

func (s *Service) Get(writer http.ResponseWriter, request *http.Request)

func (*Service) List

func (s *Service) List(writer http.ResponseWriter, request *http.Request)

func (*Service) ReceiveFromPeer

func (s *Service) ReceiveFromPeer(writer http.ResponseWriter, request *http.Request)

func (*Service) RestoreFromBackupURL added in v1.6.0

func (s *Service) RestoreFromBackupURL(writer http.ResponseWriter, request *http.Request)

func (*Service) SendToPeer

func (s *Service) SendToPeer(writer http.ResponseWriter, request *http.Request)

func (*Service) UploadFromRequest

func (s *Service) UploadFromRequest(writer http.ResponseWriter, request *http.Request)

type SyncingFile

type SyncingFile struct {
	// contains filtered or unexported fields
}

func NewSyncingFile

func NewSyncingFile(parentCtx context.Context, filePath, uuid, diskUUID, expectedChecksum string, size int64, handler Handler) *SyncingFile

func (*SyncingFile) Delete

func (sf *SyncingFile) Delete()

func (*SyncingFile) DownloadFromURL

func (sf *SyncingFile) DownloadFromURL(url string) (written int64, err error)

func (*SyncingFile) Fetch

func (sf *SyncingFile) Fetch(srcFilePath string) (err error)

func (*SyncingFile) Get

func (sf *SyncingFile) Get() api.FileInfo

func (*SyncingFile) GetFileReader

func (sf *SyncingFile) GetFileReader() (io.ReadCloser, error)

func (*SyncingFile) IdleTimeoutCopyToFile

func (sf *SyncingFile) IdleTimeoutCopyToFile(src io.ReadCloser) (copied int64, err error)

func (*SyncingFile) Receive

func (sf *SyncingFile) Receive(port int, fileType string) (err error)

func (*SyncingFile) RestoreFromBackupURL added in v1.6.0

func (sf *SyncingFile) RestoreFromBackupURL(backupURL string, credential map[string]string, concurrentLimit int) (err error)

func (*SyncingFile) Send

func (sf *SyncingFile) Send(toAddress string, sender Sender) (err error)

func (*SyncingFile) UpdateProgress

func (sf *SyncingFile) UpdateProgress(processedSize int64)

func (*SyncingFile) UpdateRestoreProgress added in v1.6.0

func (sf *SyncingFile) UpdateRestoreProgress(processedSize int, err error)

func (*SyncingFile) UpdateSyncFileProgress

func (sf *SyncingFile) UpdateSyncFileProgress(size int64)

func (*SyncingFile) WaitForStateNonPending

func (sf *SyncingFile) WaitForStateNonPending() error

Jump to

Keyboard shortcuts

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