-
Notifications
You must be signed in to change notification settings - Fork 75
update insecure transport to plaintext/2.0.0 #37
Conversation
I'm also wondering if we should log a warning when the transport is instantiated, just as a guard against people accidentally enabling this during production. I don't know anything about go logging though, so idk what's appropriate for a library to log and so on. |
About the protobuf import thing, I've discovered that it basically works if you add the crypto.proto: syntax = "proto2";
package crypto.pb;
option go_package = "github.com/libp2p/go-libp2p-core/crypto/pb"; Then when you import import (
fmt "fmt"
proto "github.com/gogo/protobuf/proto"
pb "github.com/libp2p/go-libp2p-core/crypto/pb"
io "io"
math "math"
) Which is great and the compiler loves me. The only problem is that, instead of generating
So that's annoying. It's not hard to work around - we can Maybe there's a way that's less of a hack though, i don't know. |
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 great! just some golang tips to make things a little more brief
Sweet, thanks for the feedback @bigs, it's much better now :) |
sec/insecure/insecure.go
Outdated
} | ||
|
||
func (ic *Conn) runHandshakeSync(ctx context.Context) error { | ||
const maxSize = 1 << 16 |
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 have a default here https://github.com/libp2p/go-libp2p-core/blob/master/network/network.go#L23
but honestly we can probably place a smaller limit on key exchanges. just linking for info
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.
on second thought, may be worth just using that constant. also this is reminding me, one of msgio's big benefits is buffer pooling, but since this is a test-only upgrader, we're probably fine with a little extra allocation.
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.
awesome, thanks for pointing me at the constant. it seems best to use it for consistency rather than have more magic numbers sprinkled about.
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.
This needs to be rethought. For now, the merge has been reverted.
} | ||
|
||
// New constructs a new insecure transport. | ||
func New(id peer.ID) *Transport { | ||
func New(id peer.ID, key ci.PrivKey) *Transport { |
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.
This causes pretty severe API breakage.
- in the
Transport
option of the go-libp2p constructor. - elsewhere (e.g. go-tcp-transport) where this constructor is used directly.
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.
The private key is unnecessary here. The public key should do.
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 deprecate the New
function and make a WithIdentity()
function that the public key, and returns a function of signature func(id peer.ID) *Transport
that can then be used with the go-libp2p constructor.
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.
Adding a new constructor function and deprecating the old is definitely the way to go 👍
I added the private key to avoid returning nil
from LocalPrivateKey
- if we don't care about that then we can just take the public key.
definite lapse here, sorry. i think we should just add a new version of the protocol alongside 1.0.0. that’s what the versioning is for and this protocol is different. |
@bigs I thought of that too, but I concluded that v1 does not really work, and there’s no point ossifying something that’s broken. |
This changes the behavior of the insecure "security" transport to conform to the new spec. Will close #36.
@bigs I can't seem to figure out how to correctly import the
crypto.pb
file from the newplaintext.pb
file I added.The way it's set up now,
protoc
generates an import statement likeWhich doesn't resolve to anything. I manually changed that to
pb "github.com/libp2p/go-libp2p-core/crypto/pb"
, which is what's committed in here, just so I could get something building.I also copied the test code over from secio and stripped out the stuff related to actual crypto. It seems like it works...
Another thing I'm not sure about is whether adding a new private key argument to the
New
constructor will break anything. I think I remember that the reflection magic thing will inject a private key if you take one in as an arg, but I can't remember where that code is, lol.