Skip to content

Conversation

@iTranscend
Copy link
Contributor

in partial resolution of #342

This PR replaces the use of the SubstreamSet hashmap in substream's test with the FuturesStream type.

Copy link
Collaborator

@lexnv lexnv left a comment

Choose a reason for hiding this comment

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

Thanks @iTranscend for contributing 🙏

This looks good to me, it is nice that we have tests for our FuturesStream implementation

@lexnv lexnv requested a review from dmitry-markin October 31, 2025 12:21
Copy link
Collaborator

@dmitry-markin dmitry-markin left a comment

Choose a reason for hiding this comment

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

These tests were testing the SubstreamSet, implemented in this file. As it was replaced with FuturesStream, the equivalent tests should go to utils/futures_stream.rs.

Also, the SubstreamSet should be completely removed.

@iTranscend
Copy link
Contributor Author

regarding the complete removal of SubstreamSet

Removing it will render the CustomProtocol test defunct as FuturesStream is not a good replacement for SubstreamSet in that case.

In the implementation of UserProtocol for CustomProtocol, when a command is received in the event loop, the PeerId is used as a key to find the corresponding Substream of the peer that the received command is directed at.

litep2p/tests/substream.rs

Lines 152 to 178 in 3f13b10

command = self.rx.recv() => match command.unwrap() {
Command::SendPayloadFramed(peer, payload, tx) => {
match self.substreams.remove(&peer) {
None => {
tx.send(Err(Error::PeerDoesntExist(peer))).unwrap();
}
Some(mut substream) => {
let payload = Bytes::from(payload);
let res = substream.send_framed(payload).await.map_err(Into::into);
tx.send(res).unwrap();
let _ = substream.close().await;
}
}
}
Command::SendPayloadSink(peer, payload, tx) => {
match self.substreams.remove(&peer) {
None => {
tx.send(Err(Error::PeerDoesntExist(peer))).unwrap();
}
Some(mut substream) => {
let payload = Bytes::from(payload);
let res = substream.send(payload).await.map_err(Into::into);
tx.send(res).unwrap();
let _ = substream.close().await;
}
}
}

This behavior can't be replicated with FuturesStream because there is no way to know what future (containing the substream for the peer in focus) will be returned. We can't also iterate through the FuturesStream because that would resolve futures of substreams that we are not interested in.

My intuition on this may be wrong and I may be looking at this from the wrong angle so please lmk what you think.

cc @lexnv @dmitry-markin

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