remotesync

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2019 License: GPL-3.0 Imports: 11 Imported by: 2

Documentation

Overview

Package remotesync implements a differential file synching mechanism based on the content-based chunking that is used by CAFS internally. Step 1: Sender and receiver agree on hashes of the file's chunks Step 2: Receiver streams missing chunks (one bit per chunk) Step 3: Sender responds by sending content of requested chunks

Index

Constants

This section is empty.

Variables

View Source
var ErrDisposed = errors.New("disposed")
View Source
var ErrUnexpectedChunk = errors.New("unexpected chunk")
View Source
var LoggingEnabled = false

Functions

func WriteChunkData

func WriteChunkData(chunks Chunks, bytesToTransfer int64, r io.ByteReader, perm shuffle.Permutation, w FlushWriter, cb TransferStatusCallback) error

Writes a stream of chunk length / data pairs, permuted by a shuffler corresponding to `perm`, into an io.Writer, based on the chunks of a file and a matching permuted wishlist of requested chunks, read from `r`.

Types

type Builder

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

Type Builder contains state needed for the duration of a file transmission.

func NewBuilder

func NewBuilder(storage cafs.FileStorage, syncinf *SyncInfo, windowSize int, info string) *Builder

Returns a new Builder for reconstructing a file. Must eventually be disposed. The builder can then proceed sending a "wishlist" of chunks that are missing in the local storage for complete reconstruction of the file.

func (*Builder) Dispose

func (b *Builder) Dispose()

Disposes the Builder. Must be called exactly once per Builder. May cause the goroutines running WriteWishList and ReconstructFileFromRequestedChunks to terminate with error ErrDisposed.

func (*Builder) ReconstructFileFromRequestedChunks

func (b *Builder) ReconstructFileFromRequestedChunks(_r io.Reader) (cafs.File, error)

Reads a sequence of length-prefixed data chunks and tries to reconstruct a file from that information.

func (*Builder) WriteWishList

func (b *Builder) WriteWishList(w FlushWriter) error

Outputs a bit stream with '1' for each missing chunk, and '0' for each chunk that is already available or already requested.

type ChunkInfo

type ChunkInfo struct {
	Key  cafs.SKey
	Size int
}

Type ChunkInfo contains a chunk's hash and size.

type Chunks

type Chunks interface {
	// Function NextChunk returns either of three cases:
	// - A File, nil   (good case)
	// - nil, io.EOF   (terminal case: end of stream)
	// - nil, an error (terminal case: an error occurred)
	// It is the caller's duty to call Dispose() on the file returned.
	NextChunk() (cafs.File, error)

	// Function Dispose must be called when this object is no longer used.
	Dispose()
}

Interface Chunks allows iterating over any sequence of chunks.

func ChunksOfFile

func ChunksOfFile(file cafs.File) Chunks

Function ChunksOfFiles returns the chunks of a File as an implementation of the Chunks interface. It's the caller's responsibility to call Dispose() on the returned object.

type FlushWriter

type FlushWriter interface {
	io.Writer
	Flush()
}

Interface FlushWriter acts like an io.Writer with an additional Flush method.

type NopFlushWriter

type NopFlushWriter struct {
	W io.Writer
}

An implementation of FlushWriter whose Flush() function is a nop.

func (NopFlushWriter) Flush

func (f NopFlushWriter) Flush()

func (NopFlushWriter) Write

func (f NopFlushWriter) Write(p []byte) (n int, err error)

type SimpleFlushWriter

type SimpleFlushWriter struct {
	W io.Writer
	F http.Flusher
}

Struct SimpleFlushWriter implements FlushWriter using a Writer and a Flusher.

func (SimpleFlushWriter) Flush

func (s SimpleFlushWriter) Flush()

func (SimpleFlushWriter) Write

func (s SimpleFlushWriter) Write(p []byte) (n int, err error)

type SyncInfo

type SyncInfo struct {
	Chunks []ChunkInfo         // hashes and sizes of chunks
	Perm   shuffle.Permutation // the permutation of chunks to use when transferring
}

Struct SyncInfo contains information which two CAFS instances have to agree on before transmitting a file.

func (*SyncInfo) ReadFromLegacyStream

func (s *SyncInfo) ReadFromLegacyStream(stream io.Reader) error

func ReadFromLegacyStream reads chunk hashes from a stream encoded in the format previously used. No permutation data is sent and it is expected that permutation remain the trivial permutation {0}.

func (*SyncInfo) SetChunksFromFile

func (s *SyncInfo) SetChunksFromFile(file cafs.File)

Func SetChunksFromFile prepares sync information for a CAFS file.

func (*SyncInfo) SetPermutation

func (s *SyncInfo) SetPermutation(perm shuffle.Permutation)

Func SetPermutation sets the permutation to use when transferring chunks.

func (*SyncInfo) SetTrivialPermutation

func (s *SyncInfo) SetTrivialPermutation()

Func SetNoPermutation sets the prmutation to the trivial permutation (the one that doesn't permute).

func (*SyncInfo) Shuffle

func (s *SyncInfo) Shuffle() *SyncInfo

Applies the permutation contained within the receiver to it's own list of chunks, returning a SyncInfo with a permuted list of chunks and the trivial permutation. This is interesting for assistive transfers where a file is offered for retrieval while it is still being retrieved from a different source. In that case, forwarding file chunks in a different shuffle order than the one retrieved would lead to unnecessary delays waiting for a certain chunk while others are already available.

func (*SyncInfo) WriteToLegacyStream

func (s *SyncInfo) WriteToLegacyStream(stream io.Writer) error

Func WriteToLegacyStream writes chunk hashes to a stream encoded in the format previously used.

type TransferStatusCallback

type TransferStatusCallback func(bytesToTransfer, bytesTransferred int64)

By passing a callback function to some of the transmissions functions, the caller may subscribe to the current transmission status.

Directories

Path Synopsis
Package httpsync implements methods for requesting and serving files via CAFS
Package httpsync implements methods for requesting and serving files via CAFS
Package shuffle implements an efficient algorithm for performing a cyclic permutation on a possibly infinite stream of data elements.
Package shuffle implements an efficient algorithm for performing a cyclic permutation on a possibly infinite stream of data elements.

Jump to

Keyboard shortcuts

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