github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/synchronization/endpoint.go (about) 1 package synchronization 2 3 import ( 4 "context" 5 6 "github.com/mutagen-io/mutagen/pkg/synchronization/core" 7 "github.com/mutagen-io/mutagen/pkg/synchronization/rsync" 8 ) 9 10 // Endpoint defines the interface to which synchronization endpoints must 11 // adhere for a single session. It provides all primitives necessary to support 12 // synchronization. None of its methods should be considered safe for concurrent 13 // invocation except Shutdown. If any method returns an error, the endpoint 14 // should be considered failed and no more of its methods (other than Shutdown) 15 // should be invoked. 16 type Endpoint interface { 17 // Poll performs a one-shot polling operation for filesystem modifications 18 // in the endpoint's root. It blocks until either an event occurs, the 19 // provided context is cancelled, or an error occurs. In the first two cases 20 // it returns nil and in the latter case it returns the error that occurred. 21 Poll(ctx context.Context) error 22 23 // Scan performs a scan of the endpoint's synchronization root. If a non-nil 24 // ancestor is passed, then it will be used as a baseline for a deltified 25 // snapshot transfer if the endpoint is remote. The ancestor may be nil, in 26 // which case the transfer of the initial snapshot may be less than optimal. 27 // The full parameter forces the function to perform a full (but still warm) 28 // scan, avoiding any acceleration that might be available on the endpoint. 29 // The function returns the scan result, any error that occurred while 30 // trying to perform the scan, and a boolean indicating whether or not to 31 // re-try the scan if an error occurred. Any non-fatal problems encountered 32 // during the scan can be extracted from the resulting content. 33 Scan(ctx context.Context, ancestor *core.Entry, full bool) (*core.Snapshot, error, bool) 34 35 // Stage performs file staging on the endpoint. It accepts a list of file 36 // paths and a separate list of desired digests corresponding to those 37 // paths. If these lists do not have the same length, then this method must 38 // return an error. For optimal performance, the paths should be passed in 39 // depth-first traversal order. This method will filter the list of required 40 // paths based on what is already available from previously interrupted 41 // staging operations and what can be staged directly from the endpoint 42 // filesystem (e.g. in cases of renames and copies), and then return a list 43 // of paths, their respective signatures, and a receiver to receive them. 44 // The returned path list must maintain the relative order of elements from 45 // the original list and must be a subset of that list. If the filtered list 46 // of paths is empty (and the error non-nil), then all paths were either 47 // already staged or able to be staged from the endpoint filesystem, and the 48 // receiver must be nil. Otherwise, the receiver must be non-nil and must be 49 // finalized (i.e. transmitted to) before subsequent methods can be invoked 50 // on the endpoint. This method is allowed to modify the provided argument 51 // slices. If the returned receiver fails, the endpoint should be considered 52 // tainted and not used (though shutdown can and should still be invoked). 53 Stage(paths []string, digests [][]byte) ([]string, []*rsync.Signature, rsync.Receiver, error) 54 55 // Supply transmits files in a streaming fashion using the rsync algorithm 56 // to the specified receiver. 57 Supply(paths []string, signatures []*rsync.Signature, receiver rsync.Receiver) error 58 59 // Transition performs the specified transitions on the endpoint. It returns 60 // the respective results of the specified change operations, a list of 61 // non-fatal problems encountered during the transition operation, a boolean 62 // indicating whether or not the endpoint was missing staged files, and any 63 // error occurred while trying to perform the transition operation. 64 // TODO: Should we consider pre-emptability for transition? It could 65 // probably be done by just checking for cancellation during each transition 66 // path and reporting "cancelled" for problems arising after that, but 67 // usually the long-blocking transitions are going to be the ones where 68 // we're creating the root with a huge number of files and wouldn't catch 69 // cancellation until they're all done anyway. 70 Transition(ctx context.Context, transitions []*core.Change) ([]*core.Entry, []*core.Problem, bool, error) 71 72 // Shutdown terminates any resources associated with the endpoint. For local 73 // endpoints, Shutdown will not preempt calls, but for remote endpoints it 74 // will because it closes the underlying connection to the endpoint 75 // (actually, it terminates that connection). Shutdown can safely be called 76 // concurrently with other methods, though it's only recommended when you 77 // don't want the possibility of preempting the method (e.g. in Transition) 78 // or you know that the operation can continue and terminate on its own 79 // (e.g. in Scan). Shutdown should only be invoked once. 80 Shutdown() error 81 }