sender

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

func GetLocalIP

func GetLocalIP() (string, error)

gets a local ip. Borrowed from StackOverflow, thank you, whoever I brought it from

func GetRemoteIP

func GetRemoteIP() (string, error)

gets a remote ip. Borrowed from StackOverflow, thank you, whoever I brought it from

Types

type Sender

type Sender struct {
	Port            int
	FileToTransfer  *file
	Listener        net.Listener
	Connection      net.Conn
	IncomingPackets chan protocol.Packet
	EncryptionKey   []byte
	TransferInfo    *transferInfo
	TransferAllowed bool // the receiver had agreed to receive a file
	ReceiverIsReady bool // receiver is waiting for a new packet
	Stopped         bool // controlls the mainloop
}

The main sender struct

func NewSender

func NewSender(port int, filepath string) *Sender

Creates a new sender with default|necessary fields

func (*Sender) HandleInterrupt

func (s *Sender) HandleInterrupt()

When the interrupt signal is sent - exit cleanly

func (*Sender) MainLoop

func (s *Sender) MainLoop()

The "head" of the sender. "Glues" all things together. Current structure allows the sender to receive any type of packet in any order and react correspondingly

func (*Sender) PrintTransferInfo

func (s *Sender) PrintTransferInfo(pauseDuration time.Duration)

Prints a brief information about the state of the transfer

func (*Sender) ReceivePackets

func (s *Sender) ReceivePackets()

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

func (*Sender) SendEncryptionKey

func (s *Sender) SendEncryptionKey() error

Sends generated earlier eas encryption key to receiver

func (*Sender) SendOffer

func (s *Sender) SendOffer() error

Sends multiple packets with all information about the file to receiver (filename, filesize, checksum)

func (*Sender) SendPiece

func (s *Sender) SendPiece() error

Sends one packet that contains a piece of file to the receiver

func (*Sender) Stop

func (s *Sender) Stop()

Closes the connection, warns about it the receiver and exits the mainloop

func (*Sender) StopListening

func (s *Sender) StopListening()

Closes the listener. Used only when there is still no connection from `AcceptConnections`

func (*Sender) WaitForConnection

func (s *Sender) WaitForConnection()

Accepts one connection

Jump to

Keyboard shortcuts

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