Protocally Identical: Protocol identifiers and DKG - #83
Conversation
|
|
||
| func (s *localIdentifier) ProviderName() string { | ||
| return "local" | ||
| } |
There was a problem hiding this comment.
Btw @rargulati I don't think you need conversion code to allow a libp2p identifier to be a net.ClientIdentifier. You just need to implement the (extremely small) interface.
There was a problem hiding this comment.
So you're saying implement an Identity ie. peerIdentity as a net.ClientIdentifier with peerIdentity.ProviderName() to return a string(peer.ID) if we're in libp2p?
There was a problem hiding this comment.
ProviderName() would return something like "libp2p"; it's more meant to be a provider type than the identifier itself. The identifier should be opaque to the consumer, as it's internal to the transport layer.
There was a problem hiding this comment.
Ok, peerIdentity.ProviderName() returns libp2p when we're in the libp2p transport. Got it.
|
A note: I'll probably iterate in this branch, but let's not look to merge it into |
69ef6c2 to
66a450c
Compare
cfa9614 to
e4f7cf7
Compare
66a450c to
09e5928
Compare
e4f7cf7 to
75167c2
Compare
rargulati
left a comment
There was a problem hiding this comment.
Quick review, not done
|
|
||
| // ClientIdentifier represents the identity of a recipient for a message. | ||
| type ClientIdentifier string | ||
| type ClientIdentifier interface { |
There was a problem hiding this comment.
Why net.ClientIdentifier rather than net.Networkidentifier (given that we have a net.Protocolidentifier below.
There was a problem hiding this comment.
I think it should just be net.Identifier. I can make that revision.
There was a problem hiding this comment.
Eh… Maybe. That would imply ProtocolIdentifier is-an Identifier, which isn't really true. I don't love the stutter in net.NetworkIdentifier. Perhaps net.ChannelIdentifier or net.TransportIdentifier?
There was a problem hiding this comment.
Pushed, changed to net.TransportIdentifier.
|
|
||
| func (s *localIdentifier) ProviderName() string { | ||
| return "local" | ||
| } |
There was a problem hiding this comment.
So you're saying implement an Identity ie. peerIdentity as a net.ClientIdentifier with peerIdentity.ProviderName() to return a string(peer.ID) if we're in libp2p?
| runes[i] = letterRunes[rand.Intn(len(letterRunes))] | ||
| } | ||
|
|
||
| return string(runes) |
There was a problem hiding this comment.
A ton of questions man haha. Why?
| make(map[string]func() proto.Unmarshaler, 0), | ||
| sync.Mutex{}, | ||
| make(map[net.ClientIdentifier]net.ProtocolIdentifier), | ||
| make(map[net.ProtocolIdentifier]net.ClientIdentifier)} |
There was a problem hiding this comment.
comma on the last item, move the } to the \n.
| sync.Mutex{}, | ||
| make(map[string]func() proto.Unmarshaler, 0)} | ||
| make(map[string]func() proto.Unmarshaler, 0), | ||
| sync.Mutex{}, |
There was a problem hiding this comment.
It really helps to have fieldName: initializedMemory
There was a problem hiding this comment.
Yah, I've been bad about that in the local packages. Will fix.
| sync.Mutex{}, | ||
| make(map[net.ClientIdentifier]net.ProtocolIdentifier), | ||
| make(map[net.ProtocolIdentifier]net.ClientIdentifier)} | ||
| channels[name] = append(channels[name], channel) |
There was a problem hiding this comment.
If we're going to use this, we probably need a mutex per map/array and in some cases a RWMutex
There was a problem hiding this comment.
What do you mean by “use” :)
The expected use of this right now is exactly what's in main. I think if we find ourselves using it for internal testing that requires more concurrent access we can upgrade our protections here. Current mutexes are there because things break otherwise.
ProtocolIdentifier is meant to allow us to separate the identifier used internally for a network layer, to identify a given node, from identifiers needed for a given protocol, for example BLS IDs. We start by introducing net.ProtocolIdentifier as a type, introducing a Message interface for messages that carry both network and protocol sender ids, and add a RegisterIdentifier method to the BroadcastChannel interface that allows the protocol layer to map a network identifier to a protocol identifier. Consumers are not yet using this abstraction.
Local channels are reworked a bit so that each consumer will have its own channel instance, exactly as if they were across a network, but the instances with the same channel name will communicate with each other. Each channel instance also has a random identifier. We introduce an internal BasicMessage for easy instantiation of the Message interface without external exposure. Also clarify that the local package is not meant for real use.
We were doing BLS ID values, but that's just doing a whole lot of copyin' for nothin'.
The handler function for broadcast channels now accepts a net.Message. We adjust the DKG to deal with this new reality, and tweak a bunch of the pieces of the algorithm to deal with the fact that the Message payload carries sender identification information, as well as to verify that the sender is known. A few bls.ID values are changed to pointers, as well. More abstraction is possible, but this is the first pass at this conversion, and there's much more to come.
We create a channel per member, which is something the new DKG relies on since local channel identity maps to channel instances.
75167c2 to
e6153e5
Compare
This is more standard Go style.
7f14d2e to
d81f387
Compare
Also tweak various places where we're referring to a netID or networkID or networkIdentifier to reflect the new term. This term is both clearer (it's really an identifier for whatever transport we're using for our messages) and gives us some consistency across different places where we're using it in terms of naming.

This diff is a bit long, but much of it is small adjustments to the DKG process that are a little repetitive. DKG needs to be refactored, but that can happen in a future PR.
The big addition here is the introduction of
net.ProtocolIdentifier, and the mapping between a network-sidenet.ClientIdentifier(name could use improvement) and the protocol-sidenet.ProtocolIdentifier(viaRegisterIdentifier). DKG demonstrates this distinction: the broadcast channels have an internal way that they refer to other nodes, but in DKG each node is associated with abls.ID, and this is the identifier that matters to the DKG protocol.The expectation is that recipients in
SendTocan be specified either bynet.ClientIdentifieror by a registerednet.ProtocolIdentifier. Additionally, the protocol is expected to implement the logic that will allow registering the protocol identifier. In DKG, this is done via theJoinMessage, which carries thebls.IDof the sender. Each recipient then registers that id with their local view of the client identifier.One additional concept is the introduction of
net.Message. These are the base network messages that are passed to the recipient callback, and they carry thenet.ClientIdentifier, thenet.ProtocolIdentifierif an associated one exists, and the payload, which is the unmarshaled wire message. These will map somewhat more directly to our protobuf envelope type (though still with tweaks).The
localpackage contains a basic implementation of this that doesn't go over the network, and demonstrates some of the moving parts.