Gossip 1.1
Public Types | Public Member Functions | List of all members
gossip::server::GossipNode Class Reference

Gossip node server, handles client's and other node's request. More...

#include <GossipNode.h>

Public Types

using RetryCall = GossipPeerNode::AsyncClientCall< google::protobuf::Any, google::protobuf::Any >
 

Public Member Functions

 GossipNode (std::string name, std::string ex_addr, std::string in_addr, std::string token="")
 
 ~GossipNode ()
 Destructor of GossipNode. Recycle the sources claimed.
 
std::string internalAddress () const
 
std::string externalAddress () const
 
void run ()
 Run this gossip node.
 
bool stop ()
 
const GossipSlotlocalSlot () const
 
std::string NodeName () const
 
std::string Token () const
 
nlohmann::json getNodeStatus ()
 
SlotVersion insertOrUpdateMessage (const std::string &key, const std::string &value)
 
SlotVersion deleteMessage (const std::string &key)
 
std::string getMessage (const std::string &key)
 
pf_gossip::SearchResult searchMessage (const std::string &key, bool latest)
 
SlotVersion handlePullRequest (const std::string &slot, const SlotValues &values, SlotVersion version, const pf_gossip::SlotUpdate *origin)
 
SlotVersion handleHeartbeatRequest (const std::string &node_name, const std::string &slot_name, SlotVersion version)
 
bool handleNewNodeNotify (const std::string &name, const std::string &address, SlotVersion version, const ::pf_gossip::GossipNodeInfo *origin)
 
void handleDeleteNodeNotify (const std::string &name, const std::string &address, SlotVersion version, const ::pf_gossip::GossipNodeInfo *origin)
 
std::string startConnection (const std::string &address)
 
void startHeartBeat ()
 
void startDeleteNodeNotify ()
 
void startNewNodeNotify (const std::string &name, const std::string &address, SlotVersion version)
 
void addRetryTask (GossipPeerNode::AsyncClientCall< google::protobuf::Any, google::protobuf::Any > *call)
 

Detailed Description

Gossip node server, handles client's and other node's request.

Class GossipNode handles gossip client's and gossip peer node's rpc request, and maintains a K-V map in memory.

Constructor & Destructor Documentation

◆ GossipNode()

gossip::server::GossipNode::GossipNode ( std::string  name,
std::string  ex_addr,
std::string  in_addr,
std::string  token = "" 
)
explicit

Constructor of GossipNode. Create gossip peer node listen port and gossip client listen port.

Parameters
nameName of gossip node. Used to identify different gossip slot.
ex_addrGossip client listen address. If is set "", means don't open client port.
in_addrGossip peer node listen address. If is set "", means don't open peer node port.
tokenGossip Client Entry token. If not set, this node will acquire no token.

Member Function Documentation

◆ addRetryTask()

void gossip::server::GossipNode::addRetryTask ( GossipPeerNode::AsyncClientCall< google::protobuf::Any, google::protobuf::Any > *  call)

Add a retry task in gossip retry tasks.

Parameters
callA rpc async object

◆ deleteMessage()

SlotVersion gossip::server::GossipNode::deleteMessage ( const std::string &  key)

Handle gossip client's delete request by key.

Parameters
keyThe key of message
Returns
Updated slot version

◆ externalAddress()

std::string gossip::server::GossipNode::externalAddress ( ) const
inline

Get the gossip client address of this gossip node.

Returns
Gossip client address

◆ getMessage()

std::string gossip::server::GossipNode::getMessage ( const std::string &  key)

Handle gossip client's read request by key. This function only finds value in local slot.

Parameters
keyThe key of message
Returns
Latest value

◆ getNodeStatus()

nlohmann::json gossip::server::GossipNode::getNodeStatus ( )

Get the status of this gossip node.

Returns
The status of gossip node

◆ handleDeleteNodeNotify()

void gossip::server::GossipNode::handleDeleteNodeNotify ( const std::string &  name,
const std::string &  address,
SlotVersion  version,
const ::pf_gossip::GossipNodeInfo origin 
)

Handle gossip peer node's node delete notify. This node will set that node unhealthy and then check its real status.

Parameters
nameThe name of deleted node
addressThe address of deleted node
versionThe version of deleted node
originReceived message

◆ handleHeartbeatRequest()

SlotVersion gossip::server::GossipNode::handleHeartbeatRequest ( const std::string &  node_name,
const std::string &  slot_name,
SlotVersion  version 
)

Handle gossip peer node's heartbeat request. If peer node's version is higher than this or the same as this, function will do nothing. If peer node's version is less than this, function will put peer node to lower_slots and delayed pull this node's slot to that peer node.

Parameters
node_nameNode name of peer node
slot_nameSlot name to compare
versionVersion of peer node's slot
Returns
This node's slot version

◆ handleNewNodeNotify()

bool gossip::server::GossipNode::handleNewNodeNotify ( const std::string &  name,
const std::string &  address,
SlotVersion  version,
const ::pf_gossip::GossipNodeInfo origin 
)

Handle gossip peer node's new node notify. If the new node is not connected, this node will connect to it. Otherwise, this node will do nothing.

Parameters
nameThe name of new node
addressThe address of new node
versionThe version of new node
originReceived message
Returns
If connect to new node successfully

◆ handlePullRequest()

SlotVersion gossip::server::GossipNode::handlePullRequest ( const std::string &  slot,
const SlotValues &  values,
SlotVersion  version,
const pf_gossip::SlotUpdate origin 
)

Handle gossip peer node's pull request. Node will first propagate message to another nodes and then compare and update this node's slot. If slot is updated, function returns new version; if not, function returns original version.

Parameters
slotSlot name
valuesSlot values
versionSlot version
originPeer's request
Returns
Updated slot version. If not updated, returns original version.

◆ insertOrUpdateMessage()

SlotVersion gossip::server::GossipNode::insertOrUpdateMessage ( const std::string &  key,
const std::string &  value 
)

Handle gossip client's insert or update request. Using the request handled time as slot version.

Parameters
keyThe key of message
valueThe value of message
Returns
Updated slot version

◆ internalAddress()

std::string gossip::server::GossipNode::internalAddress ( ) const
inline

Get the gossip node address of this gossip node

Returns
Gossip node address

◆ localSlot()

const GossipSlot * gossip::server::GossipNode::localSlot ( ) const
inline

Get the copy of local slot.

Returns
GossipSlot object

◆ NodeName()

std::string gossip::server::GossipNode::NodeName ( ) const
inline

Get the name of this gossip node.

Returns
The name of this gossip node

◆ searchMessage()

pf_gossip::SearchResult gossip::server::GossipNode::searchMessage ( const std::string &  key,
bool  latest 
)

Handle gossip client's read request by key. This function will finds version in all slot. If latest is set true, this node will ask the owner of message to get latest version.

Parameters
keyThe key of message
latestIs latest version needed
Returns
Find result

◆ startConnection()

std::string gossip::server::GossipNode::startConnection ( const std::string &  address)

Send connect request to a gossip node, if succeed peer node will send notification to other gossip nodes that peer has connected to.

Parameters
addressip address of peer node
Returns
Whether connection is established. If succeed, returns "". Otherwise, returns error information

◆ startDeleteNodeNotify()

void gossip::server::GossipNode::startDeleteNodeNotify ( )

Start a gossip transmit of node delete. This only happens when this node is down. Function randomly select some nodes to send notification rpc.

◆ startHeartBeat()

void gossip::server::GossipNode::startHeartBeat ( )

Start a gossip transmit of heartbeat swap. This function randomly select a peer node to swap this node's local slot version.

◆ startNewNodeNotify()

void gossip::server::GossipNode::startNewNodeNotify ( const std::string &  name,
const std::string &  address,
SlotVersion  version 
)

Start a gossip transmit of new node. This will happen only when this node received a new node's connection request. Function randomly select some nodes to send notification rpc.

Parameters
nameNew gossip node's name
addressNew gossip node's ip address
versionNew gossip node's version

◆ stop()

bool gossip::server::GossipNode::stop ( )

Stop this gossip node.

Returns
If stop succeed

◆ Token()

std::string gossip::server::GossipNode::Token ( ) const
inline

Get the token of this gossip node.

Returns
The token of this gossip node

The documentation for this class was generated from the following files: