From 02ec61be9ef664a6e783041625c2293f1043fafa Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Thu, 12 Dec 2019 13:17:24 +0300 Subject: [PATCH] Fix `NextRouterID` handling, fix router test --- pkg/router/router.go | 2 +- pkg/router/router_test.go | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/router/router.go b/pkg/router/router.go index d79f4590c1..19a19a46e6 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -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 } diff --git a/pkg/router/router_test.go b/pkg/router/router_test.go index a01b4dbc37..ae2c9b3cae 100644 --- a/pkg/router/router_test.go +++ b/pkg/router/router_test.go @@ -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) { @@ -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) { @@ -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(), @@ -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.