mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 05:17:13 +02:00
703rc/fix port size (#802)
* validate port numbers in client * validate port numbers created at virtual servers and receiver process as tcp ports
This commit is contained in:
@ -108,6 +108,9 @@ void Detector::setHostname(const std::vector<std::string> &hostname) {
|
||||
}
|
||||
|
||||
void Detector::setVirtualDetectorServers(int numServers, int startingPort) {
|
||||
for (int i = 0; i != numServers; ++i) {
|
||||
validatePortNumber(startingPort + i * 2);
|
||||
}
|
||||
pimpl->setVirtualDetectorServers(numServers, startingPort);
|
||||
}
|
||||
|
||||
@ -1087,12 +1090,13 @@ Result<int> Detector::getDestinationUDPPort(Positions pos) const {
|
||||
|
||||
void Detector::setDestinationUDPPort(int port, int module_id) {
|
||||
if (module_id == -1) {
|
||||
std::vector<int> port_list = getPortNumbers(port);
|
||||
std::vector<int> port_list = getValidPortNumbers(port);
|
||||
for (int idet = 0; idet < size(); ++idet) {
|
||||
pimpl->Parallel(&Module::setDestinationUDPPort, {idet},
|
||||
port_list[idet]);
|
||||
}
|
||||
} else {
|
||||
validatePortNumber(port);
|
||||
pimpl->Parallel(&Module::setDestinationUDPPort, {module_id}, port);
|
||||
}
|
||||
}
|
||||
@ -1103,12 +1107,13 @@ Result<int> Detector::getDestinationUDPPort2(Positions pos) const {
|
||||
|
||||
void Detector::setDestinationUDPPort2(int port, int module_id) {
|
||||
if (module_id == -1) {
|
||||
std::vector<int> port_list = getPortNumbers(port);
|
||||
std::vector<int> port_list = getValidPortNumbers(port);
|
||||
for (int idet = 0; idet < size(); ++idet) {
|
||||
pimpl->Parallel(&Module::setDestinationUDPPort2, {idet},
|
||||
port_list[idet]);
|
||||
}
|
||||
} else {
|
||||
validatePortNumber(port);
|
||||
pimpl->Parallel(&Module::setDestinationUDPPort2, {module_id}, port);
|
||||
}
|
||||
}
|
||||
@ -1220,9 +1225,11 @@ void Detector::setRxPort(int port, int module_id) {
|
||||
it = port++;
|
||||
}
|
||||
for (int idet = 0; idet < size(); ++idet) {
|
||||
validatePortNumber(port_list[idet]);
|
||||
pimpl->Parallel(&Module::setReceiverPort, {idet}, port_list[idet]);
|
||||
}
|
||||
} else {
|
||||
validatePortNumber(port);
|
||||
pimpl->Parallel(&Module::setReceiverPort, {module_id}, port);
|
||||
}
|
||||
}
|
||||
@ -1420,12 +1427,13 @@ void Detector::setRxZmqPort(int port, int module_id) {
|
||||
bool previouslyReceiverStreaming =
|
||||
getRxZmqDataStream(std::vector<int>{module_id}).squash(false);
|
||||
if (module_id == -1) {
|
||||
std::vector<int> port_list = getPortNumbers(port);
|
||||
std::vector<int> port_list = getValidPortNumbers(port);
|
||||
for (int idet = 0; idet < size(); ++idet) {
|
||||
pimpl->Parallel(&Module::setReceiverStreamingPort, {idet},
|
||||
port_list[idet]);
|
||||
}
|
||||
} else {
|
||||
validatePortNumber(port);
|
||||
pimpl->Parallel(&Module::setReceiverStreamingPort, {module_id}, port);
|
||||
}
|
||||
if (previouslyReceiverStreaming) {
|
||||
@ -1454,12 +1462,13 @@ Result<int> Detector::getClientZmqPort(Positions pos) const {
|
||||
void Detector::setClientZmqPort(int port, int module_id) {
|
||||
bool previouslyClientStreaming = pimpl->getDataStreamingToClient();
|
||||
if (module_id == -1) {
|
||||
std::vector<int> port_list = getPortNumbers(port);
|
||||
std::vector<int> port_list = getValidPortNumbers(port);
|
||||
for (int idet = 0; idet < size(); ++idet) {
|
||||
pimpl->Parallel(&Module::setClientStreamingPort, {idet},
|
||||
port_list[idet]);
|
||||
}
|
||||
} else {
|
||||
validatePortNumber(port);
|
||||
pimpl->Parallel(&Module::setClientStreamingPort, {module_id}, port);
|
||||
}
|
||||
if (previouslyClientStreaming) {
|
||||
@ -2463,6 +2472,7 @@ Result<int> Detector::getControlPort(Positions pos) const {
|
||||
}
|
||||
|
||||
void Detector::setControlPort(int value, Positions pos) {
|
||||
validatePortNumber(value);
|
||||
pimpl->Parallel(&Module::setControlPort, pos, value);
|
||||
}
|
||||
|
||||
@ -2471,6 +2481,7 @@ Result<int> Detector::getStopPort(Positions pos) const {
|
||||
}
|
||||
|
||||
void Detector::setStopPort(int value, Positions pos) {
|
||||
validatePortNumber(value);
|
||||
pimpl->Parallel(&Module::setStopPort, pos, value);
|
||||
}
|
||||
|
||||
@ -2505,13 +2516,17 @@ Result<ns> Detector::getMeasurementTime(Positions pos) const {
|
||||
|
||||
std::string Detector::getUserDetails() const { return pimpl->getUserDetails(); }
|
||||
|
||||
std::vector<int> Detector::getPortNumbers(int start_port) {
|
||||
std::vector<int> Detector::getValidPortNumbers(int start_port) {
|
||||
int num_sockets_per_detector = getNumberofUDPInterfaces({}).tsquash(
|
||||
"Number of UDP Interfaces is not consistent among modules");
|
||||
std::vector<int> res;
|
||||
res.reserve(size());
|
||||
for (int idet = 0; idet < size(); ++idet) {
|
||||
res.push_back(start_port + (idet * num_sockets_per_detector));
|
||||
int port = start_port + (idet * num_sockets_per_detector);
|
||||
for (int i = 0; i != num_sockets_per_detector; ++i) {
|
||||
validatePortNumber(port + i);
|
||||
}
|
||||
res.push_back(port);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -288,6 +288,7 @@ void DetectorImpl::addModule(const std::string &hostname) {
|
||||
if (res.size() > 1) {
|
||||
host = res[0];
|
||||
port = StringTo<int>(res[1]);
|
||||
validatePortNumber(port);
|
||||
}
|
||||
|
||||
if (host != "localhost") {
|
||||
|
@ -1350,7 +1350,9 @@ void Module::setReceiverHostname(const std::string &receiverIP,
|
||||
auto res = split(host, ':');
|
||||
if (res.size() > 1) {
|
||||
host = res[0];
|
||||
shm()->rxTCPPort = std::stoi(res[1]);
|
||||
int port = StringTo<int>(res[1]);
|
||||
validatePortNumber(port);
|
||||
shm()->rxTCPPort = port;
|
||||
}
|
||||
strcpy_safe(shm()->rxHostname, host.c_str());
|
||||
shm()->useReceiverFlag = true;
|
||||
|
Reference in New Issue
Block a user