Skip to content

Commit

Permalink
Fix NextRouterID handling, fix router test
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkren committed Dec 12, 2019
1 parent 3c6eb73 commit 02ec61b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func (r *router) forwardPacket(ctx context.Context, payload []byte, rule routing
return errors.New("unknown transport")
}

packet := routing.MakeDataPacket(rule.KeyRouteID(), payload)
packet := routing.MakeDataPacket(rule.NextRouteID(), payload)
if err := tp.WritePacket(ctx, packet); err != nil {
return err
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestRouter_Serve(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, packet.Size(), recvPacket.Size())
assert.Equal(t, packet.Payload(), recvPacket.Payload())
assert.Equal(t, fwdRtID[0], packet.RouteID())
assert.Equal(t, routing.RouteID(1), recvPacket.RouteID())
})

t.Run("handlePacket_intFwdRule", func(t *testing.T) {
Expand All @@ -138,7 +138,7 @@ func TestRouter_Serve(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, packet.Size(), recvPacket.Size())
assert.Equal(t, packet.Payload(), recvPacket.Payload())
assert.Equal(t, fwdRtID[0], packet.RouteID())
assert.Equal(t, routing.RouteID(5), recvPacket.RouteID())
})

t.Run("handlePacket_cnsmRule", func(t *testing.T) {
Expand All @@ -158,8 +158,10 @@ func TestRouter_Serve(t *testing.T) {

fwdRule := routing.ForwardRule(1*time.Hour, dstRtIDs[0], routing.RouteID(7), tp1.Entry.ID, keys[0].PK, keys[1].PK, 0, 0)
cnsmRule := routing.ConsumeRule(1*time.Hour, dstRtIDs[1], keys[1].PK, keys[0].PK, 0, 0)
//err = r1.rt.SaveRule(cnsmRule)
//require.NoError(t, err)
err = r1.rt.SaveRule(fwdRule)
require.NoError(t, err)
err = r1.rt.SaveRule(cnsmRule)
require.NoError(t, err)
fwdRtDesc := fwdRule.RouteDescriptor()
r1.saveRouteGroupRules(routing.EdgeRules{
Desc: fwdRtDesc.Invert(),
Expand All @@ -174,7 +176,7 @@ func TestRouter_Serve(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, packet.Size(), recvPacket.Size())
assert.Equal(t, packet.Payload(), recvPacket.Payload())
assert.Equal(t, dstRtIDs[1], packet.RouteID())
assert.Equal(t, dstRtIDs[1], recvPacket.RouteID())
})

// TODO(evanlinjin): I'm having so much trouble with this I officially give up.
Expand Down

0 comments on commit 02ec61b

Please sign in to comment.