client

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WRITE_MODE = "write"
	READ_MODE  = "read"
)

Page access mode types

View Source
const (
	INVALIDATE         = "invalidate"
	READ               = "read_request"
	READ_FORWARD       = "read_forward"
	WRITE_FORWARD      = "write_forward"
	WRITE              = "write_request"
	WRITE_CONFIRMATION = "write_confirmation"
	EMPTY              = "empty"
	JOIN               = "join"
	COPY               = "copy"
	WRITE_COPY         = "write_copy"
	FIRST              = "first" // When you're the first node requesting read access to the page, so you can directly set it's
	ACK                = "ack"
	I_HAVE_COPY        = "i_have_copy"
	NEW_SERVER         = "new_server"
)

Message types

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	IP         string
	Cache      map[int]Page // List of pages in its cache. pageId -> Page{Content, Access Mode}
	ServerIP   string
	Clientlist []string
	Timestamp  int // scalar clock to indicate when the request was made. If there are concurrent requests, then we need to break ties
}

func (*Client) CallCentralRPC

func (client *Client) CallCentralRPC(msg message.Message, IP string) message.Message

func (*Client) CallRPC

func (client *Client) CallRPC(msg message.Message, IP string) message.Message

func (*Client) HandleIncomingMessage

func (client *Client) HandleIncomingMessage(msg *message.Message, reply *message.Message) error

The default method called by all RPCs. This method receives different types of requests, and calls the appropriate functions.

func (*Client) JoinNetwork

func (client *Client) JoinNetwork(helper string)

Function called to join the network, by contacting the central manager. This is so the central manager knows about you in its metadata. The client also obtains the clientlist from the central manager, and notifies all the other clients of its existence.

func (*Client) PrintCentralIP

func (client *Client) PrintCentralIP()

func (*Client) PrintClientList

func (client *Client) PrintClientList()

func (*Client) PrintPages added in v1.0.0

func (client *Client) PrintPages()

func (*Client) ReadRequest

func (client *Client) ReadRequest()

A requesting node will first check it's own cache and then check with the central manager, in case it doesn't have it. It may also update the record and become it's owner, if there is no other node in the network that owns this page.

func (*Client) WriteRequest

func (client *Client) WriteRequest()

type Page

type Page struct {
	Content    int    // Content in the page. For the purpose of this implementation, we will make it a simple integer.
	AccessMode string // READ | WRITE
}

Jump to

Keyboard shortcuts

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