sender

package
v0.1.43 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChunkSize

func ChunkSize(payloadSize int64) int64

ChunkSize returns an appropriate chunk size for the payload size

Types

type Sender

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

Sender represents the sender client, handles tranx communication and file transfer.

func NewSender

func NewSender(programOptions models.TranOptions) *Sender

NewSender returns a bare bones Sender.

func WithPayload

func WithPayload(s *Sender, payload io.Reader, payloadSize int64) *Sender

WithPayload specifies the payload that will be transfered.

func WithServer

func WithServer(s *Sender, options ServerOptions) *Sender

WithServer specifies the option to run the sender by hosting a server which the receiver establishes a connection to.

func WithUI

func WithUI(s *Sender, ui chan<- UIUpdate) *Sender

WithUI specifies the option to run the sender with an UI channel that reports the state of the transfer.

func (*Sender) CloseServer

func (s *Sender) CloseServer()

func (*Sender) ConnectToTranx

func (s *Sender) ConnectToTranx(
	tranxAddress string,
	tranxPort int,
	passwordCh chan<- models.Password,
	startServerCh chan<- ServerOptions,
	payloadReady <-chan bool,
	relayCh chan<- *websocket.Conn,
) error

ConnectToTranx, establishes the connection with the tranx server. Paramaters: tranxAddress - IP or hostname of the tranx server tranxPort - port of the tranx server startServerCh - channel to communicate to the caller when to start the server, and with which options. passwordCh - channel to communicate the password to the caller. startServerCh - channel to communicate to the caller when to start the server, and with which options. payloadReady - channel over which the caller can communicate when the payload is ready. relayCh - channel to commuincate if we are using relay (tranx) for transfer.

func (*Sender) StartServer

func (s *Sender) StartServer() error

Start starts the sender.Server webserver and setups graceful shutdown

func (*Sender) Transfer

func (s *Sender) Transfer(wsConn *websocket.Conn) error

Transfer is the file transfer sequence, can be via relay or tranx.

func (*Sender) TranxAddress

func (s *Sender) TranxAddress() string

func (*Sender) TranxPort

func (s *Sender) TranxPort() int

type Server

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

Server specifies the webserver that will be used for direct file transfer.

type ServerOptions

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

Specifies the necessary options for initializing the webserver.

type TransferState

type TransferState int
const (
	Initial TransferState = iota
	WaitForFileRequest
	SendingData
	WaitForFileAck
	WaitForCloseMessage
	WaitForCloseAck
)

func (TransferState) Name

func (s TransferState) Name() string

Name returns the associated to the state enum.

type UIUpdate

type UIUpdate struct {
	State    TransferState
	Progress float32
}

UIUpdate is a struct that is continously communicated to the UI (if sender has attached a UI)

type WrongStateError

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

WrongStateError is a custom error for the Transfer sequence

func NewWrongStateError

func NewWrongStateError(expected, got TransferState) *WrongStateError

WrongStateError constructor

func (*WrongStateError) Error

func (e *WrongStateError) Error() string

Jump to

Keyboard shortcuts

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