Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
goshimmer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iota-imt
goshimmer
Commits
db0dad7e
Commit
db0dad7e
authored
5 years ago
by
Wolfgang Welz
Browse files
Options
Downloads
Patches
Plain Diff
Add peer storage
parent
2f6f720e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugins/autopeering/peerstorage/peerstorage.go
+82
-0
82 additions, 0 deletions
plugins/autopeering/peerstorage/peerstorage.go
plugins/autopeering/plugin.go
+2
-0
2 additions, 0 deletions
plugins/autopeering/plugin.go
with
84 additions
and
0 deletions
plugins/autopeering/peerstorage/peerstorage.go
0 → 100644
+
82
−
0
View file @
db0dad7e
package
peerstorage
import
(
"bytes"
"strconv"
"github.com/iotaledger/goshimmer/packages/database"
"github.com/iotaledger/goshimmer/packages/events"
"github.com/iotaledger/goshimmer/packages/node"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers"
"github.com/iotaledger/goshimmer/plugins/autopeering/types/peer"
)
const
peerDbName
string
=
"peers"
var
peerDb
database
.
Database
func
initDb
()
{
db
,
err
:=
database
.
Get
(
peerDbName
)
if
err
!=
nil
{
panic
(
err
)
}
peerDb
=
db
}
func
storePeer
(
p
*
peer
.
Peer
)
{
err
:=
peerDb
.
Set
(
p
.
Identity
.
Identifier
,
p
.
Marshal
())
if
err
!=
nil
{
panic
(
err
)
}
}
func
removePeer
(
p
*
peer
.
Peer
)
{
err
:=
peerDb
.
Delete
(
p
.
Identity
.
Identifier
)
if
err
!=
nil
{
panic
(
err
)
}
}
func
loadPeers
(
plugin
*
node
.
Plugin
)
{
var
count
int
err
:=
peerDb
.
ForEach
(
func
(
key
[]
byte
,
value
[]
byte
)
{
peer
,
err
:=
peer
.
Unmarshal
(
value
)
if
err
!=
nil
{
panic
(
err
)
}
// the peers are stored by identifier in the db
if
!
bytes
.
Equal
(
key
,
peer
.
Identity
.
Identifier
)
{
panic
(
"Invalid item in '"
+
peerDbName
+
"' database"
)
}
knownpeers
.
INSTANCE
.
AddOrUpdate
(
peer
)
count
++
plugin
.
LogDebug
(
"Added stored peer: "
+
peer
.
Address
.
String
()
+
" / "
+
peer
.
Identity
.
StringIdentifier
)
})
if
err
!=
nil
{
panic
(
err
)
}
plugin
.
LogSuccess
(
"Restored "
+
strconv
.
Itoa
(
count
)
+
" peers from database"
)
}
func
Configure
(
plugin
*
node
.
Plugin
)
{
initDb
()
// do not store the entry nodes by ignoring all peers currently contained in konwnpeers
// add peers from db
loadPeers
(
plugin
)
// subscribe to all known peers' events
knownpeers
.
INSTANCE
.
Events
.
Add
.
Attach
(
events
.
NewClosure
(
func
(
p
*
peer
.
Peer
)
{
storePeer
(
p
)
}))
knownpeers
.
INSTANCE
.
Events
.
Update
.
Attach
(
events
.
NewClosure
(
func
(
p
*
peer
.
Peer
)
{
storePeer
(
p
)
}))
knownpeers
.
INSTANCE
.
Events
.
Remove
.
Attach
(
events
.
NewClosure
(
func
(
p
*
peer
.
Peer
)
{
removePeer
(
p
)
}))
}
This diff is collapsed.
Click to expand it.
plugins/autopeering/plugin.go
+
2
−
0
View file @
db0dad7e
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers"
"github.com/iotaledger/goshimmer/plugins/autopeering/instances/knownpeers"
"github.com/iotaledger/goshimmer/plugins/autopeering/peerstorage"
"github.com/iotaledger/goshimmer/plugins/autopeering/protocol"
"github.com/iotaledger/goshimmer/plugins/autopeering/protocol"
"github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager"
"github.com/iotaledger/goshimmer/plugins/autopeering/saltmanager"
"github.com/iotaledger/goshimmer/plugins/autopeering/server"
"github.com/iotaledger/goshimmer/plugins/autopeering/server"
...
@@ -22,6 +23,7 @@ func configure(plugin *node.Plugin) {
...
@@ -22,6 +23,7 @@ func configure(plugin *node.Plugin) {
instances
.
Configure
(
plugin
)
instances
.
Configure
(
plugin
)
server
.
Configure
(
plugin
)
server
.
Configure
(
plugin
)
protocol
.
Configure
(
plugin
)
protocol
.
Configure
(
plugin
)
peerstorage
.
Configure
(
plugin
)
daemon
.
Events
.
Shutdown
.
Attach
(
events
.
NewClosure
(
func
()
{
daemon
.
Events
.
Shutdown
.
Attach
(
events
.
NewClosure
(
func
()
{
server
.
Shutdown
(
plugin
)
server
.
Shutdown
(
plugin
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment