Skip to content

Commit

Permalink
include from id on accept requests (#47895)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkarneges authored Jan 26, 2024
1 parent 0cca88e commit 54b0c4e
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/cpp/handler/handlerengine.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2015-2023 Fanout, Inc.
* Copyright (C) 2023 Fastly, Inc.
* Copyright (C) 2023-2024 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand Down Expand Up @@ -963,11 +963,13 @@ class AcceptWorker : public Deferred
return;
}

QByteArray reqFrom = req->from();

QVariantHash result;
result["accepted"] = true;
req->respond(result);

log_debug("accepting %d requests", requestStates.count());
log_debug("accepting %d requests from %s", requestStates.count(), reqFrom.data());

if(instruct.holdMode == Instruct::ResponseHold)
{
Expand Down
12 changes: 12 additions & 0 deletions src/cpp/packet/zrpcrequestpacket.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014 Fanout, Inc.
* Copyright (C) 2024 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand All @@ -26,6 +27,9 @@ QVariant ZrpcRequestPacket::toVariant() const
{
QVariantHash obj;

if(!from.isEmpty())
obj["from"] = from;

if(!id.isEmpty())
obj["id"] = id;

Expand All @@ -44,6 +48,14 @@ bool ZrpcRequestPacket::fromVariant(const QVariant &in)

QVariantHash obj = in.toHash();

if(obj.contains("from"))
{
if(obj["from"].type() != QVariant::ByteArray)
return false;

from = obj["from"].toByteArray();
}

if(obj.contains("id"))
{
if(obj["id"].type() != QVariant::ByteArray)
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/packet/zrpcrequestpacket.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014 Fanout, Inc.
* Copyright (C) 2024 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand Down Expand Up @@ -29,6 +30,7 @@
class ZrpcRequestPacket
{
public:
QByteArray from;
QByteArray id;
QString method;
QVariantHash args;
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/proxy/engine.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2012-2023 Fanout, Inc.
* Copyright (C) 2023 Fastly, Inc.
* Copyright (C) 2023-2024 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand Down Expand Up @@ -257,6 +257,7 @@ class Engine::Private : public QObject
if(!config.acceptSpec.isEmpty())
{
accept = new ZrpcManager(this);
accept->setInstanceId(config.clientId);
accept->setBind(true);
accept->setIpcFileMode(config.ipcFileMode);
if(!accept->setClientSpecs(QStringList() << config.acceptSpec))
Expand Down
12 changes: 11 additions & 1 deletion src/cpp/zrpcmanager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014-2016 Fanout, Inc.
* Copyright (C) 2024 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand Down Expand Up @@ -56,6 +57,7 @@ class ZrpcManager::Private : public QObject
};

ZrpcManager *q;
QByteArray instanceId;
int ipcFileMode;
bool doBind;
int timeout;
Expand Down Expand Up @@ -142,7 +144,10 @@ class ZrpcManager::Private : public QObject
{
assert(clientSock);

QVariant vpacket = packet.toVariant();
ZrpcRequestPacket p = packet;
p.from = instanceId;

QVariant vpacket = p.toVariant();
QByteArray buf = TnetString::fromVariant(vpacket);

if(log_outputLevel() >= LOG_LEVEL_DEBUG)
Expand Down Expand Up @@ -264,6 +269,11 @@ int ZrpcManager::timeout() const
return d->timeout;
}

void ZrpcManager::setInstanceId(const QByteArray &instanceId)
{
d->instanceId = instanceId;
}

void ZrpcManager::setIpcFileMode(int mode)
{
d->ipcFileMode = mode;
Expand Down
3 changes: 2 additions & 1 deletion src/cpp/zrpcmanager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014 Fanout, Inc.
* Copyright (C) 2023 Fastly, Inc.
* Copyright (C) 2023-2024 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand Down Expand Up @@ -43,6 +43,7 @@ class ZrpcManager : public QObject

int timeout() const;

void setInstanceId(const QByteArray &instanceId);
void setIpcFileMode(int mode);
void setBind(bool enable);
void setTimeout(int ms);
Expand Down
8 changes: 8 additions & 0 deletions src/cpp/zrpcrequest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014-2015 Fanout, Inc.
* Copyright (C) 2024 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand Down Expand Up @@ -38,6 +39,7 @@ class ZrpcRequest::Private : public QObject
ZrpcRequest *q;
ZrpcManager *manager;
QList<QByteArray> reqHeaders;
QByteArray from;
QByteArray id;
QString method;
QVariantHash args;
Expand Down Expand Up @@ -101,6 +103,7 @@ class ZrpcRequest::Private : public QObject
void handle(const QList<QByteArray> &headers, const ZrpcRequestPacket &packet)
{
reqHeaders = headers;
from = packet.from;
id = packet.id;
method = packet.method;
args = packet.args;
Expand Down Expand Up @@ -189,6 +192,11 @@ ZrpcRequest::~ZrpcRequest()
delete d;
}

QByteArray ZrpcRequest::from() const
{
return d->from;
}

QByteArray ZrpcRequest::id() const
{
return d->id;
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/zrpcrequest.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2014-2015 Fanout, Inc.
* Copyright (C) 2024 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand Down Expand Up @@ -49,6 +50,7 @@ class ZrpcRequest : public QObject
ZrpcRequest(ZrpcManager *manager, QObject *parent = 0);
~ZrpcRequest();

QByteArray from() const;
QByteArray id() const;
QString method() const;
QVariantHash args() const;
Expand Down

0 comments on commit 54b0c4e

Please sign in to comment.