client

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

ConnectionNotificationStrings String representation of ConnectionNotificationType iota

Functions

This section is empty.

Types

type ConnectionNotificationType

type ConnectionNotificationType uint8

ConnectionNotificationType is an iota for all types of connection notifications

const (
	// ConnectionNotificationTypeConnected Connected
	ConnectionNotificationTypeConnected ConnectionNotificationType = iota
	// ConnectionNotificationTypeDisconnected Disconnected
	ConnectionNotificationTypeDisconnected
	// ConnectionNotificationTypeFilesUpdated Bytes transferred for file
	ConnectionNotificationTypeFilesUpdated
	// ConnectionNotificationTypeCompleted File transfer completed
	ConnectionNotificationTypeCompleted
	// ConnectionNotificationTypeQueryError Query error from server
	ConnectionNotificationTypeQueryError
	// ConnectionNotificationTypeTransferError Transfer error from server
	ConnectionNotificationTypeTransferError
	// ConnectionNotificationTypeFatalError Fatal transfer error
	ConnectionNotificationTypeFatalError
)

type Dispatcher added in v0.1.4

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

func NewDispatcher added in v0.1.4

func NewDispatcher(jobQueue <-chan ServerTransferJob, maxWorkers int) *Dispatcher

NewDispatcher creates, and returns a new Dispatcher object.

type File

type File struct {
	Path         string
	MediaPrefix  string
	Size         uint64
	ModifiedTime time.Time
	WatchTime    time.Time
	TransferTime time.Time
}

File in the client package represents the clients view of a watched file

func NewClientFile

func NewClientFile(path, mediaDirectoryRoot string) (*File, error)

NewClientFile parses a preset media root and a path to string and outputs the client file representation for the file path. This function should be used to tell the Torrxfer server what part of the file path should be used to generate its directory structure and what path from the client should be discarded Example: If the provided path is /home/user/foo/bar/file.txt and the directory structure under foo should be maintained on the server, mediaDirectoryRoot should be /home/user/foo. This will tell the server that under its own media folder it should create the directory bar and store file.txt there.

func (*File) GenerateRPCFile

func (f *File) GenerateRPCFile() (*net.RPCFile, error)

GenerateRPCFile creates an RPCFile representation from the current file

func (*File) MarshalText

func (f *File) MarshalText() (text []byte, err error)

MarshalText converts the clientFile representation to a utf encoded byte array

func (*File) MarshalZerologObject

func (f *File) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject adds the file details to the current zerolog event

func (*File) UnmarshalText

func (f *File) UnmarshalText(text []byte) error

UnmarshalText takes a utf encoded byte array and builds a ClientFile object from it

type FileWatcher

type FileWatcher interface {
	RegisterForFileNotifications() <-chan *File
	Close()
}

FileWatcher provides notifications when changes occur on the provided watched directory

func NewFileWatcher

func NewFileWatcher(directory string, mediaDirectoryRoot string) (FileWatcher, error)

NewFileWatcher starts watching the provided directory for any new writes and here-before unseen files If there is a new file, this will wait up to two minutes for any new writes, at which point it will

type ServerConnection

type ServerConnection struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ServerConnection contains all active data about a connection with a Torrxfer server

func (*ServerConnection) GetAddress

func (s *ServerConnection) GetAddress() (address string)

GetAddress returns the address of the server

func (*ServerConnection) GetBytesTransferred

func (s *ServerConnection) GetBytesTransferred() (bytesTransferred uint64)

GetBytesTransferred returns the total bytes transferred to the server in this session

func (*ServerConnection) GetConnectionTime

func (s *ServerConnection) GetConnectionTime() (connectionTime time.Time)

GetConnectionTime returns the time when the server was connected

func (*ServerConnection) GetFileSizeOnServer

func (s *ServerConnection) GetFileSizeOnServer(filename string) (fileSize uint64)

GetFileSizeOnServer returns the current number of bytes transferred for this file in this session

func (*ServerConnection) GetFilesTransferred

func (s *ServerConnection) GetFilesTransferred() (files []*File)

GetFilesTransferred returns the files transferred to the server in this session

func (*ServerConnection) GetIndex

func (s *ServerConnection) GetIndex() (index uint16)

GetIndex returns the index of the server for the client

func (*ServerConnection) GetPort

func (s *ServerConnection) GetPort() (port uint32)

GetPort returns the port of the server

func (*ServerConnection) MarshalZerologObject

func (s *ServerConnection) MarshalZerologObject(e *zerolog.Event)

MarshalZerologObject implements the zerolog Object Marshaller for easy connection detail logging

type ServerNotification

type ServerNotification struct {
	NotificationType ConnectionNotificationType
	Error            error
	Connection       *ServerConnection
	SentFile         *File
	LastSentSize     uint64
}

ServerNotification is a struct that contains details about a notification from a server transfer action

type ServerTransferJob added in v0.1.4

type ServerTransferJob struct {
	ID                    uuid.UUID
	Delay                 time.Duration
	ServerConnection      *ServerConnection
	File                  *File
	TransferNotifications chan ServerNotification
}

ServerTransferJob holds the attributes needed to perform unit of work.

type ServerTransferWorker added in v0.1.4

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

ServerTransferWorker performs the work necessary to transfer a file request to a server

func NewServerTransferWorker added in v0.1.4

func NewServerTransferWorker(id int, workerPool chan chan ServerTransferJob) ServerTransferWorker

NewServerTransferWorker creates takes a numeric id and a channel w/ worker pool.

type TorrxferClient

type TorrxferClient interface {
	WatchDirectory(dirname, mediaDirectoryRoot string) error
	ConnectServer(server common.ServerConnectionConfig) (*ServerConnection, error)
	RegisterForConnectionNotifications() <-chan ServerNotification
	Run(*os.File) error
}

TorrxferClient struct describes the client functionality for Torrxfer

func NewTorrxferClient

func NewTorrxferClient() (c TorrxferClient)

NewTorrxferClient creates and instantiates a torrxfer client struct

Jump to

Keyboard shortcuts

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