CHG: removed the sourcetype out of the basic message
This commit is contained in:
@@ -27,8 +27,8 @@
|
||||
namespace WHISPER {
|
||||
|
||||
|
||||
InternalUDPService::InternalUDPService(std::uint32_t parentid,std::uint32_t id, SourceType owndevicetype,std::uint16_t port, std::string destinationAdress,std::string myAdress):
|
||||
whispercomm(parentid,id, owndevicetype),port_(port),destinationAdress_(destinationAdress),myAdress_(myAdress)
|
||||
InternalUDPService::InternalUDPService(std::string id, std::uint16_t port, std::string destinationAdress,std::string myAdress):
|
||||
whispercomm(id),port_(port),destinationAdress_(destinationAdress),myAdress_(myAdress)
|
||||
{
|
||||
ctx = zmq::context_t(2);
|
||||
sender = zmq::socket_t(ctx,zmq::socket_type::radio);
|
||||
@@ -83,7 +83,7 @@ namespace WHISPER {
|
||||
|
||||
LOG_S(INFO)<<"own ID: "<< getOwnID();
|
||||
|
||||
WHISPER::Join join(getParentID(),getOwnID(),getOwnDeviceType(),ownReceivingPort_,myAdress_);
|
||||
WHISPER::Join join(getOwnID(),ownReceivingPort_,myAdress_);
|
||||
this->publish(join.serialize(),WHISPER::MsgTopicsMap[WHISPER::MsgTopics::MANAGEMENT]);
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace WHISPER {
|
||||
|
||||
void InternalUDPService::derivedDisconnect()
|
||||
{
|
||||
WHISPER::Leave Leave(getParentID(),getOwnID(),getOwnDeviceType(),ownReceivingPort_,myAdress_);
|
||||
WHISPER::Leave Leave(getOwnID(),ownReceivingPort_,myAdress_);
|
||||
this->publish(Leave.serialize(),WHISPER::MsgTopicsMap[(WHISPER::MsgTopics)Leave.topic_]);
|
||||
// unsubscribe(WHISPER::MsgTopicsMap[WHISPER::MsgTopics::MANAGEMENT]);
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace WHISPER {
|
||||
|
||||
|
||||
sendToLocalClients(receivedMessage.serialize(), WHISPER::MsgTopicsMap[(WHISPER::MsgTopics)receivedMessage.topic_]);
|
||||
if (receivedMessage.deviceId_ != getOwnID())
|
||||
if (receivedMessage.senderUUID_ != getOwnID())
|
||||
{
|
||||
|
||||
int msgType = receivedMessage.msgType_;
|
||||
@@ -168,7 +168,7 @@ namespace WHISPER {
|
||||
{
|
||||
for (auto it = localclients.begin(); it != localclients.end();it++)
|
||||
{
|
||||
if (it->get()->getPort() == join.port || it->get()->getID() == join.deviceId_)
|
||||
if (it->get()->getPort() == join.port || it->get()->getID() == join.senderUUID_)
|
||||
{
|
||||
clientAllreadyIn = true;
|
||||
}
|
||||
@@ -181,7 +181,7 @@ namespace WHISPER {
|
||||
auto tmpAddr = "udp://"+join.sourceAddr+":" + std::to_string(join.port);
|
||||
auto tmpsocket = std::make_shared<zmq::socket_t>(ctx,zmq::socket_type::radio);
|
||||
|
||||
auto client = std::make_shared<localClient>(join.port,tmpAddr,join.parentId_,join.deviceId_, tmpsocket);
|
||||
auto client = std::make_shared<localClient>(join.port,tmpAddr,join.senderUUID_, tmpsocket);
|
||||
// client->port = join.port;
|
||||
// client->id = join.deviceId_;
|
||||
// client->parentid = join.parentId_;
|
||||
@@ -207,7 +207,7 @@ namespace WHISPER {
|
||||
if (localclients.size() > 0) {
|
||||
for (auto it = localclients.begin(); it != localclients.end();it++)
|
||||
{
|
||||
if (it->get()->getPort() == Leave.port || (it->get()->getID() == Leave.deviceId_ && it->get()->getParentid() == Leave.deviceId_))
|
||||
if (it->get()->getPort() == Leave.port || (it->get()->getID() == Leave.senderUUID_))
|
||||
{
|
||||
it->get()->getClientSocket()->close();
|
||||
it = localclients.erase(it);
|
||||
@@ -223,9 +223,9 @@ namespace WHISPER {
|
||||
|
||||
}else if(msgType == WHISPER::PING)
|
||||
{
|
||||
if (receivedMessage.deviceId_ != getOwnID() )
|
||||
if (receivedMessage.senderUUID_ != getOwnID() )
|
||||
{
|
||||
WHISPER::Pong pong(getParentID(),getOwnID(),getOwnDeviceType(),ownReceivingPort_);
|
||||
WHISPER::Pong pong(getOwnID(),ownReceivingPort_);
|
||||
this->publish(pong.serialize(),WHISPER::MsgTopicsMap[WHISPER::MsgTopics::MANAGEMENT]);
|
||||
}
|
||||
|
||||
@@ -238,7 +238,7 @@ namespace WHISPER {
|
||||
|
||||
for (auto it = localclients.begin(); it != localclients.end();it++)
|
||||
{
|
||||
if (pong.deviceId_ == it->get()->getID() && pong.parentId_ == it->get()->getParentid())
|
||||
if (pong.senderUUID_ == it->get()->getID() )
|
||||
{
|
||||
it->get()->setLastResponse(std::time(nullptr));
|
||||
}
|
||||
@@ -262,7 +262,7 @@ namespace WHISPER {
|
||||
auto tmpMsg = WHISPER::Message(msg);
|
||||
for (auto it = localclients.begin(); it != localclients.end();it++)
|
||||
{
|
||||
if (tmpMsg.deviceId_ != it->get()->getID())
|
||||
if (tmpMsg.senderUUID_ != it->get()->getID())
|
||||
{
|
||||
zmq::message_t tmp(msg.begin(),msg.end());
|
||||
tmp.set_group(topic.c_str());
|
||||
@@ -317,7 +317,7 @@ namespace WHISPER {
|
||||
|
||||
if (localclients.size() > 0)
|
||||
{
|
||||
WHISPER::Ping ping(getParentID(),getOwnID(),getOwnDeviceType(),port_);
|
||||
WHISPER::Ping ping(getOwnID(),port_);
|
||||
sendToLocalClients(ping.serialize(), WHISPER::MsgTopicsMap[WHISPER::MsgTopics::MANAGEMENT]);
|
||||
|
||||
for (auto it = localclients.begin(); it != localclients.end();it++)
|
||||
|
||||
@@ -12,11 +12,9 @@ namespace WHISPER {
|
||||
try {
|
||||
msg.ParseFromString(receivedMessage);
|
||||
topic_ = msg.topic();
|
||||
sourceType_ = msg.sourcetype();
|
||||
msgType_ = msg.msgtype();
|
||||
joinMessage = messages::join::Join();
|
||||
deviceId_ = msg.sourceid();
|
||||
parentId_ = msg.parentid();
|
||||
this->senderUUID_ = msg.senderuuid();
|
||||
|
||||
|
||||
if (msg.mutable_payload()->Is<messages::join::Join>())
|
||||
@@ -35,8 +33,8 @@ namespace WHISPER {
|
||||
}
|
||||
|
||||
|
||||
WHISPER::Join::Join(std::uint32_t parentID,std::uint32_t deviceID, SourceType src,std::uint32_t port, std::string addr):
|
||||
Message(parentID,deviceID,WHISPER::MsgTopics::MANAGEMENT,WHISPER::JOIN,src),port(port),sourceAddr(addr)
|
||||
WHISPER::Join::Join(std::string senderID, std::uint32_t port, std::string addr):
|
||||
Message(senderID,WHISPER::MsgTopics::MANAGEMENT,WHISPER::JOIN),port(port),sourceAddr(addr)
|
||||
{
|
||||
joinMessage = messages::join::Join();
|
||||
joinMessage.set_port(port);
|
||||
|
||||
@@ -12,9 +12,8 @@ namespace WHISPER {
|
||||
try {
|
||||
msg.ParseFromString(receivedMessage);
|
||||
topic_ = msg.topic();
|
||||
sourceType_ = msg.sourcetype();
|
||||
msgType_ = msg.msgtype();
|
||||
parentId_ = msg.parentid();
|
||||
senderUUID_ = msg.senderuuid();
|
||||
|
||||
leaveMessage = messages::leave::Leave();
|
||||
|
||||
@@ -37,8 +36,8 @@ namespace WHISPER {
|
||||
}
|
||||
|
||||
|
||||
Leave::Leave(std::uint32_t parentID,std::uint32_t deviceID, SourceType src,std::uint32_t port, std::string addr):
|
||||
Message(parentID,deviceID,WHISPER::MsgTopics::MANAGEMENT,WHISPER::LEAVE,src),port(port),sourceAddr(addr)
|
||||
Leave::Leave(std::string senderID, std::uint32_t port, std::string addr):
|
||||
Message(senderID,WHISPER::MsgTopics::MANAGEMENT,WHISPER::LEAVE),port(port),sourceAddr(addr)
|
||||
{
|
||||
|
||||
leaveMessage = messages::leave::Leave();
|
||||
|
||||
@@ -13,12 +13,11 @@ namespace WHISPER {
|
||||
try {
|
||||
msg.ParseFromString(stringMessage);
|
||||
|
||||
deviceId_ = msg.sourceid();
|
||||
topic_ = msg.topic();
|
||||
sourceType_ = msg.sourcetype();
|
||||
msgType_ = msg.msgtype();
|
||||
parentId_ = msg.parentid();
|
||||
|
||||
senderUUID_ = msg.senderuuid();
|
||||
auto ptr = std::make_shared<google::protobuf::Any>();
|
||||
payload_->CopyFrom(*msg.mutable_payload());
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
LOG_S(ERROR)<<e.what();
|
||||
@@ -26,15 +25,14 @@ namespace WHISPER {
|
||||
|
||||
|
||||
}
|
||||
Message::Message(std::string senderUUID, MsgTopics topic, MsgType Type,SourceType src):
|
||||
senderUUID_(senderUUID),topic_(topic),sourceType_(src),msgType_(Type)
|
||||
Message::Message(std::string senderUUID, MsgTopics topic, MsgType Type):
|
||||
senderUUID_(senderUUID),topic_(topic),msgType_(Type)
|
||||
{
|
||||
msg = messages::header::Message();
|
||||
|
||||
if(msg.IsInitialized())
|
||||
{
|
||||
msg.set_topic(topic);
|
||||
msg.set_sourcetype(sourceType_);
|
||||
msg.set_msgtype(msgType_);
|
||||
msg.set_senderuuid(senderUUID_);
|
||||
|
||||
@@ -42,22 +40,22 @@ namespace WHISPER {
|
||||
}
|
||||
|
||||
|
||||
Message::Message(std::uint32_t parentId,std::uint32_t deviceId, MsgTopics topic, MsgType Type,SourceType src):
|
||||
parentId_(parentId),deviceId_(deviceId),topic_(topic),sourceType_(src),msgType_(Type)
|
||||
{
|
||||
msg = messages::header::Message();
|
||||
// Message::Message(std::uint32_t parentId,std::uint32_t deviceId, MsgTopics topic, MsgType Type,SourceType src):
|
||||
// parentId_(parentId),deviceId_(deviceId),topic_(topic),sourceType_(src),msgType_(Type)
|
||||
// {
|
||||
// msg = messages::header::Message();
|
||||
|
||||
if(msg.IsInitialized())
|
||||
{
|
||||
msg.set_sourceid(deviceId);
|
||||
msg.set_topic(topic);
|
||||
msg.set_sourcetype(sourceType_);
|
||||
msg.set_msgtype(msgType_);
|
||||
msg.set_parentid(parentId);
|
||||
// if(msg.IsInitialized())
|
||||
// {
|
||||
// msg.set_sourceid(deviceId);
|
||||
// msg.set_topic(topic);
|
||||
// msg.set_sourcetype(sourceType_);
|
||||
// msg.set_msgtype(msgType_);
|
||||
// msg.set_parentid(parentId);
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,11 +13,9 @@ namespace WHISPER {
|
||||
try {
|
||||
msg.ParseFromString(receivedMessage);
|
||||
topic_ = msg.topic();
|
||||
sourceType_ = msg.sourcetype();
|
||||
msgType_ = msg.msgtype();
|
||||
pingMessage = messages::ping::Ping();
|
||||
deviceId_ = msg.sourceid();
|
||||
parentId_ = msg.parentid();
|
||||
senderUUID_ = msg.senderuuid();
|
||||
|
||||
|
||||
if (msg.mutable_payload()->Is<messages::ping::Ping>())
|
||||
@@ -36,8 +34,8 @@ namespace WHISPER {
|
||||
}
|
||||
|
||||
|
||||
WHISPER::Ping::Ping(std::uint32_t parentID,std::uint32_t deviceID, SourceType src,std::uint32_t port):
|
||||
Message(parentID,deviceID,WHISPER::MsgTopics::MANAGEMENT,WHISPER::PING,src),port_(port)
|
||||
WHISPER::Ping::Ping(std::string senderID, std::uint32_t port):
|
||||
Message(senderID,WHISPER::MsgTopics::MANAGEMENT,WHISPER::PING),port_(port)
|
||||
{
|
||||
pingMessage = messages::ping::Ping();
|
||||
pingMessage.set_port(port_);
|
||||
|
||||
@@ -13,11 +13,9 @@ namespace WHISPER {
|
||||
try {
|
||||
msg.ParseFromString(receivedMessage);
|
||||
topic_ = msg.topic();
|
||||
sourceType_ = msg.sourcetype();
|
||||
msgType_ = msg.msgtype();
|
||||
message_ = messages::pong::Pong();
|
||||
deviceId_ = msg.sourceid();
|
||||
parentId_ = msg.parentid();
|
||||
senderUUID_ = msg.senderuuid();
|
||||
|
||||
if (msg.mutable_payload()->Is<messages::pong::Pong>())
|
||||
{
|
||||
@@ -35,8 +33,8 @@ namespace WHISPER {
|
||||
}
|
||||
|
||||
|
||||
WHISPER::Pong::Pong(std::uint32_t parentID,std::uint32_t deviceID, SourceType src,std::uint32_t port):
|
||||
Message(parentID,deviceID,WHISPER::MsgTopics::MANAGEMENT,WHISPER::PONG,src),port_(port)
|
||||
WHISPER::Pong::Pong(std::string senderID, std::uint32_t port):
|
||||
Message(senderID,WHISPER::MsgTopics::MANAGEMENT,WHISPER::PONG),port_(port)
|
||||
{
|
||||
// message_ = messages::pong::Pong();
|
||||
if (message_.IsInitialized()) {
|
||||
|
||||
@@ -13,11 +13,9 @@ namespace WHISPER {
|
||||
try {
|
||||
msg.ParseFromString(receivedMessage);
|
||||
topic_ = msg.topic();
|
||||
sourceType_ = msg.sourcetype();
|
||||
msgType_ = msg.msgtype();
|
||||
message_ = messages::stringData::StringData();
|
||||
deviceId_ = msg.sourceid();
|
||||
parentId_ = msg.parentid();
|
||||
senderUUID_ = msg.senderuuid();
|
||||
|
||||
|
||||
if (msg.mutable_payload()->Is<messages::stringData::StringData>())
|
||||
@@ -36,8 +34,8 @@ namespace WHISPER {
|
||||
}
|
||||
|
||||
|
||||
WHISPER::StringData::StringData(std::uint32_t parentID,std::uint32_t deviceID, SourceType src,std::string data):
|
||||
Message(parentID,deviceID,WHISPER::MsgTopics::DATA,WHISPER::STRINGDATA,src),data_(data)
|
||||
WHISPER::StringData::StringData(std::string senderID, std::string data):
|
||||
Message(senderID,WHISPER::MsgTopics::DATA,WHISPER::STRINGDATA),data_(data)
|
||||
{
|
||||
message_ = messages::stringData::StringData();
|
||||
message_.set_data(data);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include <WHISPER/localClients.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace WHISPER {
|
||||
|
||||
|
||||
localClient::localClient(std::uint32_t port,std::string addr,std::uint32_t parentid,std::uint32_t id, std::shared_ptr<zmq::socket_t> clientSocket)
|
||||
:port_(port),addr_(addr),parentid_(parentid),id_(id),clientSocket_(clientSocket),mx()
|
||||
localClient::localClient(std::uint32_t port,std::string addr,std::string id, std::shared_ptr<zmq::socket_t> clientSocket)
|
||||
:port_(port),addr_(addr),id_(id),clientSocket_(clientSocket),mx()
|
||||
{
|
||||
lastResponse_ = std::time(nullptr);
|
||||
}
|
||||
@@ -28,12 +29,8 @@ std::string localClient::getAddr()
|
||||
std::lock_guard<std::mutex> lock(mx);
|
||||
return addr_;
|
||||
}
|
||||
std::uint32_t localClient::getParentid()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mx);
|
||||
return parentid_;
|
||||
}
|
||||
std::uint32_t localClient::getID()
|
||||
|
||||
std::string localClient::getID()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mx);
|
||||
return id_;
|
||||
|
||||
@@ -19,15 +19,12 @@
|
||||
namespace WHISPER
|
||||
{
|
||||
|
||||
std::uint32_t whispercomm::getOwnID()
|
||||
std::string whispercomm::getOwnID()
|
||||
{
|
||||
return ownID_;
|
||||
}
|
||||
|
||||
std::uint32_t whispercomm::getParentID()
|
||||
{
|
||||
return parentID_;
|
||||
}
|
||||
|
||||
|
||||
void whispercomm::connect(std::shared_ptr<threadSafeQueue<WHISPER::Message>> receiver)
|
||||
{
|
||||
@@ -111,10 +108,10 @@ namespace WHISPER
|
||||
bool whispercomm::isGateway(){
|
||||
return gateway;
|
||||
}
|
||||
SourceType whispercomm::getOwnDeviceType()
|
||||
{
|
||||
return ownDeviceType_;
|
||||
}
|
||||
// SourceType whispercomm::getOwnDeviceType()
|
||||
// {
|
||||
// return ownDeviceType_;
|
||||
// }
|
||||
|
||||
|
||||
void whispercomm::setConnected(bool val){
|
||||
|
||||
Reference in New Issue
Block a user