Skip to content

Commit

Permalink
Merge branch 'testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
hfedcba committed Jun 22, 2018
2 parents c95cdf6 + b44bfb5 commit 3b21c4b
Show file tree
Hide file tree
Showing 17 changed files with 551 additions and 421 deletions.
2 changes: 1 addition & 1 deletion misc/State Directory/node-blue/www/red/main.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion misc/State Directory/node-blue/www/red/red.js
Original file line number Diff line number Diff line change
Expand Up @@ -12860,7 +12860,7 @@ RED.view = (function() {
if(j != 0) types += ", ";
types += inputInfo.types[j];
}
types = "</i></p>";
types += "</i></p>";
content = infoBody;
}
}
Expand Down
2 changes: 1 addition & 1 deletion misc/State Directory/node-blue/www/red/red.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion misc/State Directory/node-blue/www/red/style.min.css

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/IPC/IpcServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ IpcServer::IpcServer() : IQueue(GD::bl.get(), 3, 100000)
_rpcMethods.emplace("getVariableDescription", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCGetVariableDescription()));
_rpcMethods.emplace("getVersion", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCGetVersion()));
_rpcMethods.emplace("init", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCInit()));
_rpcMethods.emplace("invokeFamilyMethod", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCInvokeFamilyMethod()));
_rpcMethods.emplace("listBidcosInterfaces", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCListBidcosInterfaces()));
_rpcMethods.emplace("listClientServers", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCListClientServers()));
_rpcMethods.emplace("listDevices", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCListDevices()));
Expand Down Expand Up @@ -644,7 +645,7 @@ BaseLib::PVariable IpcServer::callRpcMethod(BaseLib::PRpcClientInfo clientInfo,
{
try
{
if(!clientInfo || !clientInfo->acls->checkMethodAccess(methodName)) return BaseLib::Variable::createError(-32011, "Unauthorized.");
if(!clientInfo || !clientInfo->acls->checkMethodAccess(methodName)) return BaseLib::Variable::createError(-32603, "Unauthorized.");

PIpcClientData clientData;
{
Expand Down
1 change: 1 addition & 0 deletions src/Node-BLUE/NodeBlueServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ NodeBlueServer::NodeBlueServer() : IQueue(GD::bl.get(), 3, 100000)
_rpcMethods.emplace("getVariableDescription", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCGetVariableDescription()));
_rpcMethods.emplace("getVersion", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCGetVersion()));
_rpcMethods.emplace("init", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCInit()));
_rpcMethods.emplace("invokeFamilyMethod", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCInvokeFamilyMethod()));
_rpcMethods.emplace("listBidcosInterfaces", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCListBidcosInterfaces()));
_rpcMethods.emplace("listClientServers", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCListClientServers()));
_rpcMethods.emplace("listDevices", std::shared_ptr<BaseLib::Rpc::RpcMethod>(new Rpc::RPCListDevices()));
Expand Down
25 changes: 13 additions & 12 deletions src/RPC/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void Client::initServerMethods(std::pair<std::string, std::string> address)
GD::out.printInfo("Info: Calling init methods on server \"" + address.first + "\".");
std::shared_ptr<RemoteRpcServer> server = getServer(address);
if(!server) return; //server is empty when connection timed out

//Wait a little before sending these methods, CCU needs pretty long, before it accepts the request
if(server->type == BaseLib::RpcClientType::ccu2) std::this_thread::sleep_for(std::chrono::milliseconds(20000));
else std::this_thread::sleep_for(std::chrono::milliseconds(500));
Expand Down Expand Up @@ -213,7 +214,7 @@ void Client::broadcastNodeEvent(std::string& nodeId, std::string& topic, BaseLib
for(std::map<int32_t, std::shared_ptr<RemoteRpcServer>>::const_iterator server = _servers.begin(); server != _servers.end(); ++server)
{
if(!server->second->nodeEvents) continue;
if(server->second->removed || (server->second->getServerClientInfo()->sendEventsToRpcServer && !server->second->getServerClientInfo()->socket->connected()) || (server->second->socket && !server->second->socket->connected() && server->second->keepAlive && !server->second->reconnectInfinitely) || (!server->second->initialized && BaseLib::HelperFunctions::getTimeSeconds() - server->second->creationTime > 120)) continue;
if(server->second->removed || server->second->getServerClientInfo()->closed || (server->second->getServerClientInfo()->sendEventsToRpcServer && !server->second->getServerClientInfo()->socket->connected()) || (server->second->socket && !server->second->socket->connected() && server->second->keepAlive && !server->second->reconnectInfinitely) || (!server->second->initialized && BaseLib::HelperFunctions::getTimeSeconds() - server->second->creationTime > 120)) continue;
if(!server->second->getServerClientInfo()->acls->checkEventServerMethodAccess("nodeEvent")) continue;
if(server->second->webSocket || server->second->json)
{
Expand Down Expand Up @@ -279,7 +280,7 @@ void Client::broadcastEvent(uint64_t id, int32_t channel, std::string deviceAddr
std::lock_guard<std::mutex> serversGuard(_serversMutex);
for(std::map<int32_t, std::shared_ptr<RemoteRpcServer>>::const_iterator server = _servers.begin(); server != _servers.end(); ++server)
{
if(server->second->removed || (server->second->getServerClientInfo()->sendEventsToRpcServer && !server->second->getServerClientInfo()->socket->connected()) || (server->second->socket && !server->second->socket->connected() && server->second->keepAlive && !server->second->reconnectInfinitely) || (!server->second->initialized && BaseLib::HelperFunctions::getTimeSeconds() - server->second->creationTime > 120)) continue;
if(server->second->removed || server->second->getServerClientInfo()->closed || (server->second->getServerClientInfo()->sendEventsToRpcServer && !server->second->getServerClientInfo()->socket->connected()) || (server->second->socket && !server->second->socket->connected() && server->second->keepAlive && !server->second->reconnectInfinitely) || (!server->second->initialized && BaseLib::HelperFunctions::getTimeSeconds() - server->second->creationTime > 120)) continue;
if((!server->second->initialized && valueKeys->at(0) != "PONG") || (!server->second->knownMethods.empty() && (server->second->knownMethods.find("event") == server->second->knownMethods.end() || server->second->knownMethods.find("system.multicall") == server->second->knownMethods.end()))) continue;
if(!server->second->getServerClientInfo()->acls->checkEventServerMethodAccess("event")) continue;
if(id > 0 && server->second->subscribePeers && server->second->subscribedPeers.find(id) == server->second->subscribedPeers.end()) continue;
Expand Down Expand Up @@ -403,18 +404,18 @@ void Client::broadcastEvent(uint64_t id, int32_t channel, std::string deviceAddr
}
}

void Client::systemListMethods(std::pair<std::string, std::string> address)
void Client::systemListMethods(std::pair<std::string, std::string>& address)
{
try
{
std::shared_ptr<RemoteRpcServer> server = getServer(address);
if(!server) return;
std::shared_ptr<std::list<BaseLib::PVariable>> parameters(new std::list<BaseLib::PVariable> {});
std::shared_ptr<std::list<BaseLib::PVariable>> parameters(new std::list<BaseLib::PVariable> { std::make_shared<BaseLib::Variable>(server->id) });
std::string methodName = "system.listMethods";
BaseLib::PVariable result = server->invoke(methodName, parameters);
if(result->errorStruct)
{
if(server->removed || (server->socket && !server->socket->connected() && server->keepAlive && !server->reconnectInfinitely)) return;
if(server->removed || server->getServerClientInfo()->closed || (server->socket && !server->socket->connected() && server->keepAlive && !server->reconnectInfinitely)) return;
GD::out.printWarning("Warning: Error calling XML RPC method \"system.listMethods\" on server " + address.first + " with port " + address.second + ". Error struct: ");
result->print(true, false);
return;
Expand Down Expand Up @@ -457,7 +458,7 @@ void Client::systemListMethods(std::pair<std::string, std::string> address)
}
}

void Client::listDevices(std::pair<std::string, std::string> address)
void Client::listDevices(std::pair<std::string, std::string>& address)
{
try
{
Expand All @@ -470,7 +471,7 @@ void Client::listDevices(std::pair<std::string, std::string> address)
BaseLib::PVariable result = server->invoke(methodName, parameters);
if(result->errorStruct)
{
if(server->removed || (server->socket && !server->socket->connected() && server->keepAlive && !server->reconnectInfinitely)) return;
if(server->removed || server->getServerClientInfo()->closed || (server->socket && !server->socket->connected() && server->keepAlive && !server->reconnectInfinitely)) return;
GD::out.printError("Error calling XML RPC method \"listDevices\" on server " + address.first + " with port " + address.second + ". Error struct: ");
result->print(true, false);
return;
Expand Down Expand Up @@ -526,7 +527,7 @@ void Client::listDevices(std::pair<std::string, std::string> address)
}
}

void Client::sendUnknownDevices(std::pair<std::string, std::string> address)
void Client::sendUnknownDevices(std::pair<std::string, std::string>& address)
{
try
{
Expand All @@ -552,7 +553,7 @@ void Client::sendUnknownDevices(std::pair<std::string, std::string> address)
BaseLib::PVariable result = server->invoke(methodName, parameters);
if(result->errorStruct)
{
if(server->removed) return;
if(server->removed || server->getServerClientInfo()->closed) return;
GD::out.printError("Error calling XML RPC method \"newDevices\" on server " + address.first + " with port " + address.second + ". Error struct: ");
result->print(true, false);
return;
Expand Down Expand Up @@ -930,7 +931,7 @@ void Client::collectGarbage()
_lastGarbageCollection = BaseLib::HelperFunctions::getTime();
for(std::map<int32_t, std::shared_ptr<RemoteRpcServer>>::const_iterator i = _servers.begin(); i != _servers.end(); ++i)
{
if(i->second->removed || (i->second->socket && !i->second->socket->connected() && i->second->keepAlive && !i->second->reconnectInfinitely) || (!i->second->initialized && now - i->second->creationTime > 120))
if(i->second->removed || i->second->getServerClientInfo()->closed || (i->second->getServerClientInfo()->sendEventsToRpcServer && !i->second->getServerClientInfo()->socket->connected()) || (i->second->socket && !i->second->socket->connected() && i->second->keepAlive && !i->second->reconnectInfinitely) || (!i->second->initialized && now - i->second->creationTime > 120))
{
if(i->second->socket) i->second->socket->close();
serversToRemove.push_back(i->first);
Expand Down Expand Up @@ -1325,7 +1326,7 @@ BaseLib::PVariable Client::listClientServers(std::string id)
std::lock_guard<std::mutex> serversGuard(_serversMutex);
for(std::map<int32_t, std::shared_ptr<RemoteRpcServer>>::const_iterator i = _servers.begin(); i != _servers.end(); ++i)
{
if(i->second->removed) continue;
if(i->second->removed || i->second->getServerClientInfo()->closed) continue;
if(!id.empty() && i->second->id != id) continue;
servers.push_back(i->second);
}
Expand Down Expand Up @@ -1382,7 +1383,7 @@ BaseLib::PVariable Client::clientServerInitialized(std::string id)
{
if(i->second->id == id)
{
if(i->second->removed) continue;
if(i->second->removed || i->second->getServerClientInfo()->closed) continue;
else initialized = true;
return BaseLib::PVariable(new BaseLib::Variable(initialized));
}
Expand Down
6 changes: 3 additions & 3 deletions src/RPC/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ class Client
void initServerMethods(std::pair<std::string, std::string> address);
void broadcastNodeEvent(std::string& nodeId, std::string& topic, BaseLib::PVariable& value);
void broadcastEvent(uint64_t id, int32_t channel, std::string deviceAddress, std::shared_ptr<std::vector<std::string>> valueKeys, std::shared_ptr<std::vector<BaseLib::PVariable>> values);
void systemListMethods(std::pair<std::string, std::string> address);
void listDevices(std::pair<std::string, std::string> address);
void systemListMethods(std::pair<std::string, std::string>& address);
void listDevices(std::pair<std::string, std::string>& address);
void broadcastError(int32_t level, std::string message);
void broadcastNewDevices(std::vector<uint64_t>& ids, BaseLib::PVariable deviceDescriptions);
void broadcastNewEvent(BaseLib::PVariable eventDescription);
void broadcastDeleteDevices(std::vector<uint64_t>& ids, BaseLib::PVariable deviceAddresses, BaseLib::PVariable deviceInfo);
void broadcastDeleteEvent(std::string id, int32_t type, uint64_t peerID, int32_t channel, std::string variable);
void broadcastUpdateDevice(uint64_t id, int32_t channel, std::string address, Hint::Enum hint);
void broadcastUpdateEvent(std::string id, int32_t type, uint64_t peerID, int32_t channel, std::string variable);
void sendUnknownDevices(std::pair<std::string, std::string> address);
void sendUnknownDevices(std::pair<std::string, std::string>& address);
void sendError(std::pair<std::string, std::string> address, int32_t level, std::string message);
std::shared_ptr<RemoteRpcServer> addServer(std::pair<std::string, std::string> address, BaseLib::PRpcClientInfo clientInfo, std::string path, std::string id);
std::shared_ptr<RemoteRpcServer> addSingleConnectionServer(std::pair<std::string, std::string> address, BaseLib::PRpcClientInfo clientInfo, std::string id);
Expand Down

0 comments on commit 3b21c4b

Please sign in to comment.