transfer

package
v0.0.0-...-c98d9f8 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2021 License: EPL-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRejected = errors.New(`REJECTED`)

ErrRejected signals that transfer was rejected.

Functions

func SendTransferReq

func SendTransferReq(ctx context.Context, t *Transfer) (net.Conn, error)

SendTransferReq receives a transfer, generates a request transfer message and send it to the receiver.

If there is an error, it can be because it wasn't possible to establish a connection with the receiver, an error setting the timeout or an error when writing the message to the receiver.

func WaitConfirmation

func WaitConfirmation(ctx context.Context, i int, inOut io.ReadWriteCloser, store *TransferStore) error

WaitConfirmation will wait until the receiver accepts or rejects the transfer.

If rejected it will just terminate and update the transfer status. Otherwise it will start sending the file content to the receiver.

Types

type Direction

type Direction int

Direction represents the direction of the transfer.

Upload or Download.

const (
	// Transfer is an Upload
	Upload Direction = iota + 1
	// Transfer is a Download
	Download
)

type Done

type Done chan<- interface{}

Done is channel used to singal the termination of the service.

type OnStoreChange

type OnStoreChange func(i int)

OnStoreChange is a function that is executed everytime a transfer is added, removed or updated to the store.

type Receiver

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

func NewReceiver

func NewReceiver(port int, store *TransferStore) *Receiver

NewReceiver will create a new Receiver server that will wait for connections on the specified port.

func (*Receiver) Run

func (rv *Receiver) Run(ctx context.Context, done Done) error

Run will start the receiver starting the listener to receive requests.

type Status

type Status int

Status represents the Transfer status.

const (
	// Transfer is waiting for confirmation.
	Waiting Status = iota + 1
	// Transfer was accepted.
	Accepted
	// Transfer is getting verified.
	Verifying
	// Transfer was rejected.
	Rejected
	// Transfer is completed.
	Completed
	// Transfer is error state.
	Error
)

func (Status) IsFinal

func (s Status) IsFinal() bool

IsFinal returns true if the status is a final status, which means it will not change anymore.

func (Status) String

func (s Status) String() string

String convert a transfer status into a string representation of that status.

type Transfer

type Transfer struct {
	Direction
	Status        Status
	SenderName    string
	SenderAddr    net.Addr
	FileName      string
	FileChecksum  string
	FileSize      int64
	LocalFilePath string // Full path to local file system. Sender/read path, Receiver/save path.
	// contains filtered or unexported fields
}

Transfer wraps the transfer information

func NewTransfer

func NewTransfer(name, check, sender string, size int64, addr net.Addr, dir Direction) *Transfer

NewTransfer creates a new Transfer instance.

It requires the name of the file, the checksum, the peers name that is sending or receiving depending if it's an upload or download, the size of the file, the address of the peer and the direction.

func (*Transfer) Error

func (t *Transfer) Error() error

Error return the last error registered on the transfer.

func (*Transfer) SetError

func (t *Transfer) SetError(err error)

SetError register an error to the transfer and changes the status to Error.

type TransferList

type TransferList struct {
	widget.List

	Parent fyne.Window
	// contains filtered or unexported fields
}

TransferList is an extended version of widget.List where is uses a store to hold the list items.

func NewView

func NewView(store *TransferStore) *TransferList

NewView creates a new TransferList which is just an extended version of widget.List.

Everytime the store content changes the view is refreshed.

type TransferStore

type TransferStore struct {
	OnStoreChange
	// contains filtered or unexported fields
}

TransferStore is a thread-safe store that allows to store, retrieve, remove, and update transfer and also get notification when the content of the store changes.

func NewStore

func NewStore() *TransferStore

NewTransferStore will create a new instance of TransferStore which is thread-safe.

func (*TransferStore) Add

func (s *TransferStore) Add(t *Transfer) int

Add will add a transfer to the store and return is position. If t is ni the transfer is not added and returns -1.

Also executes the function OnStoreChange after the transfer gets added.

func (*TransferStore) AddToWait

func (s *TransferStore) AddToWait(t *Transfer) (int, <-chan interface{})

AddToWait will add a transfer to the store, return is position and it will also return a channel that allows to wait until this transfer status changes from waiting to another status.

func (*TransferStore) FollowProgress

func (s *TransferStore) FollowProgress(i int) <-chan float64

FollowProgress returns a channel for the transfer on the specified position that allow the consumer to get the current progress of the transfer everytime it changes.

func (*TransferStore) Get

func (s *TransferStore) Get(i int) *Transfer

Get will return an immutable transfer by the position i on the store.

This transfer instance is a copy of the instance stored and for that reason any changes to the returned instance will not have effect on the stored instance.

func (*TransferStore) Size

func (s *TransferStore) Size() int

Size will return the current number of elements on the store.

func (*TransferStore) Update

func (s *TransferStore) Update(i int, t *Transfer)

Update will update the tranfer stored at position i with the values of t.

Only the status, localfilepath and error are updated. It Also executes the function OnStoreChange after the transfer gets updated.

If the status changes from Waiting it will close the waiting channel.

If the status change to a final status it will close the progress channel.

func (*TransferStore) UpdateProgress

func (s *TransferStore) UpdateProgress(id int, progress float64)

UpdateProgress allows to update the progress of the transfer on the specified index.

Everythime this function is called the channel from FollowProgress will get the data provided here.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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