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

Switch HTTP implementation to reqwest #124

Merged
merged 4 commits into from
Oct 22, 2019

Conversation

theotherjimmy
Copy link
Collaborator

@theotherjimmy theotherjimmy commented Oct 7, 2019

The prior HTTP implementation was hyper, and provided a low level
of abstraction. This low level required me to implement redirect and
proxy support. I omitted proxy support.

Now, we use reqwest to handle HTTP. This allows us to delete our
custom (but not special) redirect support and pick up proxy support.


Note: This contains format changes and a minor refactor (move
vidx/pidx-related code to methods on DownloadContext)

The prior HTTP implementation was `hyper`, and provided a low level
of abstraction. This low level required me to implement redirect and
proxy support. I omitted proxy support.

Now, we use `reqwest` to handle HTTP. This allows us to delete our
custom (but not special) redirect support and pick up proxy support.
@theotherjimmy
Copy link
Collaborator Author

Might resolve #101 and a part of #121 (the redirect error encountered by @flit later in the comment thread).

@theotherjimmy
Copy link
Collaborator Author

duplicate packages

before

base64
log
proc-macro2
quote
rand
rand_core
slab
smallvec
syn
unicode-xid
winapi

11

after

encoding_rs
error-chain
idna
percent-encoding
proc-macro2
quote
rand_core
syn
unicode-xid
url
winapi

11


It's weird that the same number of dupes are present, but they're not the same 😕

Checked with cargo crev verify | awk '{print $(NF - 1)}' | sort | uniq -d

@JanneKiiskila
Copy link
Contributor

JanneKiiskila commented Oct 8, 2019

Surprisingly large change, I think you're doing a small re-factoring to some bits on the go?
(On more careful look, looks like you've formatted the code a lot to have the parameters on separate lines vs. the previous oneliner).

Question - how to test this? Wonder if the README.md could be expanded to give some advice how to run this locally (as part of the project.py), i.e. generate the pip package from this repo somehow? I think the Rust part requires some wheels generation?

@theotherjimmy
Copy link
Collaborator Author

theotherjimmy commented Oct 8, 2019

@JanneKiiskila Thanks for the feedback. Responses with quoted questions below.

(On more careful look, looks like you've formatted the code a lot to have the parameters on separate lines vs. the previous oneliner).

Yeah, I compulsively run rustfmt, and it seems to have decided to reformat a tad.

I think you're doing a small re-factoring to some bits on the go?

I moved the vidx downloading code to be members on the DownloadContext Struct, as I had to change it's use of hyper::Client to reqwest::async::Client and it ended up being the same work.

Wonder if the README.md could be expanded to give some advice how to run this locally (as part of the project.py), i.e. generate the pip package from this repo somehow?

That's a good point. I'll write it here and then we can add the instructions to the readme.


To build cmsis-pack-manager locally, Install a stable rust compiler. See https://rustup.rs/ for details.

After installing the rust toolchain and downloading a stable compiler with rustup update stable, run python2 setup.py bdist_wheel from the root of this repo to generate a binary wheel in the same way as we release.

For testing purposes, there is a minimal CLI written in Rust within the rust workspace cd rust; cargo run -p cmsis-cli -- update builds this testing CLI and runs the update command, for example.

@theotherjimmy
Copy link
Collaborator Author

@JanneKiiskila I pushed up a more detailed version of the build instructions. View them here: https://github.com/ARMmbed/cmsis-pack-manager/blob/596c117e70b80a04e05ba1ccd8b284b236f5d960/README.md.


I also need to figure out what's going wrong with travis CI.

@flit
Copy link
Member

flit commented Oct 8, 2019

Fwiw, I'm also having issues with Travis-CI with pyOCD. It does seem to run the tests but the results are not making it to GitHub. Haven't had time to look into it, so I'm very curious if you find anything.

@flit
Copy link
Member

flit commented Oct 11, 2019

@theotherjimmy No I hadn't seen that, thanks for the link!

@flit
Copy link
Member

flit commented Oct 12, 2019

@theotherjimmy Unfortunately the fix described in that link doesn't apply directly. But it does hint that the problem seems to be related to Travis-CI transitioning to GitHub Apps. Basically, we need to migrate these repos to using Travis via Apps, then make sure to follow the instructions in that link.

@JanneKiiskila
Copy link
Contributor

JanneKiiskila commented Oct 17, 2019

Trial run shows we still have some issues, but I have no clear explanation/understanding why.

Starting point - located in /cmsis-pack-manager/rust -folder, started with command
cargo run --package cmsis-cli -- update

   Compiling cmsis-cli v0.1.0 (/home/jankii01/mbed/cmsis-pack-manager/rust/cmsis-cli)
    Finished dev [unoptimized + debuginfo] target(s) in 1m 21s
     Running `target/debug/cmsis-cli update`
Oct 17 17:44:26.767 DEBG Logging ready.
Oct 17 17:44:26.768 INFO Updating registry from `http://www.keil.com/pack/keil.vidx`
Oct 17 17:44:26.768 INFO Updating registry from `http://www.keil.com/pack/keil.pidx`
Oct 17 17:44:28.425 ERRO https://www.qorvo.com/extra/keil_pack/Active-Semi.pidx: error trying to connect: Connection reset by peer (os error 104), uri: https://www.qorvo.com/extra/keil_pack/Active-Semi.pidx
Oct 17 17:44:49.361 ERRO http://www.amiccom.com.tw/download/Amiccom_DeviceFamilyPack/Amiccom.pidx: error trying to connect: Connection refused (os error 111), uri: http://www.amiccom.com.tw/download/Amiccom_DeviceFamilyPack/Amiccom.pidx
Downloading Packs 298 / 630 [##########################################>                                               ] 47.30 % Oct 17 17:45:07.972 ERRO download of "http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.FRDM-KE15Z_BSP.pdsc" failed: http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.FRDM-KE15Z_BSP.pdsc: connection closed before message completed
Downloading Packs 299 / 630 [##########################################>                                               ] 47.46 % Oct 17 17:45:07.976 ERRO download of "http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.FRDM-KE04Z_BSP.pdsc" failed: http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.FRDM-KE04Z_BSP.pdsc: connection closed before message completed
Downloading Packs 478 / 630 [####################################################################>                     ] 75.87 % Oct 17 17:45:12.810 ERRO download of "http://www.redpinesignals.com/downloads/keil_packs/RS13100_DFP/Redpine.RS13100_DFP.pdsc" failed: https://www.redpinesignals.com/downloads/keil_packs/RS13100_DFP/Redpine.RS13100_DFP.pdsc: connection error: Connection reset by peer (os error 104)
Downloading Packs 596 / 630 [#####################################################################################>    ] 94.60 % Oct 17 17:45:20.852 ERRO download of "https://www.keil.com/pack/Keil.STM32F7xx_DFP.pdsc" failed: https://www.keil.com/pack/Keil.STM32F7xx_DFP.pdsc: error trying to connect: unexpected end of file
Downloading Packs 597 / 630 [#####################################################################################>    ] 94.76 % Oct 17 17:45:20.864 ERRO download of "https://www.keil.com/pack/Keil.STM32G0xx_DFP.pdsc" failed: https://www.keil.com/pack/Keil.STM32G0xx_DFP.pdsc: error trying to connect: unexpected end of file
Downloading Packs 615 / 630 [#######################################################################################>  ] 97.62 % Oct 17 17:45:21.974 ERRO download of "https://www.keil.com/pack/Keil.STM32H7xx_DFP.pdsc" failed: https://www.keil.com/pack/Keil.STM32H7xx_DFP.pdsc: error trying to connect: unexpected end of file
Downloading Packs 630 / 630 [#########################################################################################] 100.00 % Oct 17 17:45:27.309 INFO Updated 624 package

Annoyingly, it's exactly (still) one of those critical STM packages that is failing (with unexpected end of file). :-/

@JanneKiiskila
Copy link
Contributor

Much to my annoyance, curl still manages to download that darn thing.

(cmsis) jankii01@ubuntu:~/mbed/cmsis-pack-manager/rust$ curl https://www.keil.com/pack/Keil.STM32H7xx_DFP.pdsc -L >Keil.STM32H7xx_DFP.pdsc
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0  5683    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  206k  100  206k    0     0   126k      0  0:00:01  0:00:01 --:--:--  429k

So, there is some secret sauce curl does here, that even reqwest is not doing.

@JanneKiiskila
Copy link
Contributor

The Active-Semi case is also weird, curl does that one as well - but the file is in reality sort of nothing.

(cmsis) jankii01@ubuntu:~/mbed/cmsis-pack-manager/rust$ curl https://www.qorvo.com/extra/keil_pack/Active-Semi.pidx >Active-Semi.pidx
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   564  100   564    0     0    331      0  0:00:01  0:00:01 --:--:--   330
(cmsis) jankii01@ubuntu:~/mbed/cmsis-pack-manager/rust$ cat Active-Semi.pidx 
<?xml version="1.0" encoding="UTF-8" ?>
<index schemaVersion="1.0.0" xs:noNamespaceSchemaLocation="PackIndex.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
  <vendor>Active-Semi</vendor>
  <url>http://www.active-semi.com/keil_pack</url>
  <timestamp>2019-07-31T11:27:00.0000000+00:00</timestamp>
  <pindex>
    <pdsc url="http://www.active-semi.com/keil_pack" vendor="Active-Semi" name="PAC52XX" version="2.0.0"/>
    <pdsc url="http://www.active-semi.com/keil_pack" vendor="Active-Semi" name="PAC55XX" version="1.0.0"/>
  </pindex>
</index>

@JanneKiiskila
Copy link
Contributor

One question - in this case, where are the files downloaded? The current folder seems to be empty.

@theotherjimmy
Copy link
Collaborator Author

@JanneKiiskila They should be in ~/.local/share/cmsis on linux.

@theotherjimmy
Copy link
Collaborator Author

@JanneKiiskila As for the issues, I think they're TLS cypher suite mismatches. You could try applying the diff in #121 to see if that's the case. FYI, this cannot be packaged for linux with OpenSSL as the backend for TLS as it requires an ancient bug-ful version to be a manylunx1 binary.

@JanneKiiskila
Copy link
Contributor

JanneKiiskila commented Oct 18, 2019

Indeed, that does resolve the issue. Question is - what are our options here? This needs to get fixed, we have some deadlines to meet... (Unless we buy time and actually update that one package manually).

We have come rust compiler warnings:

```
warning: trait objects without an explicit `dyn` are deprecated
   --> pdsc/src/component.rs:225:17
    |
225 | ) -> Result<Box<Iterator<Item = ComponentBuilder>>, Error> {
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn Iterator<Item = ComponentBuilder>`
    |
    = note: `#[warn(bare_trait_objects)]` on by default

   Compiling reqwest v0.9.22
   Compiling cmsis-update v0.1.0 (/home/jankii01/mbed/cmsis-pack-manager/rust/cmsis-update)
warning: trait objects without an explicit `dyn` are deprecated
   --> cmsis-update/src/download.rs:153:14
    |
153 |     ) -> Box<Future<Item = (), Error = Error> + 'a> {
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn Future<Item = (), Error = Error> + 'a`
    |
    = note: `#[warn(bare_trait_objects)]` on by default

warning: trait objects without an explicit `dyn` are deprecated
   --> cmsis-update/src/download.rs:188:14
    |
188 |     ) -> Box<Stream<Item = PathBuf, Error = Error> + 'a>
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn Stream<Item = PathBuf, Error = Error> + 'a`
```

The compiler is pretty cool, as the warning it gives already tells you
the real fix, too.
@JanneKiiskila
Copy link
Contributor

JanneKiiskila commented Oct 18, 2019

Other question - how can I get this to be in place for the Python tooling, with this version I could already actually do the required cmsis-pack update. Better yet would be if I could update the information from that one particular package ONLY to the .json -file.

I think just doing ~/mbed/cmsis-pack-manager$ pip install -e . does it, actually.

JanneKiiskila pushed a commit to JanneKiiskila/mbed-os that referenced this pull request Oct 18, 2019
Updating of all CMSIS packs that running

```
python project.py -m STM32F7xx --update-packs
```

brings, while using a customer version of cmsis-pack-manager.
(Essentially using the reqwest version from theOtherJimmy with
the TLS fix mentioned in the comments).

See:

- pyocd/cmsis-pack-manager#121
- pyocd/cmsis-pack-manager#124

for more details.
@theotherjimmy
Copy link
Collaborator Author

@JanneKiiskila Yes would could do pip install -e . or python setup.py bdist_wheel followed by pip install dist/cmsis-pack-manager*.whl. I don't use pip innstall -e . on this packages, so I can't comment on how well that works.

For clarification: pip is happy to create a linux wheel, but pypi will not accept it. pypi will only accept manylinux1 wheels. This is not great, as the manylinux1 spec requires that you be able to install the wheel on Centos 4 or 5, neither of which is anywhere near current.

Fix trait objects without explicit `dyn`.
@flit
Copy link
Member

flit commented Oct 18, 2019

Fwiw, there is a new manylinux2010 that is based on CentOS 6. See https://github.com/pypa/manylinux.

@theotherjimmy
Copy link
Collaborator Author

Thanks for the link. We still don't have libcrypto or libssl, so I can't link against openssl.

@theotherjimmy theotherjimmy reopened this Oct 22, 2019
@theotherjimmy theotherjimmy merged commit 92af01b into pyocd:master Oct 22, 2019
@JanneKiiskila
Copy link
Contributor

pip install -e . seemed to do the trick, at least it did download the files & update the file.

DownloadContext {
pub fn new(config: &'a Conf, prog: Prog, log: &'a Logger) -> Result<Self, Error> {
let client = ClientBuilder::new()
.use_rustls_tls()
Copy link
Contributor

Choose a reason for hiding this comment

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

This part was having some issues still, what is the route we can consider going forwards to avoid the issue? I still had to tweak this part out to get it working (i.e. apply your patch).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JanneKiiskila Removing that line forces linux users to use Openssl instead of Rustls. This prevents the package from being a "manylinux" wheel, and you're only allowed to upload "manylinux" wheels to pypi. My hands are tied, I can't use Openssl here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, that is a problem. :-/ Question is then can we file an issue to the RustLS and have those guys fixed the underlying TLS handshake/cipher issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That really depends on the cypher suite is question. They have no plans to add support for known-broken cyphers.

Copy link
Contributor

Choose a reason for hiding this comment

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

KEIL or AWS should not use broken cipher suites. The chosen cipher suite is selected with a negotiation, right? If the client proposes a good, working cipher suite - surely the back-end should use it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, they should not use broken cypher suites. also, I think the hosting is Microsoft related, at least that's what I recall. It's also really frustrating to debug this issue, as the server in question simply terminates the connection instead of giving us any information. We might have negotiated for a cypher suite that segfaults for all we know.

Copy link
Contributor

@JanneKiiskila JanneKiiskila Nov 12, 2019

Choose a reason for hiding this comment

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

Seems we're getting more failures... :-(

(cmsis) jankii01@ubuntu:~/mbed/mbed-bootloader/mbed-os/tools$ python project.py --update-packs
Nov 12 16:04:06.756 ERRO download of "http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.LPC5528_DFP.pdsc" failed: http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.LPC5528_DFP.pdsc: connection closed before message completed
Nov 12 16:04:06.784 ERRO download of "http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.LPC5526_DFP.pdsc" failed: http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.LPC5526_DFP.pdsc: connection closed before message completed
Nov 12 16:04:06.807 ERRO download of "http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.LPC55S28_DFP.pdsc" failed: http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.LPC55S28_DFP.pdsc: connection closed before message completed
Nov 12 16:04:06.996 ERRO download of "http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.LPC55S26_DFP.pdsc" failed: https://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.LPC55S26_DFP.pdsc: connection closed before message completed
http://www.amiccom.com.tw/download/Amiccom_DeviceFamilyPack/Amiccom.SoC_DFP.pdsc: error trying to connect: Connection refused (os error 111)
Nov 12 16:07:58.866 ERRO download of "http://www.mindmotion.com.cn/Download/MDK_KEIL/MindMotion.MM32L3xx_DFP.1.0.6.pack" failed: http://www.mindmotion.com.cn/Download/MDK_KEIL/MindMotion.MM32L3xx_DFP.1.0.6.pack: error trying to connect: Connection refused (os error 111)
Nov 12 16:08:22.251 ERRO download of "http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.LPC844_DFP.12.0.0.pack" failed: http://mcuxpresso.nxp.com/cmsis_pack/repo/NXP.LPC844_DFP.12.0.0.pack: connection closed before message completed
Nov 12 16:10:16.694 ERRO download of "http://www.mindmotion.com.cn/Download/MDK_KEIL/MindMotion.MM32F031_DFP.1.3.7.pack" failed: http://www.mindmotion.com.cn/Download/MDK_KEIL/MindMotion.MM32F031_DFP.1.3.7.pack: connection error: Connection reset by peer (os error 104)

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.

3 participants