Skip to content

Commit f275577

Browse files
yschimkelehecka
authored andcommitted
Receive client setup (#110)
* receive setup frame * cleanup * request handler use value type
1 parent e797f78 commit f275577

12 files changed

+99
-26
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ add_library(
131131
src/Stats.cpp
132132
src/folly/FollyKeepaliveTimer.cpp
133133
src/folly/FollyKeepaliveTimer.h
134-
src/ConnectionSetupPayload.h)
134+
src/ConnectionSetupPayload.h
135+
src/ConnectionSetupPayload.cpp)
135136

136137
target_link_libraries(
137138
ReactiveSocket

src/ConnectionAutomaton.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -180,30 +180,14 @@ void ConnectionAutomaton::onConnectionFrame(
180180
outputFrameOrEnqueue(Frame_ERROR::unexpectedFrame().serializeOut());
181181
disconnect();
182182
}
183-
}
184183
return;
184+
}
185185
case FrameType::SETUP: {
186-
Frame_SETUP frame;
187-
if (frame.deserializeFrom(std::move(payload))) {
188-
if (frame.header_.flags_ & FrameFlags_LEASE) {
189-
// TODO(yschimke) We don't have the correct lease and wait logic above
190-
// yet
191-
LOG(WARNING) << "ignoring setup frame with lease";
192-
// connectionOutput_.onNext(
193-
// Frame_ERROR::badSetupFrame("leases not supported")
194-
// .serializeOut());
195-
// disconnect();
196-
}
197-
} else {
198-
// TODO(yschimke) enable this later after clients upgraded
199-
LOG(WARNING) << "ignoring bad setup frame";
200-
// connectionOutput_.onNext(
201-
// Frame_ERROR::badSetupFrame("bad setup
202-
// frame").serializeOut());
203-
// disconnect();
186+
if (!factory_(0, std::move(payload))) {
187+
assert(false);
204188
}
205-
}
206189
return;
190+
}
207191
case FrameType::METADATA_PUSH: {
208192
if (!factory_(0, std::move(payload))) {
209193
assert(false);
@@ -230,7 +214,8 @@ void ConnectionAutomaton::onTerminal(folly::exception_wrapper ex) {
230214
auto result = endStreamInternal(streams_.begin()->first, signal);
231215
(void)oldSize;
232216
(void)result;
233-
// TODO(stupaq): what kind of a user action could violate these assertions?
217+
// TODO(stupaq): what kind of a user action could violate these
218+
// assertions?
234219
assert(result);
235220
assert(streams_.size() == oldSize - 1);
236221
}

src/ConnectionSetupPayload.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2004-present Facebook. All Rights Reserved.
2+
3+
#include "ConnectionSetupPayload.h"
4+
#include <folly/String.h>
5+
6+
namespace reactivesocket {
7+
std::ostream& operator<<(
8+
std::ostream& os,
9+
const ConnectionSetupPayload& setupPayload) {
10+
return os << "[metadataMimeType: " << setupPayload.metadataMimeType
11+
<< " dataMimeType: " << setupPayload.dataMimeType
12+
<< " payload: " << setupPayload.payload << "]";
13+
}
14+
}

src/ConnectionSetupPayload.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#pragma once
44

5+
#include <folly/io/IOBuf.h>
56
#include <string>
67
#include "Payload.h"
78

@@ -20,4 +21,6 @@ class ConnectionSetupPayload {
2021
std::string dataMimeType;
2122
Payload payload;
2223
};
24+
25+
std::ostream& operator<<(std::ostream&, const ConnectionSetupPayload&);
2326
}

src/NullRequestHandler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,7 @@ void NullRequestHandler::handleFireAndForgetRequest(Payload /*request*/) {}
5050

5151
void NullRequestHandler::handleMetadataPush(
5252
std::unique_ptr<folly::IOBuf> /*request*/) {}
53+
54+
void NullRequestHandler::handleSetupPayload(
55+
ConnectionSetupPayload /*request*/) {}
5356
}

src/NullRequestHandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#pragma once
44

5+
#include "ConnectionSetupPayload.h"
56
#include "src/RequestHandler.h"
67

78
namespace reactivesocket {
@@ -37,6 +38,8 @@ class NullRequestHandler : public RequestHandler {
3738
void handleFireAndForgetRequest(Payload request) override;
3839

3940
void handleMetadataPush(std::unique_ptr<folly::IOBuf> request) override;
41+
42+
void handleSetupPayload(ConnectionSetupPayload request) override;
4043
};
4144

4245
using DefaultRequestHandler = NullRequestHandler;

src/ReactiveSocket.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,34 @@ bool ReactiveSocket::createResponder(
164164
std::unique_ptr<folly::IOBuf> serializedFrame) {
165165
auto type = FrameHeader::peekType(*serializedFrame);
166166
switch (type) {
167+
case FrameType::SETUP: {
168+
Frame_SETUP frame;
169+
if (frame.deserializeFrom(std::move(serializedFrame))) {
170+
if (frame.header_.flags_ & FrameFlags_LEASE) {
171+
// TODO(yschimke) We don't have the correct lease and wait logic above
172+
// yet
173+
LOG(WARNING) << "ignoring setup frame with lease";
174+
// connectionOutput_.onNext(
175+
// Frame_ERROR::badSetupFrame("leases not supported")
176+
// .serializeOut());
177+
// disconnect();
178+
}
179+
180+
handler_->handleSetupPayload(ConnectionSetupPayload(
181+
std::move(frame.metadataMimeType_),
182+
std::move(frame.dataMimeType_),
183+
std::move(frame.payload_)));
184+
} else {
185+
// TODO(yschimke) enable this later after clients upgraded
186+
LOG(WARNING) << "ignoring bad setup frame";
187+
// connectionOutput_.onNext(
188+
// Frame_ERROR::badSetupFrame("bad setup
189+
// frame").serializeOut());
190+
// disconnect();
191+
}
192+
193+
break;
194+
}
167195
case FrameType::REQUEST_CHANNEL: {
168196
Frame_REQUEST_CHANNEL frame;
169197
if (!frame.deserializeFrom(std::move(serializedFrame))) {

src/RequestHandler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#pragma once
44

5+
#include "ConnectionSetupPayload.h"
56
#include "src/Payload.h"
67
#include "src/ReactiveStreamsCompat.h"
78

@@ -34,5 +35,9 @@ class RequestHandler {
3435

3536
/// Handles a new metadata-push sent by the other end.
3637
virtual void handleMetadataPush(std::unique_ptr<folly::IOBuf> request) = 0;
38+
39+
/// Temporary home - this should eventually be an input to asking for a
40+
/// RequestHandler so negotiation is possible
41+
virtual void handleSetupPayload(ConnectionSetupPayload request) = 0;
3742
};
3843
}

tck-test/client.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ int main(int argc, char* argv[]) {
9393
folly::make_unique<DefaultRequestHandler>();
9494

9595
reactiveSocket = ReactiveSocket::fromClientConnection(
96-
std::move(framedConnection),
97-
std::move(requestHandler));
96+
std::move(framedConnection), std::move(requestHandler));
9897
});
9998

10099
LOG(INFO) << "Test file parsed. Starting executing tests...";

test/MockRequestHandler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class MockRequestHandler : public RequestHandler {
2626
MOCK_METHOD1(
2727
handleMetadataPush_,
2828
void(std::unique_ptr<folly::IOBuf>& request));
29+
MOCK_METHOD1(handleSetupPayload_, void(ConnectionSetupPayload& request));
2930

3031
Subscriber<Payload>& handleRequestChannel(
3132
Payload request,
@@ -50,5 +51,9 @@ class MockRequestHandler : public RequestHandler {
5051
void handleMetadataPush(std::unique_ptr<folly::IOBuf> request) override {
5152
handleMetadataPush_(request);
5253
}
54+
55+
void handleSetupPayload(ConnectionSetupPayload request) override {
56+
handleSetupPayload_(request);
57+
}
5358
};
5459
}

0 commit comments

Comments
 (0)