Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
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
张蕾
Geth-Modification
Commits
d4f0a673
Commit
d4f0a673
authored
May 08, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
p2p: drop connections with no matching protocols
parent
e45d9bb2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
4 deletions
+21
-4
peer.go
p2p/peer.go
+12
-0
server.go
p2p/server.go
+9
-4
No files found.
p2p/peer.go
View file @
d4f0a673
...
...
@@ -211,6 +211,18 @@ func (p *Peer) handle(msg Msg) error {
return
nil
}
func
countMatchingProtocols
(
protocols
[]
Protocol
,
caps
[]
Cap
)
int
{
n
:=
0
for
_
,
cap
:=
range
caps
{
for
_
,
proto
:=
range
protocols
{
if
proto
.
Name
==
cap
.
Name
&&
proto
.
Version
==
cap
.
Version
{
n
++
}
}
}
return
n
}
// matchProtocols creates structures for matching named subprotocols.
func
matchProtocols
(
protocols
[]
Protocol
,
caps
[]
Cap
,
rw
MsgReadWriter
)
map
[
string
]
*
protoRW
{
sort
.
Sort
(
capsByName
(
caps
))
...
...
p2p/server.go
View file @
d4f0a673
...
...
@@ -518,7 +518,7 @@ func (srv *Server) startPeer(fd net.Conn, dest *discover.Node) {
conn
:
fd
,
rtimeout
:
frameReadTimeout
,
wtimeout
:
frameWriteTimeout
,
}
p
:=
newPeer
(
fd
,
conn
,
srv
.
Protocols
)
if
ok
,
reason
:=
srv
.
addPeer
(
conn
.
ID
,
p
);
!
ok
{
if
ok
,
reason
:=
srv
.
addPeer
(
conn
,
p
);
!
ok
{
glog
.
V
(
logger
.
Detail
)
.
Infof
(
"Not adding %v (%v)
\n
"
,
p
,
reason
)
p
.
politeDisconnect
(
reason
)
srv
.
peerWG
.
Done
()
...
...
@@ -564,13 +564,18 @@ func (srv *Server) runPeer(p *Peer) {
})
}
func
(
srv
*
Server
)
addPeer
(
id
discover
.
NodeID
,
p
*
Peer
)
(
bool
,
DiscReason
)
{
func
(
srv
*
Server
)
addPeer
(
conn
*
conn
,
p
*
Peer
)
(
bool
,
DiscReason
)
{
// drop connections with no matching protocols.
if
len
(
srv
.
Protocols
)
>
0
&&
countMatchingProtocols
(
srv
.
Protocols
,
conn
.
protoHandshake
.
Caps
)
==
0
{
return
false
,
DiscUselessPeer
}
// add the peer if it passes the other checks.
srv
.
lock
.
Lock
()
defer
srv
.
lock
.
Unlock
()
if
ok
,
reason
:=
srv
.
checkPeer
(
id
);
!
ok
{
if
ok
,
reason
:=
srv
.
checkPeer
(
conn
.
ID
);
!
ok
{
return
false
,
reason
}
srv
.
peers
[
id
]
=
p
srv
.
peers
[
conn
.
ID
]
=
p
return
true
,
0
}
...
...
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