receiver

package
v0.0.0-...-1aa968d Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Receiver

type Receiver struct {
	DownloadsFolder string
	Connection      net.Conn
	IncomingPackets chan protocol.Packet
	FileToDownload  *file
	EncryptionKey   []byte
	TransferInfo    *transferInfo
	ReadyToReceive  bool // waiting for a new packet
	Stopped         bool // controlls the mainloop
}

Representation of a receiver

func NewReceiver

func NewReceiver(downloadsFolder string) *Receiver

Creates a new client with default fields

func (*Receiver) Connect

func (r *Receiver) Connect(addr string) error

Connects to a given address over tcp. Sets a connection to a corresponding field in receiver

func (*Receiver) HandleFileOffer

func (r *Receiver) HandleFileOffer() error

Prints known information about the file that is about to be transported. Handles the input from the user after the sender sent "DOYOUACCEPT?" packet. The choice of acceptance is given to the user

func (*Receiver) HandleInterrupt

func (r *Receiver) HandleInterrupt()

When the interrupt signal is sent - exit cleanly

func (*Receiver) MainLoop

func (r *Receiver) MainLoop()

The "head" of the receiver. Similarly as in server`s logic "glues" everything together. Current structure allows the receiver to receive any type of packet in any order and react correspondingly

func (*Receiver) PrintTransferInfo

func (r *Receiver) PrintTransferInfo(pauseDuration time.Duration)

Prints a brief information about the state of the transfer

func (*Receiver) ReceivePackets

func (r *Receiver) ReceivePackets()

Listens in an endless loop; reads incoming packets, decrypts their BODY and puts into channel

func (*Receiver) Stop

func (r *Receiver) Stop()

Closes the connection, warns the sender and exits the mainloop

func (*Receiver) WritePieceOfFile

func (r *Receiver) WritePieceOfFile(filePacket protocol.Packet) error

Handles the download by writing incoming bytes into the file

Jump to

Keyboard shortcuts

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