Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-pubsub
Commits
eef4d41e
Commit
eef4d41e
authored
May 16, 2020
by
Edgar Aroutiounian
Committed by
vyzo
May 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[blacklist] Use .Has check before add in time cached version - adjust signature
parent
9de0241d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
blacklist.go
blacklist.go
+11
-5
No files found.
blacklist.go
View file @
eef4d41e
...
...
@@ -10,7 +10,7 @@ import (
// Blacklist is an interface for peer blacklisting.
type
Blacklist
interface
{
Add
(
peer
.
ID
)
Add
(
peer
.
ID
)
bool
Contains
(
peer
.
ID
)
bool
}
...
...
@@ -22,8 +22,9 @@ func NewMapBlacklist() Blacklist {
return
MapBlacklist
(
make
(
map
[
peer
.
ID
]
struct
{}))
}
func
(
b
MapBlacklist
)
Add
(
p
peer
.
ID
)
{
func
(
b
MapBlacklist
)
Add
(
p
peer
.
ID
)
bool
{
b
[
p
]
=
struct
{}{}
return
true
}
func
(
b
MapBlacklist
)
Contains
(
p
peer
.
ID
)
bool
{
...
...
@@ -43,11 +44,16 @@ func NewTimeCachedBlacklist(expiry time.Duration) (Blacklist, error) {
return
b
,
nil
}
func
(
b
*
TimeCachedBlacklist
)
Add
(
p
peer
.
ID
)
{
// Add returns a bool saying whether Add of peer was successful
func
(
b
*
TimeCachedBlacklist
)
Add
(
p
peer
.
ID
)
bool
{
b
.
Lock
()
defer
b
.
Unlock
()
b
.
tc
.
Add
(
p
.
String
())
s
:=
p
.
String
()
if
b
.
tc
.
Has
(
s
)
{
return
false
}
b
.
tc
.
Add
(
s
)
return
true
}
func
(
b
*
TimeCachedBlacklist
)
Contains
(
p
peer
.
ID
)
bool
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment