Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

HTTP Proxy : see #507 #528

Merged
merged 1 commit into from
Feb 10, 2017
Merged

Conversation

guzzijones
Copy link
Contributor

By submitting this pull-request, I confirm the following:

  • I have read and understood the Contributing Guide.
  • I have checked that another pull-request for this purpose does not exist.
  • I have considered and confirmed that this submission will be valuable to others.
  • I accept that this submission may not be used and that this pull-request may be closed by the will of the maintainer.
  • I give this submission freely under the BSD 3-clause license.

Place an X inside the bracket (or click the box in preview) to confirm

  • [x ] I confirm.

Enter your pull-request summary here

"client/reseed.cc"
"client/proxy/http.cc"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must have been an artifact of git rebase -i

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix it, rebase, force push.

Copy link
Collaborator

@anonimal anonimal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are too many issues to post in one review, so we'll have to go step-by-step. Fortunately, the key problems are fixed: user-agent and POST, so a huge thank you @guzzijones.

Note, you didn't have to close the previous PR: you can just force push the branch with --force (see man git-push). Please do that for the remainder of the work for this PR.

Now that you've also solved the learning curve of rebasing, we'll start with more of the basics:

  1. run clang-format on all effected files as described in the style guide. If clang-format does something completely stupid, fix it
  2. run cpplint (you can ignore warnings about any const references for now)
  3. style refactor local variables (we don't use camelCase or HeaderBody for local variables)
  4. Name variables as appropriate / use their intended purpose. This is specifically noted in our (and google's style guide). Variables like tbuffer tmpBuf bufString are, in this context, poorly named not because of the choice of words but because they are not tying into their intention (also, no camelCase). buf is fine to use if it's localized and unmistakable the only buffer we are operating on but the others need clarification (example, bufString implies there's another type of buffer).

These are the absolute easiest and most trivial part of development. If you can learn to organize your thoughts more visually, with an emphasis on clear composition, I believe that many other aspects of development will fall into place - and you will catch all the other non-style issues (and some dangerous style issues) that I will be pointing out after you've fixed these first 4 points.

For anyone else reading this: guzzi and I do most of our dialogue on IRC so if this response sounds harsh or pedantic, it's because @guzzijones has asked me to do so [respond in such a way] 😄

Referencing #527

@guzzijones
Copy link
Contributor Author

I made changes to variables. I had ran cpplint on files again. I did a force push. Let me know. I am not sure why it is showing merge conflicts now as i don't believe it was before..

@anonimal
Copy link
Collaborator

You'll need to rebase against current master.

@guzzijones
Copy link
Contributor Author

I will adjust the logging to the new system. That seems to be the reason for the merge conflicts.

@anonimal
Copy link
Collaborator

Yes, like I said, just rebase against current master.

@guzzijones
Copy link
Contributor Author

I finished up the rebase against the current master.

Copy link
Collaborator

@anonimal anonimal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you've finished rebasing, I must point out again that you didn't run clang-format on either the source or header file. That's fine, there are much bigger issues to deal with.

I don't want to spend an hour commenting on every issue, nor do I think I should patch this, so let's take the remaining issues step-by-step. First: notice the bottom of the build log https://build.getmonero.org/builders/kovri-all-ubuntu-amd64/builds/242/steps/compile/logs/stdio. You'll see the new warnings that this PR introduces. They point out problems with your async_read_until, async_read, and handler implementations. What you've written is not how function binding works nor is it how to use boost error codes. I suggest to either read the boost docs more or look at other areas of the code that implement what you're trying to do or simply look at what was previously there.

Once you resolve this issue, the remaining issues that prevent us from merging should should be a breeze to fix.

@guzzijones
Copy link
Contributor Author

switch back to using async_receive is what i see as a possibility.

@guzzijones
Copy link
Contributor Author

i removed the offending header and rebased again.

Copy link
Collaborator

@anonimal anonimal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You asked for harsh, so you shall receive! 😃

Too many comments on my end, I've lost my train of thought for this second pass. I can elaborate more on IRC for the remainder.

#include "core/router/identity.h"

#include "core/util/i2p_endian.h"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these header changes and line removals: please don't move them around unless needed; they can stay within their own groups.

//

HTTPProxyServer::HTTPProxyServer(
HTTPProxyServerService::HTTPProxyServerService(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no reason why you wanted to change this name. Please don't change class/function names unless absolutely needed.

//

void HTTPProxyHandler::AsyncSockRead() {
void HTTPProxyHandler::Handle() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I'll note below, I2PService handler is not confined to the HTTP Proxy. Virtual or not, I have no idea why you wanted to change all of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not changed. Both of these functions still exist.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had no where else to comment, this comment was for your handling implementation as it relates to I2PService (and your handling implementation).

// and forward along
// Read the request headers, which are terminated by a blank line.
// TODO(guzzi)
// unit test: One example is the addressbook unit-test I merged earlier.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to quote me, then quote me 😄

const boost::system::error_code& error,
size_t bytes_transfered) {
if (error) {
LOG(debug) << "AsyncHandleRead: error sock read: " << bytes_transfered;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AsyncHandleRead

What is this referencing? If you want to output the function name, use __func__. If not, please keep in line with the class name HTTPProxyHandler. Ideally, our logger will take care of this in the future.

boost::system::error_code b ) {
if (b == 0)
a->reset(b);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_result

?


BOOST_AUTO_TEST_CASE(Short) {
kovri::client::HTTPProtocol tmp;
std::string tmpData = "GET anonimal.i2p http/1.1";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use my garlicsite as a reference-point to show that I've been in a certain area. Certainly you don't want me to take credit for your work? Why not guzzi.i2p?

Also, doesn't the RFC specify uppercase HTTP?

tmpData+="http/1.1\r\nUser-Agent: dummy\r\n\r\n";
BOOST_CHECK(tmp.HandleData(tmpData));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could stand to make these tests more robust. I can provide details on IRC.

const boost::system::error_code& error,
std::size_t bytes_transferred) {
if (error) {
LOG(debug) << "HTTPSockRecv: error sock read: " << bytes_transferred;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above about logging class name/function name.

LOG(debug)
<< "HTTPProxyHandler: method is: " << m_Method
<< " request is: " << m_URL;
// Set defaults and regexp

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed. Please try to be more concise with your commits.

@guzzijones
Copy link
Contributor Author

guzzijones commented Jan 28, 2017 via email

Copy link
Collaborator

@anonimal anonimal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the aforementioned, always build and run unit-tests if you do work in that area because this PR will break the build (run make tests).

@@ -144,7 +148,14 @@ void HTTPProxyHandler::AsyncHandleReadHeaders(
boost::asio::buffers_end(buf));
// add the additional bytes the m_body
m_Protocol.m_Body = str;
}
} else if (num_additional_bytes < 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num_additional_bytes is unsigned. Research the difference between signed and unsigned types (and overflow + underflow for both types) to learn why this line makes no sense. Even if this type was signed (but it's not so don't get caught up with what I'm about to say), you don't want to test this way; you'll usually want to throw a class from std::exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i understand.

HTTPRequestFailed(); // calls Terminate
return;
}
size_t num_additional_bytes = m_Protocol.m_Buffer.size() - bytes_transfered;
std::size_t num_additional_bytes = m_Protocol.m_Buffer.size()
- bytes_transfered;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still doesn't prevent overflow if bytes transferred is greater than buffer size. Ensure that this will never happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i understand.

iss >> clen;
clen = clen - num_additional_bytes;
// need to call one more function to fill body after this read.
if (clen > 0) {
if (clen < 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i understand.

@guzzijones
Copy link
Contributor Author

I will go through tonight and add todos. I will go through tonight and run cpplint and test implemetation again. This push was for review. (others work during the day time). :)

HTTPProxy:: Adjustments

HTTPProxy:: fix unit tests, adjust buffer logic
@anonimal
Copy link
Collaborator

anonimal commented Feb 9, 2017

As discussed with @guzzijones on IRC, even though there are remaining issues to resolve (and he will resolve them with time), this PR will fix our headers issue and implements POST at the same time - so we can merge this now while he continues his TODO work.

@anonimal anonimal merged commit 4fd414e into monero-project:master Feb 10, 2017
anonimal added a commit that referenced this pull request Feb 10, 2017
4fd414e HTTP Proxy : see #11 (guzzi_jones)
@anonimal anonimal changed the title HTTP Proxy : see #11 HTTP Proxy : see #507 Feb 10, 2017
@anonimal
Copy link
Collaborator

Resolves #507.

@anonimal anonimal mentioned this pull request Feb 10, 2017
1 task
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants