This repository has been archived by the owner on Nov 2, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 442
User-manual ‘disconnect’ adds a peer to a blacklist #2664
Open
ChrisSchinnerl
wants to merge
6
commits into
master
Choose a base branch
from
gateway-blacklist
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2d78d6d
create wrapper functions and blacklist field
ChrisSchinnerl 3ba8585
add persistence
ChrisSchinnerl 606e8f7
added tests
ChrisSchinnerl 395f8ef
merge load functions
ChrisSchinnerl 327450c
fix ndfs in tests
ChrisSchinnerl 5999d81
add NDF safe wrapper for connecting and disconnecting to/from nodes
ChrisSchinnerl File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,8 @@ type Gateway struct { | |
handlers map[rpcID]modules.RPCFunc | ||
initRPCs map[string]modules.RPCFunc | ||
|
||
// blacklist are peers that the gateway shouldn't connect to | ||
// | ||
// nodes is the set of all known nodes (i.e. potential peers). | ||
// | ||
// peers are the nodes that the gateway is currently connected to. | ||
|
@@ -141,9 +143,10 @@ type Gateway struct { | |
// and would block any threads.Flush() calls. So a second threadgroup is | ||
// added which handles clean-shutdown for the peers, without blocking | ||
// threads.Flush() calls. | ||
nodes map[modules.NetAddress]*node | ||
peers map[modules.NetAddress]*peer | ||
peerTG siasync.ThreadGroup | ||
blacklist map[string]struct{} | ||
nodes map[modules.NetAddress]*node | ||
peers map[modules.NetAddress]*peer | ||
peerTG siasync.ThreadGroup | ||
|
||
// Utilities. | ||
log *persist.Logger | ||
|
@@ -198,8 +201,9 @@ func New(addr string, bootstrap bool, persistDir string) (*Gateway, error) { | |
handlers: make(map[rpcID]modules.RPCFunc), | ||
initRPCs: make(map[string]modules.RPCFunc), | ||
|
||
nodes: make(map[modules.NetAddress]*node), | ||
peers: make(map[modules.NetAddress]*peer), | ||
blacklist: make(map[string]struct{}), | ||
nodes: make(map[modules.NetAddress]*node), | ||
peers: make(map[modules.NetAddress]*peer), | ||
|
||
persistDir: persistDir, | ||
} | ||
|
@@ -245,6 +249,10 @@ 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 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all persist loading should happen in |
||
// Spawn the thread to periodically save the gateway. | ||
go g.threadedSaveLoop() | ||
// Make sure that the gateway saves after shutdown. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need these? Wouldn't a
Blacklist
method make more sense? It's not clear to me that a user-initiated disconnect always implies that the user wants to blacklist the peer.As always, we may want to check how bitcoind solves these problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think bitcoind has a
setban
function that allows a user to ban a node for a certain period of time.If we don't like this behaviour we can also change this PR to introduce a new endpoint. I started it because it was one of the todos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DavidVorick any thoughts on that?