github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/api/models/synchronization/endpoint.go (about)

     1  package synchronization
     2  
     3  import (
     4  	"github.com/mutagen-io/mutagen/pkg/synchronization"
     5  	"github.com/mutagen-io/mutagen/pkg/url"
     6  )
     7  
     8  // Endpoint represents a synchronization endpoint.
     9  type Endpoint struct {
    10  	// Protocol endpoint transport protocol.
    11  	Protocol url.Protocol `json:"protocol"`
    12  	// User is the endpoint user.
    13  	User string `json:"user,omitempty"`
    14  	// Host is the endpoint host.
    15  	Host string `json:"host,omitempty"`
    16  	// Port is the endpoint port.
    17  	Port uint16 `json:"port,omitempty"`
    18  	// Path is the synchronization root on the endpoint.
    19  	Path string `json:"path"`
    20  	// Environment is the environment variable map to use for the transport.
    21  	Environment map[string]string `json:"environment,omitempty"`
    22  	// Parameters is the parameter map to use for the transport.
    23  	Parameters map[string]string `json:"parameters,omitempty"`
    24  	// Configuration is the endpoint-specific configuration.
    25  	Configuration
    26  	// Connected indicates whether or not the controller is currently connected
    27  	// to the endpoint.
    28  	Connected bool `json:"connected"`
    29  	// EndpointState stores state fields relevant to connected endpoints. It is
    30  	// non-nil if and only if the endpoint is connected.
    31  	*EndpointState
    32  }
    33  
    34  // EndpointState encodes the current state of a synchronization endpoint.
    35  type EndpointState struct {
    36  	// Scanned indicates whether or not at least one scan has been performed on
    37  	// the endpoint.
    38  	Scanned bool `json:"scanned"`
    39  	// Directories is the number of synchronizable directory entries contained
    40  	// in the last snapshot from the endpoint.
    41  	Directories uint64 `json:"directories,omitempty"`
    42  	// Files is the number of synchronizable file entries contained in the last
    43  	// snapshot from the endpoint.
    44  	Files uint64 `json:"files,omitempty"`
    45  	// SymbolicLinks is the number of synchronizable symbolic link entries
    46  	// contained in the last snapshot from the endpoint.
    47  	SymbolicLinks uint64 `json:"symbolicLinks,omitempty"`
    48  	// TotalFileSize is the total size of all synchronizable files referenced by
    49  	// the last snapshot from the endpoint.
    50  	TotalFileSize uint64 `json:"totalFileSize,omitempty"`
    51  	// ScanProblems is the list of non-terminal problems encountered during the
    52  	// last scanning operation on the endpoint. This list may be a truncated
    53  	// version of the full list if too many problems are encountered to report
    54  	// via the API, in which case ExcludedScanProblems will be non-zero.
    55  	ScanProblems []Problem `json:"scanProblems,omitempty"`
    56  	// ExcludedScanProblems is the number of problems that have been excluded
    57  	// from ScanProblems due to truncation. This value can be non-zero only if
    58  	// ScanProblems is non-empty.
    59  	ExcludedScanProblems uint64 `json:"excludedScanProblems,omitempty"`
    60  	// TransitionProblems is the list of non-terminal problems encountered
    61  	// during the last transition operation on the endpoint. This list may be a
    62  	// truncated version of the full list if too many problems are encountered
    63  	// to report via the API, in which case ExcludedTransitionProblems will be
    64  	// non-zero.
    65  	TransitionProblems []Problem `json:"transitionProblems,omitempty"`
    66  	// ExcludedTransitionProblems is the number of problems that have been
    67  	// excluded from TransitionProblems due to truncation. This value can be
    68  	// non-zero only if TransitionProblems is non-empty.
    69  	ExcludedTransitionProblems uint64 `json:"excludedTransitionProblems,omitempty"`
    70  	// StagingProgress is the rsync staging progress. It is non-nil if and only
    71  	// if the endpoint is currently staging files.
    72  	StagingProgress *ReceiverState `json:"stagingProgress,omitempty"`
    73  }
    74  
    75  // loadFromInternal sets an Endpoint to match internal Protocol Buffers
    76  // representations. All parameters must be valid.
    77  func (e *Endpoint) loadFromInternal(url *url.URL, configuration *synchronization.Configuration, state *synchronization.EndpointState) {
    78  	// Propagate URL parameters.
    79  	e.Protocol = url.Protocol
    80  	e.User = url.User
    81  	e.Host = url.Host
    82  	e.Port = uint16(url.Port)
    83  	e.Path = url.Path
    84  	e.Environment = url.Environment
    85  	e.Parameters = url.Parameters
    86  
    87  	// Propagate configuration.
    88  	e.Configuration.loadFromInternal(configuration)
    89  
    90  	// Propagate connectivity.
    91  	e.Connected = state.Connected
    92  
    93  	// Propagate other state fields.
    94  	if !e.Connected {
    95  		e.EndpointState = nil
    96  	} else {
    97  		e.EndpointState = &EndpointState{
    98  			Scanned:                    state.Scanned,
    99  			Directories:                state.Directories,
   100  			Files:                      state.Files,
   101  			SymbolicLinks:              state.SymbolicLinks,
   102  			TotalFileSize:              state.TotalFileSize,
   103  			ScanProblems:               exportProblems(state.ScanProblems),
   104  			ExcludedScanProblems:       state.ExcludedScanProblems,
   105  			TransitionProblems:         exportProblems(state.TransitionProblems),
   106  			ExcludedTransitionProblems: state.ExcludedTransitionProblems,
   107  			StagingProgress:            newReceiverStateFromInternalReceiverState(state.StagingProgress),
   108  		}
   109  	}
   110  }