From a22741507b73cc0a6db5ccabf9019e4388a0d01e Mon Sep 17 00:00:00 2001 From: Sir Darkrengarius Date: Tue, 12 Nov 2019 18:47:44 +0300 Subject: [PATCH] Fix router `RemoveRouteDescriptor` test --- pkg/router/router_test.go | 11 +++++++---- pkg/routing/rule.go | 8 ++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/router/router_test.go b/pkg/router/router_test.go index b3ef75c6b..bddb13aed 100644 --- a/pkg/router/router_test.go +++ b/pkg/router/router_test.go @@ -7,7 +7,10 @@ import ( "testing" "time" + "github.com/google/uuid" + "github.com/SkycoinProject/dmsg" + cipher "github.com/SkycoinProject/dmsg/cipher" "github.com/SkycoinProject/skycoin/src/util/logging" "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -165,7 +168,7 @@ func TestRouter_Serve(t *testing.T) { } // TODO (Darkren): fix tests -/*func TestRouter_Rules(t *testing.T) { +func TestRouter_Rules(t *testing.T) { pk, sk := cipher.GenerateKeyPair() env := snettest.NewEnv(t, []snettest.KeyPair{{PK: pk, SK: sk}}) @@ -255,7 +258,7 @@ func TestRouter_Serve(t *testing.T) { }) // TEST: Ensure AddRule and DeleteRule requests from a SetupNode does as expected. - t.Run("AddRemoveRule", func(t *testing.T) { + /*t.Run("AddRemoveRule", func(t *testing.T) { clearRules() // Add/Remove rules multiple times. @@ -441,8 +444,8 @@ func TestRouter_Serve(t *testing.T) { assert.Equal(t, routing.Port(2), inLoop.Local.Port) assert.Equal(t, routing.Port(3), inLoop.Remote.Port) assert.Equal(t, pk, inLoop.Remote.PubKey) - }) -}*/ + })*/ +} type TestEnv struct { TpD transport.DiscoveryClient diff --git a/pkg/routing/rule.go b/pkg/routing/rule.go index eb52664d5..fe5ddece7 100644 --- a/pkg/routing/rule.go +++ b/pkg/routing/rule.go @@ -248,10 +248,14 @@ type RouteDescriptor [routeDescriptorSize]byte func NewRouteDescriptor(srcPK, dstPK cipher.PubKey, srcPort, dstPort Port) RouteDescriptor { var desc RouteDescriptor - desc.setSrcPK(srcPK) + p := copy(desc[:pkSize], srcPK[:]) + p = copy(desc[p:p+pkSize], dstPK[:]) + binary.BigEndian.PutUint16(desc[p:p+2], uint16(srcPort)) + binary.BigEndian.PutUint16(desc[p+2:p+2*2], uint16(dstPort)) + /*desc.setSrcPK(srcPK) desc.setDstPK(dstPK) desc.setSrcPort(srcPort) - desc.setDstPort(dstPort) + desc.setDstPort(dstPort)*/ return desc }