Skip to content

Commit

Permalink
Remove managedRoutingTable
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Sep 10, 2019
1 parent b249fa6 commit 473306f
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 238 deletions.
100 changes: 0 additions & 100 deletions pkg/router/managed_routing_table.go

This file was deleted.

43 changes: 0 additions & 43 deletions pkg/router/managed_routing_table_test.go

This file was deleted.

33 changes: 5 additions & 28 deletions pkg/router/route_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"net"
"time"

"github.com/google/uuid"
"github.com/skycoin/dmsg/cipher"
Expand All @@ -19,10 +18,9 @@ import (

// RMConfig represents route manager configuration.
type RMConfig struct {
SetupPKs []cipher.PubKey // Trusted setup PKs.
GarbageCollectDuration time.Duration
OnConfirmLoop func(loop routing.Loop, rule routing.Rule) (err error)
OnLoopClosed func(loop routing.Loop) error
SetupPKs []cipher.PubKey // Trusted setup PKs.
OnConfirmLoop func(loop routing.Loop, rule routing.Rule) (err error)
OnLoopClosed func(loop routing.Loop) error
}

// SetupIsTrusted checks if setup node is trusted.
Expand All @@ -41,7 +39,7 @@ type routeManager struct {
conf RMConfig
n *snet.Network
sl *snet.Listener // Listens for setup node requests.
rt *managedRoutingTable
rt routing.Table
done chan struct{}
}

Expand All @@ -56,7 +54,7 @@ func newRouteManager(n *snet.Network, rt routing.Table, config RMConfig) (*route
conf: config,
n: n,
sl: sl,
rt: manageRoutingTable(rt),
rt: rt,
done: make(chan struct{}),
}, nil
}
Expand All @@ -69,9 +67,6 @@ func (rm *routeManager) Close() error {

// Serve initiates serving connections by route manager.
func (rm *routeManager) Serve() {
// Routing table garbage collect loop.
go rm.rtGarbageCollectLoop()

// Accept setup node request loop.
for {
if err := rm.serveConn(); err != nil {
Expand Down Expand Up @@ -139,24 +134,6 @@ func (rm *routeManager) handleSetupConn(conn net.Conn) error {
return proto.WritePacket(setup.RespSuccess, respBody)
}

func (rm *routeManager) rtGarbageCollectLoop() {
if rm.conf.GarbageCollectDuration <= 0 {
return
}
ticker := time.NewTicker(rm.conf.GarbageCollectDuration)
defer ticker.Stop()
for {
select {
case <-rm.done:
return
case <-ticker.C:
if err := rm.rt.Cleanup(); err != nil {
rm.Logger.WithError(err).Warnf("routing table cleanup returned error")
}
}
}
}

func (rm *routeManager) dialSetupConn(_ context.Context) (*snet.Conn, error) {
for _, sPK := range rm.conf.SetupPKs {
conn, err := rm.n.Dial(snet.DmsgType, sPK, snet.SetupPort)
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/route_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestNewRouteManager(t *testing.T) {
env := snettest.NewEnv(t, []snettest.KeyPair{{PK: pk, SK: sk}})
defer env.Teardown()

rt := routing.InMemoryRoutingTable()
rt := routing.New()

rm, err := newRouteManager(env.Nets[0], rt, RMConfig{})
require.NoError(t, err)
Expand Down
28 changes: 10 additions & 18 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ const (
// DefaultRouteKeepAlive is the default expiration interval for routes
DefaultRouteKeepAlive = 2 * time.Hour

// DefaultGarbageCollectDuration is the default duration for garbage collection of routing rules.
DefaultGarbageCollectDuration = time.Second * 5

minHops = 0
maxHops = 50
)
Expand All @@ -37,24 +34,20 @@ var log = logging.MustGetLogger("router")

// Config configures Router.
type Config struct {
Logger *logging.Logger
PubKey cipher.PubKey
SecKey cipher.SecKey
TransportManager *transport.Manager
RoutingTable routing.Table
RouteFinder routeFinder.Client
SetupNodes []cipher.PubKey
GarbageCollectDuration time.Duration
Logger *logging.Logger
PubKey cipher.PubKey
SecKey cipher.SecKey
TransportManager *transport.Manager
RoutingTable routing.Table
RouteFinder routeFinder.Client
SetupNodes []cipher.PubKey
}

// SetDefaults sets default values for certain empty values.
func (c *Config) SetDefaults() {
if c.Logger == nil {
c.Logger = log
}
if c.GarbageCollectDuration <= 0 {
c.GarbageCollectDuration = DefaultGarbageCollectDuration
}
}

// Router implements node.PacketRouter. It manages routing table by
Expand Down Expand Up @@ -90,10 +83,9 @@ func New(n *snet.Network, config *Config) (*Router, error) {

// Prepare route manager.
rm, err := newRouteManager(n, config.RoutingTable, RMConfig{
SetupPKs: config.SetupNodes,
GarbageCollectDuration: config.GarbageCollectDuration,
OnConfirmLoop: r.confirmLoop,
OnLoopClosed: r.loopClosed,
SetupPKs: config.SetupNodes,
OnConfirmLoop: r.confirmLoop,
OnLoopClosed: r.loopClosed,
})
if err != nil {
return nil, err
Expand Down
15 changes: 7 additions & 8 deletions pkg/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,13 @@ func NewTestEnv(t *testing.T, nets []*snet.Network) *TestEnv {

func (e *TestEnv) GenRouterConfig(i int) *Config {
return &Config{
Logger: logging.MustGetLogger(fmt.Sprintf("router_%d", i)),
PubKey: e.TpMngrConfs[i].PubKey,
SecKey: e.TpMngrConfs[i].SecKey,
TransportManager: e.TpMngrs[i],
RoutingTable: routing.InMemoryRoutingTable(),
RouteFinder: routeFinder.NewMock(),
SetupNodes: nil, // TODO
GarbageCollectDuration: DefaultGarbageCollectDuration,
Logger: logging.MustGetLogger(fmt.Sprintf("router_%d", i)),
PubKey: e.TpMngrConfs[i].PubKey,
SecKey: e.TpMngrConfs[i].SecKey,
TransportManager: e.TpMngrs[i],
RoutingTable: routing.New(),
RouteFinder: routeFinder.NewMock(),
SetupNodes: nil, // TODO
}
}

Expand Down
Loading

0 comments on commit 473306f

Please sign in to comment.