Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
613b8179
Commit
613b8179
authored
Sep 09, 2021
by
libangzhu
Committed by
vipwzw
Sep 13, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename func
parent
5e7b70b5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
10 deletions
+10
-10
common.go
plugin/p2p/gossip/common.go
+1
-1
p2p_test.go
plugin/p2p/gossip/p2p_test.go
+5
-5
p2pcli.go
plugin/p2p/gossip/p2pcli.go
+4
-4
No files found.
plugin/p2p/gossip/common.go
View file @
613b8179
...
@@ -30,7 +30,7 @@ var P2pComm Comm
...
@@ -30,7 +30,7 @@ var P2pComm Comm
type
Comm
struct
{}
type
Comm
struct
{}
//CheckNetAddr check addr or ip format
//CheckNetAddr check addr or ip format
func
(
Comm
)
Check
NetAddr
(
addr
string
)
(
string
,
int64
,
error
)
{
func
(
Comm
)
Parase
NetAddr
(
addr
string
)
(
string
,
int64
,
error
)
{
//check peerAddr
//check peerAddr
if
!
strings
.
Contains
(
addr
,
":"
)
{
//only ip
if
!
strings
.
Contains
(
addr
,
":"
)
{
//only ip
if
net
.
ParseIP
(
addr
)
==
nil
{
if
net
.
ParseIP
(
addr
)
==
nil
{
...
...
plugin/p2p/gossip/p2p_test.go
View file @
613b8179
...
@@ -493,18 +493,18 @@ func TestBytesToInt32(t *testing.T) {
...
@@ -493,18 +493,18 @@ func TestBytesToInt32(t *testing.T) {
}
}
func
TestComm_CheckNetAddr
(
t
*
testing
.
T
)
{
func
TestComm_CheckNetAddr
(
t
*
testing
.
T
)
{
_
,
_
,
err
:=
P2pComm
.
Check
NetAddr
(
"192.16666.0.1"
)
_
,
_
,
err
:=
P2pComm
.
Parase
NetAddr
(
"192.16666.0.1"
)
assert
.
NotNil
(
t
,
err
)
assert
.
NotNil
(
t
,
err
)
assert
.
Equal
(
t
,
"invalid ip"
,
err
.
Error
())
assert
.
Equal
(
t
,
"invalid ip"
,
err
.
Error
())
_
,
_
,
err
=
P2pComm
.
Check
NetAddr
(
"192.169.0.1:899999"
)
_
,
_
,
err
=
P2pComm
.
Parase
NetAddr
(
"192.169.0.1:899999"
)
assert
.
NotNil
(
t
,
err
)
assert
.
NotNil
(
t
,
err
)
assert
.
Equal
(
t
,
"invalid port"
,
err
.
Error
())
assert
.
Equal
(
t
,
"invalid port"
,
err
.
Error
())
_
,
_
,
err
=
P2pComm
.
Check
NetAddr
(
"192.169.257.1:899"
)
_
,
_
,
err
=
P2pComm
.
Parase
NetAddr
(
"192.169.257.1:899"
)
assert
.
NotNil
(
t
,
err
)
assert
.
NotNil
(
t
,
err
)
assert
.
Equal
(
t
,
"invalid ip"
,
err
.
Error
())
assert
.
Equal
(
t
,
"invalid ip"
,
err
.
Error
())
_
,
_
,
err
=
P2pComm
.
Check
NetAddr
(
"192.169.1.1"
)
_
,
_
,
err
=
P2pComm
.
Parase
NetAddr
(
"192.169.1.1"
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
_
,
_
,
err
=
P2pComm
.
Check
NetAddr
(
"192.169.1.1:123"
)
_
,
_
,
err
=
P2pComm
.
Parase
NetAddr
(
"192.169.1.1:123"
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
}
}
...
...
plugin/p2p/gossip/p2pcli.go
View file @
613b8179
...
@@ -675,7 +675,7 @@ func (m *Cli) AddPeerToBlacklist(msg *queue.Message, taskindex int64) {
...
@@ -675,7 +675,7 @@ func (m *Cli) AddPeerToBlacklist(msg *queue.Message, taskindex int64) {
if
blackPeer
.
PeerAddr
!=
""
{
//把IP或者IP:PORT加入 黑名单
if
blackPeer
.
PeerAddr
!=
""
{
//把IP或者IP:PORT加入 黑名单
//check peerAddr
//check peerAddr
ip
,
_
,
err
:=
P2pComm
.
Check
NetAddr
(
blackPeer
.
GetPeerAddr
())
ip
,
_
,
err
:=
P2pComm
.
Parase
NetAddr
(
blackPeer
.
GetPeerAddr
())
if
err
!=
nil
{
if
err
!=
nil
{
msg
.
Reply
(
m
.
network
.
client
.
NewMessage
(
"rpc"
,
pb
.
EventReply
,
&
pb
.
Reply
{
IsOk
:
false
,
Msg
:
[]
byte
(
err
.
Error
())}))
msg
.
Reply
(
m
.
network
.
client
.
NewMessage
(
"rpc"
,
pb
.
EventReply
,
&
pb
.
Reply
{
IsOk
:
false
,
Msg
:
[]
byte
(
err
.
Error
())}))
return
return
...
@@ -691,7 +691,7 @@ func (m *Cli) AddPeerToBlacklist(msg *queue.Message, taskindex int64) {
...
@@ -691,7 +691,7 @@ func (m *Cli) AddPeerToBlacklist(msg *queue.Message, taskindex int64) {
}
else
if
blackPeer
.
PeerName
!=
""
{
}
else
if
blackPeer
.
PeerName
!=
""
{
peer
:=
m
.
network
.
node
.
GetRegisterPeer
(
blackPeer
.
PeerName
)
peer
:=
m
.
network
.
node
.
GetRegisterPeer
(
blackPeer
.
PeerName
)
if
peer
!=
nil
{
if
peer
!=
nil
{
ip
,
_
,
_
:=
P2pComm
.
Check
NetAddr
(
peer
.
Addr
())
ip
,
_
,
_
:=
P2pComm
.
Parase
NetAddr
(
peer
.
Addr
())
m
.
network
.
node
.
nodeInfo
.
blacklist
.
Add
(
ip
,
int64
(
lifetime
.
Seconds
()))
m
.
network
.
node
.
nodeInfo
.
blacklist
.
Add
(
ip
,
int64
(
lifetime
.
Seconds
()))
m
.
network
.
node
.
nodeInfo
.
blacklist
.
Add
(
peer
.
Addr
(),
int64
(
lifetime
.
Seconds
()))
m
.
network
.
node
.
nodeInfo
.
blacklist
.
Add
(
peer
.
Addr
(),
int64
(
lifetime
.
Seconds
()))
...
@@ -719,7 +719,7 @@ func (m *Cli) DelPeerFromBlacklist(msg *queue.Message, taskindex int64) {
...
@@ -719,7 +719,7 @@ func (m *Cli) DelPeerFromBlacklist(msg *queue.Message, taskindex int64) {
blackPeer
:=
msg
.
GetData
()
.
(
*
pb
.
BlackPeer
)
blackPeer
:=
msg
.
GetData
()
.
(
*
pb
.
BlackPeer
)
if
blackPeer
.
PeerAddr
!=
""
{
if
blackPeer
.
PeerAddr
!=
""
{
//check peerAddr
//check peerAddr
ip
,
_
,
err
:=
P2pComm
.
Check
NetAddr
(
blackPeer
.
GetPeerAddr
())
ip
,
_
,
err
:=
P2pComm
.
Parase
NetAddr
(
blackPeer
.
GetPeerAddr
())
if
err
!=
nil
{
if
err
!=
nil
{
msg
.
Reply
(
m
.
network
.
client
.
NewMessage
(
"rpc"
,
pb
.
EventReply
,
&
pb
.
Reply
{
IsOk
:
false
,
Msg
:
[]
byte
(
err
.
Error
())}))
msg
.
Reply
(
m
.
network
.
client
.
NewMessage
(
"rpc"
,
pb
.
EventReply
,
&
pb
.
Reply
{
IsOk
:
false
,
Msg
:
[]
byte
(
err
.
Error
())}))
return
return
...
@@ -731,7 +731,7 @@ func (m *Cli) DelPeerFromBlacklist(msg *queue.Message, taskindex int64) {
...
@@ -731,7 +731,7 @@ func (m *Cli) DelPeerFromBlacklist(msg *queue.Message, taskindex int64) {
//通过pid 获取remoteAddr
//通过pid 获取remoteAddr
remoteAddr
,
ok
:=
m
.
network
.
node
.
nodeInfo
.
blacklist
.
getpeerStore
(
blackPeer
.
PeerName
)
remoteAddr
,
ok
:=
m
.
network
.
node
.
nodeInfo
.
blacklist
.
getpeerStore
(
blackPeer
.
PeerName
)
if
ok
{
if
ok
{
ip
,
_
,
_
:=
P2pComm
.
Check
NetAddr
(
remoteAddr
)
ip
,
_
,
_
:=
P2pComm
.
Parase
NetAddr
(
remoteAddr
)
m
.
network
.
node
.
nodeInfo
.
blacklist
.
Delete
(
ip
)
m
.
network
.
node
.
nodeInfo
.
blacklist
.
Delete
(
ip
)
m
.
network
.
node
.
nodeInfo
.
blacklist
.
Delete
(
remoteAddr
)
m
.
network
.
node
.
nodeInfo
.
blacklist
.
Delete
(
remoteAddr
)
m
.
network
.
node
.
nodeInfo
.
blacklist
.
deletePeerStore
(
remoteAddr
)
m
.
network
.
node
.
nodeInfo
.
blacklist
.
deletePeerStore
(
remoteAddr
)
...
...
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