Documentation
¶
Index ¶
- Variables
- func SendTransferReq(ctx context.Context, t *Transfer) (net.Conn, error)
- func WaitConfirmation(ctx context.Context, i int, inOut io.ReadWriteCloser, store *TransferStore) error
- type Direction
- type Done
- type OnStoreChange
- type Receiver
- type Status
- type Transfer
- type TransferList
- type TransferStore
- func (s *TransferStore) Add(t *Transfer) int
- func (s *TransferStore) AddToWait(t *Transfer) (int, <-chan interface{})
- func (s *TransferStore) FollowProgress(i int) <-chan float64
- func (s *TransferStore) Get(i int) *Transfer
- func (s *TransferStore) Size() int
- func (s *TransferStore) Update(i int, t *Transfer)
- func (s *TransferStore) UpdateProgress(id int, progress float64)
Constants ¶
This section is empty.
Variables ¶
var ErrRejected = errors.New(`REJECTED`)
ErrRejected signals that transfer was rejected.
Functions ¶
func SendTransferReq ¶
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.
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.
type Status ¶
type Status int
Status represents the Transfer 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 ¶
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.
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.