Gossip node server, handles client's and other node's request.
More...
#include <GossipNode.h>
|
| 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 GossipSlot * | localSlot () 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) |
|
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.
◆ 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
-
name | Name of gossip node. Used to identify different gossip slot. |
ex_addr | Gossip client listen address. If is set "", means don't open client port. |
in_addr | Gossip peer node listen address. If is set "", means don't open peer node port. |
token | Gossip Client Entry token. If not set, this node will acquire no token. |
◆ addRetryTask()
Add a retry task in gossip retry tasks.
- Parameters
-
◆ deleteMessage()
SlotVersion gossip::server::GossipNode::deleteMessage |
( |
const std::string & |
key | ) |
|
Handle gossip client's delete request by key.
- Parameters
-
- 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
-
- 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
-
name | The name of deleted node |
address | The address of deleted node |
version | The version of deleted node |
origin | Received 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_name | Node name of peer node |
slot_name | Slot name to compare |
version | Version 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
-
name | The name of new node |
address | The address of new node |
version | The version of new node |
origin | Received 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
-
slot | Slot name |
values | Slot values |
version | Slot version |
origin | Peer'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
-
key | The key of message |
value | The 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()
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
-
key | The key of message |
latest | Is 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
-
address | ip 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
-
name | New gossip node's name |
address | New gossip node's ip address |
version | New 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:
- /Users/tangrenchu/CLionProjects/Gossip/server/GossipNode.h
- /Users/tangrenchu/CLionProjects/Gossip/server/GossipNode.cpp