Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified MIMEParser class for upload of larger files and multiple files #132

Merged
merged 25 commits into from
Jun 13, 2020
Merged

Conversation

squonk11
Copy link
Contributor

modified MIMEParser class for uploading lager files and multiple files

@squonk11
Copy link
Contributor Author

I will take care about the remaining issues during the next days. Unfortunately I have a problem running the shell scripts for the tests in my Docker; I think this is related to fact that the shell scripts are having CRLF line endings. I will try to find a fix for this also.

@squonk11
Copy link
Contributor Author

Now I changed the line endings of the shell scripts to LF and the error message of the missing interpreter "bin/bash^M" is gone and the script starts to be executed in Docker. But now I get the error message ./CI/build_test.sh: line 14: docker: command not found. Do you have an idea what I am missing?

@PerMalmberg
Copy link
Owner

The CI-scripts are meant to be run outside of docker; they will start an instance of the docker-image to run the tests.

@squonk11
Copy link
Contributor Author

but starting the scripts outside of Docker I can only do under Linux, right? Or is there a trick to do it under Windows also - maybe WSL?

@PerMalmberg
Copy link
Owner

Yes, I'd expect WSL to work.

I'd guess any bash terminal would work, such as Git-bash that comes with Git for Windows.

@squonk11
Copy link
Contributor Author

unfortunately both do not work. With git bash I get the error message: C:\Program Files\Docker\Docker\resources\bin\docker.exe: Error response from daemon: the working directory 'C:/Program Files/Git/src' is invalid, it needs to be an absolute path. I guess this is somehow related to the my Git installation because the directory C:/Program Files/Git/src really does not exist.
With WSL I get the error message docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?. This probably is due to the fact that WSL assumes that Docker is installed under WSL (but it is not).
So, I think I have to continue the try and error method via several commit/push sequences.

@PerMalmberg
Copy link
Owner

Aww, sorry to hear that.

You can ofc simply run the commands that the CI-scripts themselves run from within Docker.

@PerMalmberg
Copy link
Owner

Last! :) @squonk11 :)

@PerMalmberg
Copy link
Owner

@squonk11 Are you happy with the PR in its current state? I've not test run it myself, but I presume you have.

@squonk11
Copy link
Contributor Author

I did quite a lot of testing with the previous version using lambda functions. This version I did not test so much. I do not expect issues with this version but before accepting the pull request maybe it would be better to do some more testing. I will try to do it over the next weekend and finally add this PR to the file CONTRIBUTORS.md.
Do you have any more comments on the code?

@PerMalmberg
Copy link
Owner

I didn't see any obvious issues with the code.

I was thinking that we could perhaps do some automatic testing using the Linux version and curl inside docker, i.e. do actual calls to the HTTP-server. That way we get reproducability of the tests and can test a large range of cases.

@squonk11
Copy link
Contributor Author

Automatic testing would be a good idea. Unfortunately I am having problems starting bash scripts from outside Docker. Is it possible to do use these scripts from inside Docker as well? How to start the HTTP-server inside Docker? Additionally I did not use curl before - but I think I could find out how to use it.

@PerMalmberg
Copy link
Owner

The scripts that currently start the CI-test and builds just start a docker instance to run other scripts. The "other" scripts can all be run manually from within docker.

Python might actually be a better idea than curl, as it is easier to build tests in Python than in bash.

Starting the HTTP-server inside docker would require a test application built for testing the HTTP server specifically. The tests we currently have can serve the example folder with all the images, but that's not really useful in automated testing.

I'm thinking that an echo server, i.e. reply back with what is received, could be a useful thing. Then we can automated sending and receiving data from a single byte up to several mega-bytes with little effort.

@squonk11
Copy link
Contributor Author

squonk11 commented May 28, 2020

So, the Python script should launch a HTTP client which sends the files to the HTTP test-server. The HTTP test-server will then echo the files back to the python script. In order to receive the echoed files the python script needs to also launch a HTTP server which will then receive the files and comapres the contents against the files sent. Is that what you have in mind?
EDIT: to be more precise: it will not "launch" the HTTP client and server but "act" as a HTTP client and server.

@PerMalmberg
Copy link
Owner

No, no need for a HTTP server on the Python side, that can be done over the same client socket that Python uses to send the data. So, POST some data, then receive the answer.

@squonk11
Copy link
Contributor Author

Will the upload from the Python script be done via requests; e.g. like so:

import requests

url = "http://localhost:5000/"
fin = open('simple_table.pdf', 'rb')
files = {'file': fin}
try:
  r = requests.post(url, files=files)
	print r.text
finally:
	fin.close()

?
How must the Http-Server send the file back to the Python script? I guess it must send it also via a Multipart/Mime protocoll. But how to do that - there is not such a functionality in Smooth, isn't it?

@PerMalmberg
Copy link
Owner

Yes, requests will most likely do the job.

No there isn't. How about this:

  1. Pre-generate a set of random binary data so that each test can be recreated and re-run.
  2. Create a hash of the data
  3. Send the data to Smooth.
  4. Calculate the hash on the received data.
  5. Reply with the hash
  6. Compare the hash. If they don't match, the test fails.

This would allow us to test everything from 1 byte to megabytes.

@squonk11
Copy link
Contributor Author

The hash will be one hash value calculated over all files to be send (in case of multiple files)? The hash value will then be returned via the HTTP response?

@squonk11
Copy link
Contributor Author

Now I have the first version of the test ready.
I used the StringResponse to reply with the JSON string. In Python this string gets converted to a Python dict. The hashes of the files are then compared to the hashes returned from the HTTP server and a success or error message is printed.
I tested several times with the 1000 icon files and no error ocured. The only message I see is again that the watchdog on one CPU is triggered due to not being serviced. But the transmission still completes.
Shall I upload this as first version for discussion into this PR since it is still open?

@PerMalmberg
Copy link
Owner

PerMalmberg commented Jun 12, 2020 via email

@squonk11
Copy link
Contributor Author

yes, I tried also with lager files; e.g. three files: 8MB, 10MB and 1kB
I will provide the update soon.

@PerMalmberg
Copy link
Owner

I tried to run this in as a Linux version, but that unfortunately results in a crash.

[1] 31201 abort (core dumped) ./http_files_upload_test.elf

I'll have to debug this and see what goes wrong.

@squonk11
Copy link
Contributor Author

squonk11 commented Jun 12, 2020 via email

@PerMalmberg
Copy link
Owner

PerMalmberg commented Jun 12, 2020 via email

@squonk11
Copy link
Contributor Author

I checked the sources again. Maybe there could be two weak points:

  1. in UploadResponder::start_of_request() I am using sodium_malloc(). Maybe a stub is needed for this?
  2. In MIMEParser::parse() I define status as static. Maybe it must be a private member variable of MIMEParser?

Are you using the secure or the insecure server for the test?

@PerMalmberg
Copy link
Owner

I used the insecure server. It's most likely related to the sodium stuff, not sure why though. Adding gdb to the container right now to debug it.

A static local in parse() is no good since it then is is shared between instances.

@PerMalmberg
Copy link
Owner

First crash solved - sodium_init() must be called prior to using the library.

Another problem that then immediately showed it self - in end_of_request(), the call to free(pState) must be changed to sodium_free().

This clearly shows why it is beneficial to perform most of the work on a Linux system - the debugging facilities are so much better.

I'll be testing this a bit and will push the changes to you branch (if I can).

squonk11 and others added 2 commits June 13, 2020 17:50
Changed free() to sodium_free().
Made static function variable into class-member to avoid collisions with multiple instances.
General code review.
@PerMalmberg
Copy link
Owner

I'm done testing now, just waiting for the CI scripts to run locally. I see that you changed it to a local variable. I'll merge that into my local copy and push my changes to this PR.

@squonk11
Copy link
Contributor Author

o.k. thanks. Then I will check again.
Sure, testing under a "real" OS is much easier because you have all tools available. Usually I am working on µCs where this is not possible - even the logging to a terminal (like here in esp-idf) is not possible. Then debugging becomes very ugly...

@PerMalmberg
Copy link
Owner

Just pushed my changes, have a look.

Yes, uCs are a pain to debug, which is why I made Smooth so that it would be possible to use all the cool toys available :)

@squonk11
Copy link
Contributor Author

yes, great idea!
Do you know if I just have to do git pull in order to receive your changes?

@PerMalmberg
Copy link
Owner

PerMalmberg commented Jun 13, 2020 via email

@squonk11
Copy link
Contributor Author

I tested it again and it seems to work - after adjusting the url in upload.py.
Interesting to see your modifications in upload.py - for me it was more or less the first Python script I made.
Are there any other changes needed from my side? Maybe adding PR132 to CONTRIBUTORS.md?

@PerMalmberg
Copy link
Owner

Yes, please add it to the contributions file, then I'll accept this PR.

@PerMalmberg PerMalmberg merged commit c6e1a1d into PerMalmberg:master Jun 13, 2020
@PerMalmberg
Copy link
Owner

Merged! Thank you for your contribution @squonk11, great work.

@squonk11
Copy link
Contributor Author

squonk11 commented Jun 14, 2020 via email

@PerMalmberg
Copy link
Owner

Huh, how odd. I'll fix that.

@PerMalmberg
Copy link
Owner

@squonk11 Dunno if the commit was advertised to you, but it was just a typo. It's fixed in master now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants