diff --git a/cmd/skywire-cli/commands/node/gen-config.go b/cmd/skywire-cli/commands/node/gen-config.go index 1058b00f9..c431c8666 100644 --- a/cmd/skywire-cli/commands/node/gen-config.go +++ b/cmd/skywire-cli/commands/node/gen-config.go @@ -62,7 +62,6 @@ func homeConfig() *visor.Config { c := defaultConfig() c.AppsPath = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/apps") c.Transport.LogStore.Location = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/transport_logs") - c.Routing.Table.Location = filepath.Join(pathutil.HomeDir(), ".skycoin/skywire/routing.db") return c } @@ -70,7 +69,6 @@ func localConfig() *visor.Config { c := defaultConfig() c.AppsPath = "/usr/local/skycoin/skywire/apps" c.Transport.LogStore.Location = "/usr/local/skycoin/skywire/transport_logs" - c.Routing.Table.Location = "/usr/local/skycoin/skywire/routing.db" return c } @@ -105,8 +103,6 @@ func defaultConfig() *visor.Config { log.WithError(err).Warnf("Failed to unmarshal default setup node public key %s", defaultSetupNodePK) } conf.Routing.SetupNodes = []cipher.PubKey{sPK} - conf.Routing.Table.Type = "boltdb" - conf.Routing.Table.Location = "./skywire/routing.db" conf.Routing.RouteFinderTimeout = visor.Duration(10 * time.Second) conf.Hypervisors = []visor.HypervisorConfig{} diff --git a/integration/generic/nodeA.json b/integration/generic/nodeA.json index 67baf6ec3..8fe38dd06 100644 --- a/integration/generic/nodeA.json +++ b/integration/generic/nodeA.json @@ -19,11 +19,7 @@ "setup_nodes": [ "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" ], - "route_finder": "https://routefinder.skywire.skycoin.net/", - "table": { - "type": "boltdb", - "location": "./local/nodeA/routing.db" - } + "route_finder": "https://routefinder.skywire.skycoin.net/" }, "apps": [ { diff --git a/integration/generic/nodeC.json b/integration/generic/nodeC.json index 684caa34f..38d08b5d4 100644 --- a/integration/generic/nodeC.json +++ b/integration/generic/nodeC.json @@ -19,11 +19,7 @@ "setup_nodes": [ "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" ], - "route_finder": "https://routefinder.skywire.skycoin.net/", - "table": { - "type": "boltdb", - "location": "./local/nodeC/routing.db" - } + "route_finder": "https://routefinder.skywire.skycoin.net/" }, "apps": [ { diff --git a/integration/intermediary-nodeB.json b/integration/intermediary-nodeB.json index ca657feb4..9f2a4d464 100644 --- a/integration/intermediary-nodeB.json +++ b/integration/intermediary-nodeB.json @@ -20,11 +20,7 @@ "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" ], "route_finder": "https://routefinder.skywire.skycoin.net/", - "route_finder_timeout": "60s", - "table": { - "type": "boltdb", - "location": "./local/nodeB/routing.db" - } + "route_finder_timeout": "60s" }, "apps": [], "trusted_nodes": [], diff --git a/integration/messaging/nodeA.json b/integration/messaging/nodeA.json index 3f95613c3..a99b22e3a 100644 --- a/integration/messaging/nodeA.json +++ b/integration/messaging/nodeA.json @@ -20,11 +20,7 @@ "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" ], "route_finder": "https://routefinder.skywire.skycoin.net/", - "route_finder_timeout": "60s", - "table": { - "type": "boltdb", - "location": "./local/nodeA/routing.db" - } + "route_finder_timeout": "60s" }, "apps": [ { diff --git a/integration/messaging/nodeC.json b/integration/messaging/nodeC.json index f864ecd0d..6382f4436 100644 --- a/integration/messaging/nodeC.json +++ b/integration/messaging/nodeC.json @@ -20,11 +20,7 @@ "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" ], "route_finder": "https://routefinder.skywire.skycoin.net/", - "route_finder_timeout": "60s", - "table": { - "type": "boltdb", - "location": "./local/nodeC/routing.db" - } + "route_finder_timeout": "60s" }, "apps": [ { diff --git a/integration/proxy/nodeA.json b/integration/proxy/nodeA.json index ea4352493..17a0b03ae 100644 --- a/integration/proxy/nodeA.json +++ b/integration/proxy/nodeA.json @@ -19,11 +19,7 @@ "setup_nodes": [ "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" ], - "route_finder": "https://routefinder.skywire.skycoin.net/", - "table": { - "type": "boltdb", - "location": "./local/nodeA/routing.db" - } + "route_finder": "https://routefinder.skywire.skycoin.net/" }, "apps": [ { diff --git a/integration/proxy/nodeC.json b/integration/proxy/nodeC.json index 31a6c5162..604606494 100644 --- a/integration/proxy/nodeC.json +++ b/integration/proxy/nodeC.json @@ -19,11 +19,7 @@ "setup_nodes": [ "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" ], - "route_finder": "https://routefinder.skywire.skycoin.net/", - "table": { - "type": "boltdb", - "location": "./local/nodeC/routing.db" - } + "route_finder": "https://routefinder.skywire.skycoin.net/" }, "apps": [ { diff --git a/integration/ssh/nodeA.json b/integration/ssh/nodeA.json index 67baf6ec3..8fe38dd06 100644 --- a/integration/ssh/nodeA.json +++ b/integration/ssh/nodeA.json @@ -19,11 +19,7 @@ "setup_nodes": [ "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" ], - "route_finder": "https://routefinder.skywire.skycoin.net/", - "table": { - "type": "boltdb", - "location": "./local/nodeA/routing.db" - } + "route_finder": "https://routefinder.skywire.skycoin.net/" }, "apps": [ { diff --git a/integration/ssh/nodeC.json b/integration/ssh/nodeC.json index 684caa34f..38d08b5d4 100644 --- a/integration/ssh/nodeC.json +++ b/integration/ssh/nodeC.json @@ -19,11 +19,7 @@ "setup_nodes": [ "0324579f003e6b4048bae2def4365e634d8e0e3054a20fc7af49daf2a179658557" ], - "route_finder": "https://routefinder.skywire.skycoin.net/", - "table": { - "type": "boltdb", - "location": "./local/nodeC/routing.db" - } + "route_finder": "https://routefinder.skywire.skycoin.net/" }, "apps": [ { diff --git a/pkg/routing/boltdb_routing_table.go b/pkg/routing/boltdb_routing_table.go deleted file mode 100644 index 033a6da9c..000000000 --- a/pkg/routing/boltdb_routing_table.go +++ /dev/null @@ -1,165 +0,0 @@ -package routing - -import ( - "encoding/binary" - "errors" - "fmt" - "math" - - "github.com/skycoin/skycoin/src/util/logging" - "go.etcd.io/bbolt" -) - -var boltDBBucket = []byte("routing") -var log = logging.MustGetLogger("routing") - -// BoltDBRoutingTable implements RoutingTable on top of BoltDB. -type boltDBRoutingTable struct { - db *bbolt.DB -} - -// BoltDBRoutingTable constructs a new BoldDBRoutingTable. -func BoltDBRoutingTable(path string) (Table, error) { - db, err := bbolt.Open(path, 0600, nil) - if err != nil { - return nil, err - } - - err = db.Update(func(tx *bbolt.Tx) error { - if _, err := tx.CreateBucketIfNotExists(boltDBBucket); err != nil { - return fmt.Errorf("failed to create bucket: %s", err) - } - - return nil - }) - if err != nil { - return nil, err - } - - return &boltDBRoutingTable{db}, nil -} - -// AddRule adds routing rule to the table and returns assigned Route ID. -func (rt *boltDBRoutingTable) AddRule(rule Rule) (routeID RouteID, err error) { - err = rt.db.Update(func(tx *bbolt.Tx) error { - b := tx.Bucket(boltDBBucket) - nextID, err := b.NextSequence() - if err != nil { - return err - } - - if nextID > math.MaxUint32 { - return errors.New("no available routeIDs") - } - - routeID = RouteID(nextID) - return b.Put(binaryID(routeID), []byte(rule)) - }) - - return routeID, err -} - -// SetRule sets RoutingRule for a given RouteID. -func (rt *boltDBRoutingTable) SetRule(routeID RouteID, rule Rule) error { - return rt.db.Update(func(tx *bbolt.Tx) error { - b := tx.Bucket(boltDBBucket) - - return b.Put(binaryID(routeID), []byte(rule)) - }) -} - -// Rule returns RoutingRule with a given RouteID. -func (rt *boltDBRoutingTable) Rule(routeID RouteID) (Rule, error) { - var rule Rule - err := rt.db.View(func(tx *bbolt.Tx) error { - b := tx.Bucket(boltDBBucket) - rule = b.Get(binaryID(routeID)) - return nil - }) - if rule == nil { - return nil, fmt.Errorf("rule of routeID '%v' does not exist", routeID) - } - return rule, err -} - -// RangeRules iterates over all rules and yields values to the rangeFunc until `next` is false. -func (rt *boltDBRoutingTable) RangeRules(rangeFunc RangeFunc) error { - return rt.db.View(func(tx *bbolt.Tx) error { - b := tx.Bucket(boltDBBucket) - f := func(k, v []byte) error { - if !rangeFunc(RouteID(binary.BigEndian.Uint32(k)), v) { - return errors.New("iterator stopped") - } - - return nil - } - if err := b.ForEach(f); err != nil { - log.Warn(err) - } - return nil - }) -} - -// Rules returns RoutingRules for a given RouteIDs. -func (rt *boltDBRoutingTable) Rules(routeIDs ...RouteID) (rules []Rule, err error) { - rules = []Rule{} - err = rt.db.View(func(tx *bbolt.Tx) error { - b := tx.Bucket(boltDBBucket) - - for _, routeID := range routeIDs { - rule := b.Get(binaryID(routeID)) - if rule != nil { - rules = append(rules, rule) - } - } - return nil - }) - - return rules, err -} - -// DeleteRules removes RoutingRules with a given a RouteIDs. -func (rt *boltDBRoutingTable) DeleteRules(routeIDs ...RouteID) error { - return rt.db.Update(func(tx *bbolt.Tx) error { - b := tx.Bucket(boltDBBucket) - - var dErr error - for _, routeID := range routeIDs { - if err := b.Delete(binaryID(routeID)); err != nil { - dErr = err - } - } - - return dErr - }) -} - -// Count returns the number of routing rules stored. -func (rt *boltDBRoutingTable) Count() (count int) { - err := rt.db.View(func(tx *bbolt.Tx) error { - b := tx.Bucket(boltDBBucket) - - stats := b.Stats() - count = stats.KeyN - return nil - }) - if err != nil { - return 0 - } - - return count -} - -// Close closes underlying BoltDB instance. -func (rt *boltDBRoutingTable) Close() error { - if rt == nil { - return nil - } - return rt.db.Close() -} - -func binaryID(v RouteID) []byte { - b := make([]byte, 4) - binary.BigEndian.PutUint32(b, uint32(v)) - return b -} diff --git a/pkg/routing/boltdb_routing_table_test.go b/pkg/routing/boltdb_routing_table_test.go deleted file mode 100644 index 65506604b..000000000 --- a/pkg/routing/boltdb_routing_table_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package routing - -import ( - "io/ioutil" - "os" - "testing" - - "github.com/stretchr/testify/require" -) - -func TestBoltDBRoutingTable(t *testing.T) { - dbfile, err := ioutil.TempFile("", "routes.db") - require.NoError(t, err) - if err != nil { - log.Fatal(err) - } - - defer func() { - require.NoError(t, os.Remove(dbfile.Name())) - }() - - tbl, err := BoltDBRoutingTable(dbfile.Name()) - require.NoError(t, err) - - RoutingTableSuite(t, tbl) -} diff --git a/pkg/visor/config.go b/pkg/visor/config.go index 36451dd6d..41290ea20 100644 --- a/pkg/visor/config.go +++ b/pkg/visor/config.go @@ -47,10 +47,6 @@ type Config struct { SetupNodes []cipher.PubKey `json:"setup_nodes"` RouteFinder string `json:"route_finder"` RouteFinderTimeout Duration `json:"route_finder_timeout"` - Table struct { - Type string `json:"type"` - Location string `json:"location"` - } `json:"table"` } `json:"routing"` Uptime struct { @@ -108,10 +104,6 @@ func (c *Config) TransportLogStore() (transport.LogStore, error) { // RoutingTable returns configure routing.Table. func (c *Config) RoutingTable() (routing.Table, error) { - if c.Routing.Table.Type == "boltdb" { - return routing.BoltDBRoutingTable(c.Routing.Table.Location) - } - return routing.InMemoryRoutingTable(), nil } diff --git a/pkg/visor/config_test.go b/pkg/visor/config_test.go index 0a278bdf4..fd3426b6f 100644 --- a/pkg/visor/config_test.go +++ b/pkg/visor/config_test.go @@ -80,13 +80,6 @@ func TestRoutingTable(t *testing.T) { }() conf := Config{} - conf.Routing.Table.Type = "boltdb" - conf.Routing.Table.Location = tmpfile.Name() - _, err = conf.RoutingTable() - require.NoError(t, err) - - conf.Routing.Table.Type = "memory" - conf.Routing.Table.Location = "" _, err = conf.RoutingTable() require.NoError(t, err) }