flu

package
v0.0.0-...-b8f7ae2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RecvConnection

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

func DialPeer

func DialPeer(ip [4]byte, port uint16, hash *common.Sha1Hash, chunk uint16) (*RecvConnection, error)

func (*RecvConnection) Ack

func (r *RecvConnection) Ack(offset uint32)

func (*RecvConnection) Read

func (r *RecvConnection) Read() (*messages.DataPacket, bool)

type SenderConnection

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

func NewSenderConnection

func NewSenderConnection(reader *common.ChunkReader,
	windowCap uint16,
	conn *net.UDPConn,
	addr *net.UDPAddr,
) *SenderConnection

type Server

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

Server dispatches and responds to flu messages. It contains enough internal state to map an incoming UDP message to a previous outgoing message, thereby providing a request/response paradigm when needed. Every request/response is tagged with a monotonically-increasing requestID so many conversations can occur concurrently. All incoming UDP messages should be sent to Server for handling.

func NewServer

func NewServer(port int, cat *catalogue.Cat) *Server

NewServer returns a *Server

func (*Server) ContinueUpload

func (s *Server) ContinueUpload(
	ack *messages.DataPacketAck,
	conn *net.UDPConn,
	returnAddr *net.UDPAddr,
) error

func (*Server) DiscoverHosts

func (s *Server) DiscoverHosts(
	hash *common.Sha1Hash,
	chunks []uint16,
) []messages.DiscoverHostResponse

DiscoverHosts broadcasts a DiscoverHostRequest on the local network, collects responses for a few seconds, and returns the collected results. Both arguments are optional and serve as filters.

func (*Server) HandleMessage

func (s *Server) HandleMessage(message []byte, conn *net.UDPConn, returnAddr *net.UDPAddr) error

HandleMessage does exactly what it says. It expects parameters to be passed by value because it is assumed it will be run concurrently.

func (*Server) ListFilesOnHost

func (s *Server) ListFilesOnHost(
	ipv4 [4]byte,
	port uint16,
	hash *common.Sha1Hash,
) (*messages.ListFilesResponse, error)

ListFilesOnHost sends a request for a list of files from a remote host and returns the response. The request times out if not fulfilled in a few seconds

func (*Server) LocalIP

func (s *Server) LocalIP() *net.IP

LocalIP returns the IPV4 address of the running process (if available). This is not the loopback address (192.168.0.1; 'localhost'), but the address assigned to this host by the LAN's router.

func (*Server) Port

func (s *Server) Port() int

Port retuns the port the server is running on

func (*Server) RespondToDiscoverHosts

func (s *Server) RespondToDiscoverHosts(
	req *messages.DiscoverHostRequest,
	returnAddr *net.UDPAddr,
) error

func (*Server) RespondToListFilesOnHost

func (s *Server) RespondToListFilesOnHost(
	req *messages.ListFilesRequest,
	conn *net.UDPConn,
	returnAddr *net.UDPAddr,
) error

func (*Server) StartDownload

func (s *Server) StartDownload(hash *common.Sha1Hash) error

StartDownload creates a progressfile for the specified file, adds it to the catalogue, and begins the download. A name for the file is chosen arbitrarily from one of the hosts who have that file.

func (*Server) StartUpload

func (s *Server) StartUpload(
	msg *messages.OpenConnectionRequest,
	conn *net.UDPConn,
	returnAddr *net.UDPAddr,
) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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