<div dir="ltr"><div> <br>Ed,<br><br>Thank you so much for quick response. <br><br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> 1) Create StreamSocketRule and StreamSocket classes as like as websocket<br>
> 2) Add one more RuleParameterTraits for StreamSocketTwo ways to invoke this new class -<br>
> 1) Create static bmcweb route for each logservice with dump uri with specific rule trait for streamsocket<br>
> eg:<br>
> BMCWEB_ROUTE(app, "/system/LogServices/Dump/attachment/<str>",id)<br>
> .privileges({"ConfigureComponents", "ConfigureManager"})<br>
> .streamsocket()<br>
<br>
I'd much rather call it "dyamicResponse" and have it take 3 callables,<br>
one for onRequest, that accepts a Request and a Response object, like<br>
a normal handler, one for onData, that accepts a buffer of the body<br>
data, and one for onClose, that informs the calling code the socket<br>
was closed.</blockquote><div> <br> <br>Exactly, we thought to implement 4 callables in new rule class similar to websocket<br> OnOpen(),OnMessage(),OnClose(),OnError() . We can use names as suggested. <br><br>Dump dump offload happens using NBD protocol, it's like NBD over http.<br>In this streaming use-case, data will be bidirectional as there will be nbd acknowledgement <br>for each nbd packet transferred to client. so thought to use "StreamSocket" name. <br><br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> 2) Create another redfish node class(as the existing node class is for dynamic route) </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">which would call app.route with the streamSocket trait.Do you have any preference here?handleUpgrade() of router class gets invoked in the following conditions -<br>
<br>
The Redfish Node class is specifically for request->response type<br>
operations, and in the long run, I'd really like to see it just go<br>
away. Today, it doesn't do anything more than the underlying router<br>
already does, and is missing a number of things, like typesafe<br>
parameter parsing, as well as copy-less parameters. If it were me, I<br>
would simply model your dynamic responses around BMCWEB_ROUTE </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> a)request contains http header(upgrade:websocket)<br>
> b)request contains http header (accept: text/event-stream) ---> yet to be upstreamedIn our use case for dump stream, we do not need to take this decision by looking at the request header as the URL is already registered with their associated rule(StreamSocketRule) class.When we search in the trie for a specific URL, we will get the associated rule class object, which in our case would be StreamSocketRule and the handle function of this class should make sure that socket is not closed.<br>
> Is my understanding correct understanding or do you have more suggestion on this?There is an active discussion going on in the following commit for the same.<br>
> <a href="https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/36038" rel="noreferrer" target="_blank">https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/36038</a><br>
<br>
I think you've described what bmcweb does today. In this case, we<br>
might want to just promote an "isUpgrade" method from the app, that we<br>
can use to determine if a given route is dynamic or not, and call into<br>
the correct "handleStream" operator. Keep in mind that at some point<br>
you need to transfer control back to httpConnection to handle<br>
keepalive properly.<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thinking about keepalive more gave me another thought: This isn't<br>
really an "upgrade" in the normal sense. What if we just added a<br>
"write" method to the Response object that immediately wrote the<br>
payload to the dynamic body and sent it? write() could return an<br>
error code in the cases where the client has disconnected, and we<br>
never have to transfer ownership or knowledge of the socket, and the<br>
keepalive and end() mechanisms would continue to work like normal.<br>
HttpConnection would have to get some knowledge about whether this<br>
request was dynamic or not, but that seems pretty doable, and could<br>
just be based on the first call to write. Also, this keeps all the<br>
keepalive code the same, which I think is good.<br>
<br></blockquote><div>That's exactly why we thought to use handle() method, but<b> there is a gap how to transfer ownership</b></div><div><b>of socket from connection class to rule class.</b></div><div><br></div><div>In the existing implementation where we transferred ownership of socket from connection class to rule class</div><div>based on http header field "upgrade::websocket"<br><br> As I explained above, we need bi-directional communication, where bmc sends certain payload and nbd on client-side</div><div>acknowledges received payload.<br><br>So we need websocket way of implementation, where we need to keep reading and writing constantly on the same socket.<br><br>What I am unable to connect is how to transfer ownership of socket connection to new rule class, as in this case </div><div>we can't take the decision based on request header/content. can you provide your suggestion please?<br><br>What do you mean by dynamic request and dynamic response?<br>As per my understanding, dynamic response is based on http request content, one of the header field "accept"</div><div>where client specifies data format and depending on this format, response gets generated. Is it a dynamic response?</div><div>if it's true, how is it applicable here?<br><br></div><div>Response object writing payload to dynamic body may not work in this case.<br>Response object does not hold socket, only connection class which is having socket, except handleUpgrade case <br>where we transfer socket ownership to connection to rule class which creates another connection</div><div><br>Thanks<br>-Raviteja<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br><br>
>> On Fri, 28 Aug, 2020, 12:42 am Ed Tanous, <<a href="mailto:ed@tanous.net" target="_blank">ed@tanous.net</a>> wrote:<br>
>>><br>
>>> On Sun, Aug 2, 2020 at 8:53 AM Ed Tanous <<a href="mailto:ed@tanous.net" target="_blank">ed@tanous.net</a>> wrote:<br>
>>> ><br>
>>> > I'm looking at a couple recent changes to bmcweb, and I'm finding a<br>
>>> > significant architecture problem has been injected. Namely, it's<br>
>>> > these innocuous looking 4 lines here, which injects the socket adaptor<br>
>>> > into the request object for use later.<br>
>>> > <a href="https://github.com/openbmc/bmcweb/blob/30c58d581606b4484757e6ee9133c248de1514a6/http/http_request.h#L18" rel="noreferrer" target="_blank">https://github.com/openbmc/bmcweb/blob/30c58d581606b4484757e6ee9133c248de1514a6/http/http_request.h#L18</a><br>
>>> ><br>
>>> > The problem with this approach has a few roots:<br>
>>> > 1. The Request class is meant to model a single request, single<br>
>>> > response model. Adding the stream semantics breaks this in pretty<br>
>>> > significant ways, and forces a hard dependency between the streaming<br>
>>> > adapter and the Request, which was not the intent. We have<br>
>>> > abstractions for "streaming" requests, but that was seemingly not<br>
>>> > used.<br>
>>> ><br>
>>> > 2. In the code that existed before this, Adaptor was a template on<br>
>>> > purpose. It is designed to implement the std::networking<br>
>>> > AsyncReadStream and AsyncWriteStream concepts. This is designed to<br>
>>> > allow injection of Unit Tests at some point, as I've talked about<br>
>>> > before. Hardcoding it in request to 2 forced stream types, based on<br>
>>> > the compiler flag is incorrect per asio standards, and removes the<br>
>>> > ability to inject arbitrary adapters, like test adaptors. Also, the<br>
>>> > flag used is incorrect, as it's possible to inject a non-ssl socket<br>
>>> > even if SSL is enabled.<br>
>>> ><br>
>>> > 3. There is already a precedent and pattern for streaming interfaces<br>
>>> > in bmcweb that we adopted from Crow. If you look at the Websocket<br>
>>> > request response type, it implements a way to request a route that<br>
>>> > streams dynamically. Frustratingly, part of what this was used for<br>
>>> > was SSE, which I had already written a patch for that didn't have any<br>
>>> > of the above issues, and only hadn't merged it because we didn't have<br>
>>> > any SSE routes yet, and didn't want to check in dead code.<br>
>>> > <a href="https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/13948" rel="noreferrer" target="_blank">https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/13948</a><br>
>>> ><br>
>>> > 4. It opens the possibility for lifetime and possible (at the very<br>
>>> > least harder to audit) security issues, as now the "http server"<br>
>>> > component is no longer the only thing that can own sockets.<br>
>>> > Previously, the server owned the sockets until handed off, then there<br>
>>> > was no shared ownership between the websocket class, and the<br>
>>> > Connection class. The Connection class could be completely destroyed<br>
>>> > (and memory freed) while the websocket was still connected and<br>
>>> > running.<br>
>>> ><br>
>>> > Moving to another track, you may ask, how did I come across this and<br>
>>> > why does it matter? I'm trying to add 2 new features to bmcweb. The<br>
>>> > first allows opening multiple sockets, and dynamically detecting TLS<br>
>>> > streams on them. This allows bmcweb to handle both HTTPS redirects in<br>
>>> > band, and handle the case where users type in something erroneous,<br>
>>> > like "<a href="http://mybmc:443" rel="noreferrer" target="_blank">http://mybmc:443</a>" and connect to an SSL socket with a non-ssl<br>
>>> > protocol. In those cases, we can simply do the right thing. It also<br>
>>> > allows bmcweb to host on multiple ports, which might be interesting<br>
>>> > for aggregator types. More importantly, it cleans up some of the<br>
>>> > Adaptor abstraction to make way for unit testing, and being able to<br>
>>> > inject a "test" socket, that we can control the semantics of. I'm<br>
>>> > hoping eventually to be able to mock dbus, and mock the TCP socket,<br>
>>> > and run a full Redfish validator run in a unit test. I think that<br>
>>> > would save a lot of time overall for both committers and consumers.<br>
>>> ><br>
>>> > The first of these patches is posted here, and simply comments out the<br>
>>> > above problems for now.<br>
>>> > <a href="https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/35265" rel="noreferrer" target="_blank">https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/35265</a><br>
>>> ><br>
>>> > If I look through the commit logs, it looks like Ravi and Appu built<br>
>>> > the two small subsystems that rely on the above abstraction, one for<br>
>>> > SSE, and one for some NBD streamer.<br>
>>> > What do you two think about the above? Was it something you<br>
>>> > considered when you wrote your patches? Would you consider fixing<br>
>>> > them?<br>
>>> ><br>
>>> > My recommendation would be to move both of those two over to<br>
>>> > something similar to the websocket abstraction we have, with, on<br>
>>> > connect, on data, and on close handlers. This means that handlers no<br>
>>> > longer take a hard dependency on the transport, which will help for<br>
>>> > both unit testing, and if we ever want to support redfish device<br>
>>> > enablement (which relies on an i2c based transport). The SSE one can<br>
>>> > probably be used more or less as-is from my old patch. The NBD one<br>
>>> > might need a "Dynamic body" type, which beast already has an<br>
>>> > abstraction for that seems to have been discounted.<br>
>>> ><br>
>>> > What do you guys think?<br>
>>> ><br>
>>> > -Ed<br>
>>><br>
>>><br>
>>> It's been 3 weeks and I haven't gotten any replies to this pretty<br>
>>> major architecture break. It also looks like it can also cause a<br>
>>> memory leak in HttpConnection here (found by code inspection here).<br>
>>> <a href="https://github.com/openbmc/bmcweb/blob/ebd459060ea4f42761402dd54acd0962c36136c2/http/http_connection.h#L351" rel="noreferrer" target="_blank">https://github.com/openbmc/bmcweb/blob/ebd459060ea4f42761402dd54acd0962c36136c2/http/http_connection.h#L351</a><br>
>>><br>
>>> I've pushed a revert to remove the features in question. I would love<br>
>>> some comments from the developers that caused these breakages, so I<br>
>>> can make sure I'm doing the right thing here, and I'm not completely<br>
>>> off base (or that you intend to fix them, and this patch is<br>
>>> unnecessary).<br>
>>> <a href="https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/36038" rel="noreferrer" target="_blank">https://gerrit.openbmc-project.xyz/c/openbmc/bmcweb/+/36038</a><br>
>>><br>
>>> Thanks,<br>
>>><br>
>>> -Ed<br>
</blockquote></div></div>