Implement private networks#1385
Conversation
|
I think the basic encryption is now reasonably correct. Here is the spec for reference: https://github.com/libp2p/specs/blob/master/pnet/Private-Networks-PSK-V1.md However, I tried getting the chat example to work with go-ipfs with a private swarm key, but could not get it to work. This might be related to the Looking at the help for the method: /// Returns the list of protocols that are supported. Used during the negotiation process.
fn protocol_info(&self) -> Self::InfoIter;It seems that what happens is that my made up protocol name will now be part of the negotiation process. So obviously this won't work since the go-ipfs side does not know about my made up protocol name. Is there a way around this? |
|
Oh I see, I didn't think about that. |
|
Not exactly sure how to wire this up. I naively tried this: pub fn build_tcp_ws_pnet_secio_mplex_yamux(keypair: identity::Keypair, psk: PSK)
-> io::Result<impl Transport<Output = (PeerId, impl core::muxing::StreamMuxer<OutboundSubstream = impl Send, Substream = impl Send, Error = impl Into<io::Error>> + Send + Sync), Error = impl error::Error + Send, Listener = impl Send, Dial = impl Send, ListenerUpgrade = impl Send> + Clone>
{
Ok(CommonTransport::new()?
.and_then(|socket, endpoint| PnetConfig::new(psk).handshake(socket))
// .and_then(move |io, endpoint| {
// libp2p_core::upgrade::apply(
// io,
// PnetConfig::new(psk),
// endpoint,
// libp2p_core::transport::upgrade::Version::V1,
// )
// })
.upgrade(core::upgrade::Version::V1)
.authenticate(secio::SecioConfig::new(keypair))
.multiplex(core::upgrade::SelectUpgrade::new(yamux::Config::default(), mplex::MplexConfig::new()))
.map(|(peer, muxer), _| (peer, core::muxing::StreamMuxerBox::new(muxer)))
.timeout(Duration::from_secs(20)))
}...but then the result of the and_then is not a transport anymore so the |
|
Right. Got it to work now. Making handshake return a BoxFuture fixes it! pub fn pin_handshake<TSocket>(self, socket: TSocket) -> BoxFuture<'static, Result<PnetOutput<TSocket>, PnetError>>
where
TSocket: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{
Box::pin(self.handshake(socket))
}Got the thing to talk to go-ipfs now. Thanks for helping me sort this out! |
4d4b4a8 to
52ef77c
Compare
0d99543 to
1202c67
Compare
|
I will remove or replace the pnet example before merging this. Now just want to keep it in for testing. |
ec753e8 to
43a3dd0
Compare
|
To me, multiple calls to Looks mostly good for me, except that |
484d798 to
9150a65
Compare
tomaka
left a comment
There was a problem hiding this comment.
LGTM. Please remove the example and let's merge!
|
Wait, I didn't realize that you had changed the logic of the buffer writing. |
|
Happy to revert it if you want, but I think the new code is better. |
da4dbb9 to
b61b92b
Compare
tomaka
left a comment
There was a problem hiding this comment.
The buffering logic still looks hard to read to me, hence these debug_assert!s, after which we should be good for merging.
copied from plaintext protocol, since that seems to be the closest match
Also remove unneeded InboundUpgrade and OutboundUpgrade
To be able to check if a go-ipfs and rust-libp2p use the same key without having to dump the actual key. Not sure if there is a spec for this anywhere, but it is basically just copied from go-ipfs.
Basically a stripped down and modified version of async_std BufWriter that also encrypts using the given cipher.
There will be a more elaborate and useful example in a different PR
also make doc text less ambiguous
Also, clarify the invariants in the comments of that method
fbf88f6 to
9ca5961
Compare
|
@tomaka I have taken all your suggestions and merged them into one commit, and rebased on current master. |
Implements private networks ( #476 )
This is meant to be interoperable with go-ipfs private swarms. For reference: the specification from PL is at https://github.com/libp2p/specs/blob/master/pnet/Private-Networks-PSK-V1.md , the implementation in go-ipfs is at https://github.com/libp2p/go-libp2p-pnet/ .
Tested by checking that two rust-ipfs nodes (pnet example) can chat with each other, and in addition checking that the pubsub traffic is visible in go-ipfs.