Documentation ¶
Index ¶
- type Receiver
- func (r *Receiver) Connect(addr string) error
- func (r *Receiver) HandleFileOffer() error
- func (r *Receiver) HandleInterrupt()
- func (r *Receiver) MainLoop()
- func (r *Receiver) PrintTransferInfo(pauseDuration time.Duration)
- func (r *Receiver) ReceivePackets()
- func (r *Receiver) Stop()
- func (r *Receiver) WritePieceOfFile(filePacket protocol.Packet) error
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 ¶
Creates a new client with default fields
func (*Receiver) Connect ¶
Connects to a given address over tcp. Sets a connection to a corresponding field in receiver
func (*Receiver) HandleFileOffer ¶
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 ¶
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