client

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: GPL-3.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// DefaultGistURL points to the canonical machines.json published by the cluster.
	DefaultGistURL = "https://gist.githubusercontent.com/dvfs-iitgn/6eb8da397735b83f76b54af4cca64c83/raw/machines.json"
	// DefaultGistTimeout is the maximum duration to wait for a Gist response.
	DefaultGistTimeout = 8 * time.Second
	// DefaultCacheTTL is the duration after which cached entries are considered stale.
	DefaultCacheTTL = 5 * time.Minute
)
View Source
const CacheDir = "./.cache"
View Source
const DownloadDir = "./Download"
View Source
const RootCAPEM = `` /* 2109-byte string literal not displayed */

RootCAPEM contains the public certificate of the 10-year offline DVFS Root CA. Embedded directly into the client binary; no external ca_cert file required.

Variables

This section is empty.

Functions

func NewDVFSUniversalCertPool

func NewDVFSUniversalCertPool() (*x509.CertPool, error)

NewDVFSUniversalCertPool creates an isolated x509.CertPool containing strictly the DVFS Root CA, completely ignoring the host operating system's root store. It uses the embedded RootCAPEM and also incorporates any local certs/ca.crt if found.

Types

type CNode

type CNode struct {
	Name string
	Type domain.InodeType // 0 for file, 1 for directory

	Size uint64 // size of the file (for files)
	// contains filtered or unexported fields
}

CNode represents a cached file or directory in the client, and are made to mirror the structure of the remote file system as it gets accessed. They are stored in a tree structure, with the root node representing the root directory of the remote file system. Each CNode has a name, type (file or directory), a map of children nodes (for directories), and a reference to its parent node. The client uses CNodes to cache metadata about files and directories, allowing for faster access and reduced network calls when navigating the file system or performing operations on files and directories.

type CacheHandler

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

func NewCacheHandler

func NewCacheHandler(c *Client, rootFID *domain.FID) *CacheHandler

func (*CacheHandler) ChangeDirectory

func (c *CacheHandler) ChangeDirectory(s string) error

func (*CacheHandler) ClearCache

func (c *CacheHandler) ClearCache()

func (*CacheHandler) ClearTrash

func (c *CacheHandler) ClearTrash() (int, error)

func (*CacheHandler) CreateDirectory

func (c *CacheHandler) CreateDirectory(s string) (*FileInfo, error)

func (*CacheHandler) CreateFile

func (c *CacheHandler) CreateFile(s string) (*FileInfo, error)

func (*CacheHandler) DeleteFile

func (c *CacheHandler) DeleteFile(s string, recursive bool) error

delete file/dir from server and update cache accordingly. If recursive is true, delete all contents of the directory as well

func (*CacheHandler) DeleteFromTrash

func (c *CacheHandler) DeleteFromTrash(name string) error

func (*CacheHandler) Download

func (c *CacheHandler) Download(s string) error

func (*CacheHandler) GetFileInfo

func (c *CacheHandler) GetFileInfo() (*FileInfo, error)

func (*CacheHandler) InvalidateFileByFID

func (c *CacheHandler) InvalidateFileByFID(fid *domain.FID) (string, bool)

InvalidateFileByFID clears cached content for a file and returns a display path.

func (*CacheHandler) ListFiles

func (c *CacheHandler) ListFiles() ([]*FileInfo, error)

func (*CacheHandler) Path

func (c *CacheHandler) Path() (string, error)

func (*CacheHandler) ReadFile

func (c *CacheHandler) ReadFile(s string) ([]byte, error)

check for cache hit, if not then download file from server and update cache

func (*CacheHandler) Refresh

func (c *CacheHandler) Refresh() error

Refresh synchronizes the current directory cache with server state.

func (*CacheHandler) RestoreFile

func (c *CacheHandler) RestoreFile(name string) (string, error)

RestoreFile restores an item from server-side trash and updates cache if currently viewing trash.

func (*CacheHandler) Share

func (c *CacheHandler) Share(s string) error

func (*CacheHandler) ShowTrash

func (c *CacheHandler) ShowTrash() ([]*FileInfo, error)

func (*CacheHandler) TrashFile

func (c *CacheHandler) TrashFile(name string, recursive bool) (string, error)

TrashFile moves a file/dir to server-side trash and updates the current cache view.

func (*CacheHandler) Unshare

func (c *CacheHandler) Unshare(s string) error

func (*CacheHandler) Upload

func (c *CacheHandler) Upload(s string) error

func (*CacheHandler) VisualizeCache

func (c *CacheHandler) VisualizeCache(indent string)

type Client

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

Client provides basic VFS client functionality

func NewClient

func NewClient(username string, opts ...ClientOption) *Client

NewClient creates a new VFS client using the hardcoded Root CA by default.

func (*Client) AttachCacheHandler

func (c *Client) AttachCacheHandler(cacheHandler *CacheHandler)

AttachCacheHandler wires cache invalidation callbacks to the active cache handler.

func (*Client) ChangeCurrentFID

func (c *Client) ChangeCurrentFID(fid *domain.FID)

func (*Client) ChangeDirectory

func (c *Client) ChangeDirectory(relative_path string) (domain.FID, error)

CreateDirectory changes the current directory

func (*Client) ClearTrash

func (c *Client) ClearTrash() (int, error)

ClearTrash permanently deletes every entry currently present in trash.

func (*Client) Connect

func (c *Client) Connect(serverAddress string) (*domain.FID, error)

Connect connects to a file server and gets user root and files/dir in the root

func (*Client) CreateDirectory

func (c *Client) CreateDirectory(name string) (*FileInfo, error)

CreateDirectory creates a new directory

func (*Client) CreateFile

func (c *Client) CreateFile(name string) (*FileInfo, error)

CreateFile creates a new file

func (*Client) DeleteFile

func (c *Client) DeleteFile(name string, recursive bool) error

DeleteFile deletes a file or directory by name in the current directory If recursive is true, non-empty directories will be deleted with all contents

func (*Client) DeleteFromTrash

func (c *Client) DeleteFromTrash(name string) error

DeleteFromTrash permanently deletes a single file/directory currently in trash. Directories are always deleted recursively when deleting from trash.

func (*Client) Disconnect

func (c *Client) Disconnect()

Disconnect gracefully unregisters the client from the fileserver, closes the gRPC connection, and shuts down the callback listener.

func (*Client) Download

func (c *Client) Download(path string) error

Download downloads a file or a directory recursively

func (*Client) DownloadFile

func (c *Client) DownloadFile(name string) error

func (*Client) GetFIDForPath

func (c *Client) GetFIDForPath(path string) (*domain.FID, error)

GetFIDForPath returns the FID of a path relative to current or root directory

func (*Client) GetFileInfo

func (c *Client) GetFileInfo() (*FileInfo, error)

GetFileInfo gets information about user's current directory

func (*Client) GetRoots

func (client *Client) GetRoots(msAddr string) ([]SharedRoot, error)

GetRoots gets the accessible roots to the user from the metaserver

func (*Client) ListFiles

func (c *Client) ListFiles() ([]*FileInfo, error)

ListFiles lists files in user's current directory

func (*Client) ListFilesAt

func (c *Client) ListFilesAt(dirFID *domain.FID) ([]*FileInfo, error)

ListFilesAt lists files/directories for the provided directory FID. It does not change the client's current directory.

func (*Client) NavigateToFileServer

func (client *Client) NavigateToFileServer(msAddr string) (string, error)

NavigateToFileServer dials the meta server over TLS and navigates the client to the appropriate file server. selfAddr is the host:port that the meta server should store as this FS's address. If msAddr is empty this is a no-op.

func (*Client) Notify

func (c *Client) Notify(format string, args ...interface{})

Notify prints a notification message. If a readline-aware writer is set it uses that (which redraws the prompt); otherwise it falls back to os.Stdout.

func (*Client) Path

func (c *Client) Path() (string, error)

Returns current user path

func (*Client) ReRegister

func (c *Client) ReRegister() error

ReRegister re-establishes the client session with the fileserver. This restores the server-side session (for callbacks) and verifies that the root FID hasn't changed.

func (*Client) ReadFile

func (c *Client) ReadFile(name string) ([]byte, error)

ReadFile reads a file

func (*Client) Resolver

func (c *Client) Resolver() *DiscoveryResolver

Resolver returns the client's discovery resolver.

func (*Client) RestoreFile

func (c *Client) RestoreFile(name string) (string, error)

RestoreFile restores a trashed file/directory (by name in .trash) back to its original location.

func (*Client) SetNotifyWriter

func (c *Client) SetNotifyWriter(w io.Writer)

SetNotifyWriter provides a readline-aware writer so notifications correctly redraw the prompt instead of overwriting it.

func (*Client) SetRootPath

func (c *Client) SetRootPath(display_name, path string)

Set root path

func (*Client) SetRootUser

func (c *Client) SetRootUser(root_user string)

Set user root

func (*Client) Share

func (c *Client) Share(share_with string) error

Share another user the root dir only if current user is owner

func (*Client) ShowTrash

func (c *Client) ShowTrash() ([]*FileInfo, error)

ShowTrash lists the user's trash contents without navigating into .trash.

func (*Client) TrashFile

func (c *Client) TrashFile(name string, recursive bool) (string, error)

TrashFile moves a file or directory (by name in current directory) to the user's trash. If recursive is true, non-empty directories can be trashed.

func (*Client) Unshare

func (c *Client) Unshare(unshare_with string) error

Unshare another user the root dir only if current user is owner

func (*Client) Upload

func (c *Client) Upload(localPath string) (*domain.FID, error)

Upload uploads a file or a directory recursively, returning the FID

func (*Client) WriteFile

func (c *Client) WriteFile(name string, data []byte) error

WriteFile writes given data to a file

type ClientOption

type ClientOption func(*Client)

ClientOption configures optional client settings (primarily for testing).

func WithDiscovery

func WithDiscovery(resolver *DiscoveryResolver) ClientOption

WithDiscovery attaches a custom DiscoveryResolver to the client.

func WithInsecure

func WithInsecure() ClientOption

WithInsecure disables TLS verification (for local in-memory unit tests only).

func WithServerName

func WithServerName(name string) ClientOption

WithServerName sets a custom TLS server name (SNI).

type CobraCompleter

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

CobraCompleter implements readline.Completer using the Cobra command tree

func (*CobraCompleter) Do

func (c *CobraCompleter) Do(line []rune, pos int) (newLine [][]rune, length int)

type CobraHandler

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

CobraHandler handles commands using Cobra

func NewCobraHandler

func NewCobraHandler(cacheHandler *CacheHandler) *CobraHandler

NewCobraHandler creates a new Cobra-based command handler

func (*CobraHandler) Start

func (h *CobraHandler) Start() bool

Start begins the interactive command loop

type DiscoveryOption

type DiscoveryOption func(*DiscoveryResolver)

DiscoveryOption configures a DiscoveryResolver.

func WithCacheFile

func WithCacheFile(path string) DiscoveryOption

WithCacheFile overrides the local disk cache path.

func WithCacheTTL

func WithCacheTTL(ttl time.Duration) DiscoveryOption

WithCacheTTL sets the time-to-live for cached discovery entries.

func WithGistURL

func WithGistURL(url string) DiscoveryOption

WithGistURL overrides the default Gist URL.

func WithHTTPClient

func WithHTTPClient(client *http.Client) DiscoveryOption

WithHTTPClient overrides the default HTTP client.

type DiscoveryResolver

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

DiscoveryResolver dynamically resolves cluster node hostnames to IPs and vice versa.

func NewDiscoveryResolver

func NewDiscoveryResolver(opts ...DiscoveryOption) *DiscoveryResolver

NewDiscoveryResolver initializes a resolver with default or custom options.

func (*DiscoveryResolver) FetchNodes

func (d *DiscoveryResolver) FetchNodes(ctx context.Context) (map[string]string, error)

FetchNodes polls the GitHub Gist over HTTPS, updates memory caches, and persists to disk. If the network request fails, it falls back to the persisted disk cache.

func (*DiscoveryResolver) Lookup

func (d *DiscoveryResolver) Lookup(nodeName string) (string, error)

Lookup returns the IP address for the given node identifier (e.g. "dvfs1"). If the cache is empty or stale, it attempts a live fetch.

func (*DiscoveryResolver) ResolveMetaAddress

func (d *DiscoveryResolver) ResolveMetaAddress(defaultPort string) (string, error)

ResolveMetaAddress resolves the metaserver (dvfs1) IP and formats host:port.

func (*DiscoveryResolver) ResolveServerName

func (d *DiscoveryResolver) ResolveServerName(address string) string

ResolveServerName determines the TLS SNI / SAN name to verify against. Given "10.0.171.38:50051", it extracts "10.0.171.38", checks if it maps to "dvfs1", and returns "dvfs1". For "127.0.0.1" or "localhost", it returns "localhost".

func (*DiscoveryResolver) SetNodes

func (d *DiscoveryResolver) SetNodes(nodes []GistNode)

SetNodes manually sets node mappings (primarily for unit tests and local overrides).

type FileInfo

type FileInfo struct {
	FID  *domain.FID
	Name string
	Type domain.InodeType
	Size uint64
}

FileInfo represents file information

type GistNode

type GistNode struct {
	Username string `json:"username"` // e.g. "dvfs1", "dvfs2"
	MAC      string `json:"mac"`      // e.g. "28:cd:c1:0e:25:70"
	IP       string `json:"ip"`       // e.g. "10.0.171.38"
	LastSeen string `json:"last_seen"`
}

GistNode represents a node entry in the cluster's machines.json.

type SharedRoot

type SharedRoot struct {
	Path        string
	DisplayName string
	Owner       string
}

Shared Roots with the user

Jump to

Keyboard shortcuts

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