Skip to content

Commit

Permalink
Fixes wrong spell of "enveloppe"
Browse files Browse the repository at this point in the history
  • Loading branch information
nkcr committed May 13, 2020
1 parent 0ef849f commit 0e1bf33
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
18 changes: 9 additions & 9 deletions mino/minogrpc/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ func (o overlayService) Stream(stream Overlay_StreamServer) error {
rpcID := o.addr.String()

// Listen on the first message, which should be the routing infos
enveloppe, err := stream.Recv()
envelope, err := stream.Recv()
if err != nil {
return xerrors.Errorf("failed to receive first routing message: %v", err)
}

rting, err := o.routingFactory.FromAny(enveloppe.Message)
rting, err := o.routingFactory.FromAny(envelope.Message)
if err != nil {
return xerrors.Errorf("failed to decode routing message: %v", err)
}

o.rootAddr = address{enveloppe.PhysicalFrom}
o.rootAddr = address{envelope.PhysicalFrom}

// fmt.Print(o.addr)
// rting.(*routing.TreeRouting).Display(os.Stdout)
Expand All @@ -135,16 +135,16 @@ func (o overlayService) Stream(stream Overlay_StreamServer) error {
encoder: o.encoder,
// This address is used when the client doesn't find the address it
// should send the message to in the list of participant. In that case
// it packs the message in an enveloppe and send it back to this
// address, which is registered in the list of participant.
// It is also used to indicate the "from" of the message in the case it
// doesn't relay but sends directly.
// it packs the message in an envelope and send it back to this address,
// which is registered in the list of participant. It is also used to
// indicate the "from" of the message in the case it doesn't relay but
// sends directly.
address: address{rpcID},
name: "remote RPC of " + o.addr.String(),
srvCert: o.srvCert,
traffic: o.traffic,
routing: rting,
rootAddr: address{enveloppe.PhysicalFrom},
rootAddr: address{envelope.PhysicalFrom},
}

sender.participants.Store(rpcID, stream)
Expand Down Expand Up @@ -201,7 +201,7 @@ func (o overlayService) Stream(stream Overlay_StreamServer) error {
From: o.addr.String(),
PhysicalFrom: o.addr.String(),
To: []string{addr.String()},
Message: enveloppe.Message,
Message: envelope.Message,
})

// TODO: think how we can make all the node set the routing then start
Expand Down
4 changes: 2 additions & 2 deletions mino/minogrpc/overlay.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mino/minogrpc/overlay.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import "google/protobuf/any.proto";
// Envelope is wrapper around a message and one or several recipients.
message Envelope {
// This is the origin address of the message. For example if node A sends a
// message to Node C via Node B, then node C will receive an enveloppe with
// message to Node C via Node B, then node C will receive an envelope with
// "from = A" and "physicalFrom = B"
string from = 1;
// This is the real address of the node that sent this enveloppe
// This is the real address of the node that sent this envelope
string physicalFrom = 2;
repeated string to = 3;
google.protobuf.Any message = 4;
Expand Down
15 changes: 7 additions & 8 deletions mino/minogrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ func (rpc RPC) Stream(ctx context.Context,
func listenStream(stream overlayStream, orchRecv *receiver,
orchSender *sender, addr mino.Address) error {

// This msg.Message should always be an enveloppe
envelope, err := stream.Recv()
if err == io.EOF {
return io.EOF
Expand Down Expand Up @@ -315,7 +314,7 @@ func listenStream(stream overlayStream, orchRecv *receiver,

msg, err := orchRecv.encoder.UnmarshalDynamicAny(envelope.Message)
if err != nil {
return xerrors.Errorf("failed to unmarshal enveloppe message: %v", err)
return xerrors.Errorf("failed to unmarshal envelope message: %v", err)
}

errChan := orchSender.sendWithFrom(msg,
Expand Down Expand Up @@ -593,12 +592,12 @@ type receiver struct {
// Recv implements mino.receiver
func (r receiver) Recv(ctx context.Context) (mino.Address, proto.Message, error) {
// TODO: close the channel
var enveloppe *Envelope
var envelope *Envelope
var err error
var ok bool

select {
case enveloppe, ok = <-r.in:
case envelope, ok = <-r.in:
if !ok {
return nil, nil, errors.New("time to end")
}
Expand All @@ -612,16 +611,16 @@ func (r receiver) Recv(ctx context.Context) (mino.Address, proto.Message, error)
}

// we check it to prevent a panic on msg.Message
if enveloppe == nil {
if envelope == nil {
return nil, nil, xerrors.New("message is nil")
}

msg, err := r.encoder.UnmarshalDynamicAny(enveloppe.Message)
msg, err := r.encoder.UnmarshalDynamicAny(envelope.Message)
if err != nil {
return nil, nil, xerrors.Errorf("failed to unmarshal enveloppe msg: %v", err)
return nil, nil, xerrors.Errorf("failed to unmarshal envelope msg: %v", err)
}

return address{id: enveloppe.From}, msg, nil
return address{id: envelope.From}, msg, nil
}

// This interface is used to have a common object between Overlay_StreamServer
Expand Down
4 changes: 2 additions & 2 deletions mino/minogrpc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,15 +1027,15 @@ func TestReceiver_Recv(t *testing.T) {
receiver.encoder = badUnmarshalAnyEncoder{}
receiver.in <- msg
_, _, err = receiver.Recv(context.Background())
require.EqualError(t, err, "failed to unmarshal enveloppe msg: message is nil")
require.EqualError(t, err, "failed to unmarshal envelope msg: message is nil")

// now with a failing unmarshal of the message
msg.Message, err = ptypes.MarshalAny(&Envelope{})
require.NoError(t, err)
receiver.encoder = badUnmarshalDynEncoder{}
receiver.in <- msg
_, _, err = receiver.Recv(context.Background())
require.EqualError(t, err, "failed to unmarshal enveloppe msg: oops")
require.EqualError(t, err, "failed to unmarshal envelope msg: oops")
}

// -----------------------------------------------------------------------------
Expand Down

0 comments on commit 0e1bf33

Please sign in to comment.