server search response delay

This commit is contained in:
Matej Sekoranja
2014-11-24 11:00:04 +01:00
parent d654738dc5
commit 5a6b681bf7
4 changed files with 44 additions and 6 deletions

View File

@@ -26,7 +26,7 @@
// TODO to be generated, etc.
#define EPICS_PVA_MAJOR_VERSION 4
#define EPICS_PVA_MINOR_VERSION 0
#define EPICS_PVA_MAINTENANCE_VERSION 2
#define EPICS_PVA_MAINTENANCE_VERSION 3
#define EPICS_PVA_DEVELOPMENT_FLAG 0
namespace epics {

View File

@@ -14,6 +14,8 @@
#endif
#include <sstream>
#include <time.h>
#include <stdlib.h>
#include <pv/responseHandlers.h>
#include <pv/remote.h>
@@ -27,8 +29,6 @@
#include <osiProcess.h>
#include <pv/logger.h>
#include <sstream>
#include <pv/pvAccessMB.h>
#include <pv/rpcServer.h>
#include <pv/security.h>
@@ -206,6 +206,8 @@ std::string ServerSearchHandler::SUPPORTED_PROTOCOL = "tcp";
ServerSearchHandler::ServerSearchHandler(ServerContextImpl::shared_pointer const & context) :
AbstractServerResponseHandler(context, "Search request"), _providers(context->getChannelProviders())
{
// initialize random seed with some random value
srand ( time(NULL) );
}
void ServerSearchHandler::handleResponse(osiSockAddr* responseFrom,
@@ -254,8 +256,11 @@ void ServerSearchHandler::handleResponse(osiSockAddr* responseFrom,
transport->ensureData(2);
const int32 count = payloadBuffer->getShort() & 0xFFFF;
// TODO DoS attack?
const bool responseRequired = (QOS_REPLY_REQUIRED & qosCode) != 0;
// TODO bloom filter or similar server selection (by GUID)
//
// locally broadcast if unicast (qosCode & 0x80 == 0x80)
//
@@ -306,12 +311,17 @@ void ServerSearchHandler::handleResponse(osiSockAddr* responseFrom,
{
if (allowed)
{
// TODO constant
#define MAX_SERVER_SEARCH_RESPONSE_DELAY_MS 100
double period = (rand() % MAX_SERVER_SEARCH_RESPONSE_DELAY_MS)/(double)1000;
ServerChannelFindRequesterImpl* pr = new ServerChannelFindRequesterImpl(_context, 1);
pr->set("", searchSequenceId, 0, responseAddress, true, true);
// TODO use std::make_shared
std::tr1::shared_ptr<ServerChannelFindRequesterImpl> tp(pr);
ChannelFindRequester::shared_pointer spr = tp;
spr->channelFindResult(Status::Ok, ChannelFind::shared_pointer(), false);
TimerCallback::shared_pointer tc = tp;
_context->getTimer()->scheduleAfterDelay(tc, period);
}
}
}
@@ -335,6 +345,16 @@ void ServerChannelFindRequesterImpl::clear()
_serverSearch = false;
}
void ServerChannelFindRequesterImpl::callback()
{
channelFindResult(Status::Ok, ChannelFind::shared_pointer(), false);
}
void ServerChannelFindRequesterImpl::timerStopped()
{
// noop
}
ServerChannelFindRequesterImpl* ServerChannelFindRequesterImpl::set(std::string name, int32 searchSequenceId, int32 cid, osiSockAddr const & sendTo,
bool responseRequired, bool serverSearch)
{

View File

@@ -7,6 +7,8 @@
#ifndef RESPONSEHANDLERS_H_
#define RESPONSEHANDLERS_H_
#include <pv/timer.h>
#include <pv/serverContext.h>
#include <pv/remote.h>
#include <pv/serverChannelImpl.h>
@@ -161,6 +163,7 @@ namespace pvAccess {
class ServerChannelFindRequesterImpl:
public ChannelFindRequester,
public TransportSender,
public epics::pvData::TimerCallback,
public std::tr1::enable_shared_from_this<ServerChannelFindRequesterImpl>
{
public:
@@ -170,9 +173,14 @@ namespace pvAccess {
ServerChannelFindRequesterImpl* set(std::string _name, epics::pvData::int32 searchSequenceId,
epics::pvData::int32 cid, osiSockAddr const & sendTo, bool responseRequired, bool serverSearch);
void channelFindResult(const epics::pvData::Status& status, ChannelFind::shared_pointer const & channelFind, bool wasFound);
void lock();
void lock();
void unlock();
void send(epics::pvData::ByteBuffer* buffer, TransportSendControl* control);
void callback();
void timerStopped();
private:
GUID _guid;
std::string _name;

View File

@@ -76,6 +76,16 @@ const Version& ServerContextImpl::getVersion()
return ServerContextImpl::VERSION;
}
/*
#ifdef WIN32
UUID uuid;
UuidCreate ( &uuid );
#else
uuid_t uuid;
uuid_generate_random ( uuid );
#endif
*/
void ServerContextImpl::generateGUID()
{
// TODO use UUID