fileshare

package
v0.0.0-...-578063f Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectReply

type ConnectReply struct {
	PeerID   int
	Accepted bool
}

Reply RPC for Peer's to connect.

type ConnectRequest

type ConnectRequest struct {
	PeerID int
	Port   string
}

Request RPC for Peer's to connect.

type FindPeerReply

type FindPeerReply struct {
	PeerID int
	Port   string
	File   string
	Found  bool
}

Sent by the SwarmMaster to a Peer indicating the details regarding a Peer that possesses a particular file. Used in Peer.SearchForFile() and SwarmMaster.SearchFile().

type Peer

type Peer struct {
	PeerID int

	Port string
	// contains filtered or unexported fields
}

Struct type for the Peers.

func MakePeer

func MakePeer(id int, directory string, port string) *Peer

Method called to create a new Peer.

func (*Peer) AcceptConnect

func (p *Peer) AcceptConnect(request *ConnectRequest, reply *ConnectReply) error

Handles incoming connection RPCs (ConnectRequest{}) from other Peers.

func (*Peer) ConnectPeer

func (p *Peer) ConnectPeer(port string, id int)

Connects the Peer to the provided Peer.

func (*Peer) ConnectServer

func (p *Peer) ConnectServer()

Connects the Peer to the SwarmMaster.

func (*Peer) RegisterFile

func (p *Peer) RegisterFile(fileName string) error

Registers a file that a Peer has on disk into the FileShare system.

func (*Peer) RequestFile

func (p *Peer) RequestFile(port string, id int, file string)

Requests a given file from a given Peer.

func (*Peer) SearchForFile

func (p *Peer) SearchForFile(fileName string) error

Asks the SwarmMaster for a particular file. The SwarmMaster will search the network of Peers and find the Peer with the requested file, and then send the connection details back to the requesting Peer.

func (*Peer) ServeFile

func (p *Peer) ServeFile(request *RequestFileArgs, reply *RequestFileReply) error

Handles file request RPCs (RequestFileArgs{}) from other Peers.

type PeerInfo

type PeerInfo struct {
	PeerID int
	Port   string
	Files  [10]string
	// contains filtered or unexported fields
}

A lightweight data type for the SwarmMaster and Peers to hold relevant information about the Peers connected to it, including their port and the files they posses.

type PeerSendFile

type PeerSendFile struct {
	PeerID   int
	FileName string
}

RPC for a Peer to send a file to the server.

type RequestFileArgs

type RequestFileArgs struct {
	PeerID int
	File   string
}

Sent by the Peer to the SwarmMaster when searching for a file in the network using Peer.SearchForFile().

type RequestFileReply

type RequestFileReply struct {
	PeerID       int
	FileExists   bool
	ErrorMessage string
	File         string
	FileContents string
}

Used by a peer to send another Peer a file in Peer.RequestFile() and Peer.ServeFile().

type ServerReceiveFile

type ServerReceiveFile struct {
	FileName string
	Received bool
	Accepted bool
}

RPC for the server to confirm it received the file.

type SwarmMaster

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

SwarmMaster data type for the server.

func MakeSwarmMaster

func MakeSwarmMaster() *SwarmMaster

Creates a new SwarmMaster.

func (*SwarmMaster) ConnectPeer

func (m *SwarmMaster) ConnectPeer(request *ConnectRequest, reply *ConnectReply) error

RPC handler for when a Peer wishes to connect to the SwarmMaster.

func (*SwarmMaster) MasterTest

func (m *SwarmMaster) MasterTest()

Simple function to let us know when the SwarmMaster has successfully been built.

func (*SwarmMaster) Register

func (m *SwarmMaster) Register(request *PeerSendFile, reply *ServerReceiveFile) error

RPC handler for when a Peer registers a file in the FileShare system to be shareable. This function will update the SwarmMaster's peers data to include the new file.

func (*SwarmMaster) SearchFile

func (m *SwarmMaster) SearchFile(request *RequestFileArgs, reply *FindPeerReply) error

RPC handler for when a Peer is in search of a file. This function will search the registered files in each Peer's file list to find which Peer contains the requested file. Then a FindPeerReply RPC will be sent to the requesting Peer telling it how to contact the Peer with the desired file.

Jump to

Keyboard shortcuts

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