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

#![no_std] support #627

Closed
tomaka opened this issue Nov 12, 2018 · 7 comments
Closed

#![no_std] support #627

tomaka opened this issue Nov 12, 2018 · 7 comments
Labels
difficulty:moderate getting-started Issues that can be tackled if you don't know the internals of libp2p very well

Comments

@tomaka
Copy link
Member

tomaka commented Nov 12, 2018

Very long term and possibly not doable in practice.

@tomaka tomaka added the getting-started Issues that can be tackled if you don't know the internals of libp2p very well label Feb 21, 2019
@tomaka
Copy link
Member Author

tomaka commented Aug 30, 2019

Now that alloc is stable and available, this has become a bit more realistically doable.

However, there are two major issues in the codebase that need to be addresses:

  • alloc doesn't provide any HashMap, probably because of the randomness of the SIP hasher. We could replace hashmaps with other data structures, or find a no-std-friendly crate that provides hash maps.
  • We use std::io::Error a lot, notably in two places: the muxing system and in the context of AsyncRead/AsyncWrite. I don't really have an opinion on how to solve that.

@tomaka
Copy link
Member Author

tomaka commented Jan 10, 2020

alloc doesn't provide any HashMap, probably because of the randomness of the SIP hasher. We could replace hashmaps with other data structures, or find a no-std-friendly crate that provides hash maps.

The primary replacement for this would be the hashbrown crate. It is actually the library that the Rust standard library uses internally. The Rust stdlib can't expose HashMap in alloc because of the SIP hasher, but hashbrown doesn't use randomness.

@olanod
Copy link

olanod commented Jun 18, 2020

Any updates and thoughts on this? I think is now possible to have async/await code compile in no_std right?

@tomaka
Copy link
Member Author

tomaka commented Jun 18, 2020

It is possible to use async/await, but the AsyncRead and AsyncWrite traits of the futures crate use std::io::Error, which isn't available in no-std contexts, and we make heavy use of these traits.

I don't really know how to solve this.

@olanod
Copy link

olanod commented Jun 18, 2020

Oh right, well it'll have to wait since it seems moving std::io::Error to alloc might take a while.

@mriise
Copy link

mriise commented Jan 20, 2022

Small update for parties interested

Error trait:

rust-lang/rust#90328
rust-lang/rfcs#3192

no-alloc:

https://docs.rs/heapless/latest/heapless has a lot of alloc replacements of things like Vec and String

The "HashMap" (IndexMap) implementation's default hashing algorithm isn't properly suitable* as a pure replacement without a better one, such as HigwayHash

* https://github.com/servo/rust-fnv

... it is important to profile your program to ensure that you are using small hash keys, and be certain that your program could not be exposed to malicious inputs (including being a networked server).

@thomaseizinger
Copy link
Contributor

I am going to close this as unlikely to be actioned. It is possible to write a libp2p implementation using no_std but very likely, it is much more productive to just create a dedictated no_std fork that only supports a subset of features.

@thomaseizinger thomaseizinger closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty:moderate getting-started Issues that can be tackled if you don't know the internals of libp2p very well
Projects
None yet
Development

No branches or pull requests

4 participants