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 29d54f0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 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

0 comments on commit 29d54f0

Please sign in to comment.