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
Noise: skeleton of transport and connection #405
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i know this is still a draft, just taking a quick look :)
Co-Authored-By: Alex Stokes <r.alex.stokes@gmail.com>
@ralexstokes No problem! Thanks for the review. 🙏 |
To return `None` instead of `int. `Writer.write` *does* write all data in all use case.
This one is ready for review. Most of the details are implemented in #406 . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good at a high-level; i'll go look at the other PR now
@@ -51,14 +51,14 @@ def set_protocol(self, protocol_id: TProtocol) -> None: | |||
except MuxedStreamReset as error: | |||
raise StreamReset() from error | |||
|
|||
async def write(self, data: bytes) -> int: | |||
async def write(self, data: bytes) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if we can't write all of data
to the underlying stream? the idea w/ this interface is to allow a caller to detect this scenario and re-attempt the write if that happens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'm changing this because I didn't see this use case(returns before all of the data is written) present in our codebase and also the underlying transport e.g. trio.SocketStream.send_all
. write
is asynchronous and we probably can guarantee that write
returns only when all of the data is written. I can also change it back if we would prefer to allow write
to return if it only writes part of the data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should avoid underlying implementations from guiding our interface choices but i suppose we can leave this alone for now just to bias towards speed :)
def __init__( | ||
self, local_peer: ID, libp2p_privkey: PrivateKey, noise_static_key: PrivateKey | ||
) -> None: | ||
self.protocol_name = b"Noise_XX_25519_ChaChaPoly_SHA256" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this the specific noise suite we are using in libp2p-noise
according to that spec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's the protocol we use in the XX pattern. Ref: https://github.com/libp2p/specs/tree/master/noise#valid-noise-protocol-names
What's inside this PR
Transport(ISecureTransport)
IRawConnection
toNoiseConnection
.IPattern(ABC)
PatternXX(IPattern)
NoiseConnection(ISecureConn)
noise_conn_factory
IRawConnection
toNoiseConnection
.noise.Transport
andNoiseConnection
.