Documentation
¶
Index ¶
- Constants
- func HashBytes(b []byte) uint32
- func HttpRequestToBytes(r HTTPRequest) []byte
- func HttpResponseToBytes(r HTTPResponse) []byte
- func MessageToBytes(message Message) []byte
- type CacheMetadata
- type HTTPRequest
- type HTTPResponse
- type LocalCache
- type Message
- type NodeInfo
- type ProxyConfig
- type ProxyNode
- func (p *ProxyNode) ConstructAnswerMessage() Message
- func (p *ProxyNode) ConstructElectionMessage() Message
- func (p *ProxyNode) ConstructNodeJoinedMessage() Message
- func (p *ProxyNode) ConstructNodeLeftMessage(url string) Message
- func (p *ProxyNode) ConstructVictoryMessage() Message
- func (p *ProxyNode) ContainsResponse(url string) bool
- func (p *ProxyNode) ContainsUrl(url string) bool
- func (p *ProxyNode) HandleHttpRequest(w http.ResponseWriter, r *http.Request)
- func (p *ProxyNode) HandleRequest(b []byte)
- func (p *ProxyNode) HandleRequests()
- func (p *ProxyNode) IndexFromString(url string) int
- func (p *ProxyNode) Multicast(message []byte)
- func (p *ProxyNode) RemoveNodeFromPeers(url string)
- func (p *ProxyNode) StartBackgroundChecker()
- func (p *ProxyNode) StartLeaderElection()
- func (p *ProxyNode) Unicast(message []byte, url string) bool
- type TCPMessenger
Constants ¶
View Source
const ( UNICAST_MESSAGE = 0 // Message to a single node MULTICAST_MESSAGE = 1 // Message to every node JOIN_REQUEST_MESSAGE = 2 // Message used for joining the cluster (request) JOIN_NOTIFY_MESSAGE = 3 // Message used for noifiying the cluster that a new node has joined LEAVE_NOTIFY_MESSAGE = 4 // Message used for notifying the cluster that a node has died HTTP_REQUEST_MESSAGE = 5 HTTP_RESPONSE_MESSAGE = 6 ELECTION_MESSAGE = 7 // Message used for leader election ANSWER_MESSAGE = 8 // Message used for leader election VICTORY_MESSAGE = 9 // Message used for leader election )
Variables ¶
This section is empty.
Functions ¶
func HttpRequestToBytes ¶
func HttpRequestToBytes(r HTTPRequest) []byte
func HttpResponseToBytes ¶
func HttpResponseToBytes(r HTTPResponse) []byte
func MessageToBytes ¶
Types ¶
type CacheMetadata ¶
type HTTPRequest ¶
type HTTPRequest struct { Method string RequestUrl string Header http.Header Body []byte ContentLength int64 }
func BytesToHttpRequest ¶
func BytesToHttpRequest(b []byte) HTTPRequest
type HTTPResponse ¶
type HTTPResponse struct { Status string RequestUrl string Header http.Header Body []byte ContentLength int64 }
func BytesToHttpResponse ¶
func BytesToHttpResponse(b []byte) HTTPResponse
type LocalCache ¶
type LocalCache struct { // Note: Will need a mutex if LocalCache is accessed by multiple servers/threads. Mem map[string]CacheMetadata }
func CreateLocalCache ¶
func CreateLocalCache() *LocalCache
Create and initialize a new LocalCache, and return a pointer to it.
func (*LocalCache) CacheGet ¶
func (cache *LocalCache) CacheGet(pageURL string) *CacheMetadata
Returns a []byte representing the cache'd body, if it exists. If the body has expired, or does not exist, then the entry is deleted from the cache and nil is returned.
func (*LocalCache) CacheSet ¶
func (cache *LocalCache) CacheSet(pageURL string, Res HTTPResponse, secondsToStore int) int
If you need to convert a string into a URL struct, use: func Parse(rawurl string) (*URL, error) https://golang.org/pkg/net/url/#Parse
Attempt to cache the body of a response in a LocalCache. Takes a url, the body to store for that url, and a duration to store it for. Returns 1 on success, 0 on failure.
type Message ¶
func BytesToMessage ¶
type ProxyConfig ¶
type ProxyConfig struct { PublicUrl string `json:"public_url"` CacheTimeout int `json:"cache_timeout"` BlockedSitesList []string `json:"blocked_sites"` BlockedSites map[string]string }
func LoadProxyConfig ¶
func LoadProxyConfig(path string) *ProxyConfig
func (*ProxyConfig) SiteIsBlocked ¶
func (p *ProxyConfig) SiteIsBlocked(url string) bool
type ProxyNode ¶
type ProxyNode struct { Config *ProxyConfig Info *NodeInfo PeerInfo []*NodeInfo Messenger *TCPMessenger Responses *LocalCache Lock *sync.Mutex CV *sync.Cond CurrentForwardingIdx int LeaderUrl string }
func CreateProxyNode ¶
func (*ProxyNode) ConstructAnswerMessage ¶
func (*ProxyNode) ConstructElectionMessage ¶
func (*ProxyNode) ConstructNodeJoinedMessage ¶
func (*ProxyNode) ConstructNodeLeftMessage ¶
func (*ProxyNode) ConstructVictoryMessage ¶
func (*ProxyNode) ContainsResponse ¶
func (*ProxyNode) ContainsUrl ¶
func (*ProxyNode) HandleHttpRequest ¶
func (p *ProxyNode) HandleHttpRequest(w http.ResponseWriter, r *http.Request)
func (*ProxyNode) HandleRequest ¶
func (*ProxyNode) HandleRequests ¶
func (p *ProxyNode) HandleRequests()
func (*ProxyNode) IndexFromString ¶
func (*ProxyNode) RemoveNodeFromPeers ¶
func (*ProxyNode) StartBackgroundChecker ¶
func (p *ProxyNode) StartBackgroundChecker()
func (*ProxyNode) StartLeaderElection ¶
func (p *ProxyNode) StartLeaderElection()
type TCPMessenger ¶
func InitTCPMessenger ¶
func InitTCPMessenger(url string) *TCPMessenger
func (TCPMessenger) HasMessageStored ¶
func (m TCPMessenger) HasMessageStored(hash uint32) bool
func (TCPMessenger) PruneStoredMessages ¶
func (m TCPMessenger) PruneStoredMessages()
Click to show internal directories.
Click to hide internal directories.