Skip to content
This repository has been archived by the owner on Nov 2, 2018. It is now read-only.

Commit

Permalink
merge load functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Jan 18, 2018
1 parent 606e8f7 commit 395f8ef
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
4 changes: 0 additions & 4 deletions modules/gateway/gateway.go
Expand Up @@ -249,10 +249,6 @@ func New(addr string, bootstrap bool, persistDir string) (*Gateway, error) {
if loadErr := g.load(); loadErr != nil && !os.IsNotExist(loadErr) {
return nil, loadErr
}
// Do the same for the blacklist.
if loadErr := g.loadBlacklist(); loadErr != nil && !os.IsNotExist(loadErr) {
return nil, loadErr
}
// Spawn the thread to periodically save the gateway.
go g.threadedSaveLoop()
// Make sure that the gateway saves after shutdown.
Expand Down
13 changes: 7 additions & 6 deletions modules/gateway/persist.go
Expand Up @@ -52,22 +52,23 @@ func (g *Gateway) persistDataBlacklist() (ips []string) {

// load loads the Gateway's persistent data from disk.
func (g *Gateway) load() error {
// load nodes
var nodes []*node
err := persist.LoadJSON(persistMetadata, &nodes, filepath.Join(g.persistDir, nodesFile))
if err != nil {
// COMPATv1.3.0
return g.loadv033persist()
err = g.loadv033persist()
if err != nil {
return err
}
}
for i := range nodes {
g.nodes[nodes[i].NetAddress] = nodes[i]
}
return nil
}

// load loads the Gateway's blacklisted ips from disk.
func (g *Gateway) loadBlacklist() error {
// load blacklist
var ips []string
err := persist.LoadJSON(persistMetadataBlacklist, &ips, filepath.Join(g.persistDir, blacklistFile))
err = persist.LoadJSON(persistMetadataBlacklist, &ips, filepath.Join(g.persistDir, blacklistFile))
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion modules/gateway/persist_test.go
Expand Up @@ -2,6 +2,7 @@ package gateway

import (
"bytes"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -41,7 +42,7 @@ func TestLoadv033(t *testing.T) {
persistDir: filepath.Join("testdata", t.Name()),
log: log,
}
if err := g.load(); err != nil {
if err := g.load(); err != nil && !os.IsNotExist(err) {
t.Fatal(err)
}

Expand Down

0 comments on commit 395f8ef

Please sign in to comment.