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
f5348e17
Commit
f5348e17
authored
Jan 23, 2017
by
Zsolt Felfoldi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
les: add unknown peers to server pool instead of rejecting them
parent
1886d03f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
38 deletions
+45
-38
handler.go
les/handler.go
+0
-3
serverpool.go
les/serverpool.go
+45
-35
No files found.
les/handler.go
View file @
f5348e17
...
...
@@ -160,9 +160,6 @@ func NewProtocolManager(chainConfig *params.ChainConfig, lightSync bool, network
if
manager
.
serverPool
!=
nil
{
addr
:=
p
.
RemoteAddr
()
.
(
*
net
.
TCPAddr
)
entry
=
manager
.
serverPool
.
connect
(
peer
,
addr
.
IP
,
uint16
(
addr
.
Port
))
if
entry
==
nil
{
return
fmt
.
Errorf
(
"unwanted connection"
)
}
}
peer
.
poolEntry
=
entry
select
{
...
...
les/serverpool.go
View file @
f5348e17
...
...
@@ -160,10 +160,10 @@ func (pool *serverPool) connect(p *peer, ip net.IP, port uint16) *poolEntry {
defer
pool
.
lock
.
Unlock
()
entry
:=
pool
.
entries
[
p
.
ID
()]
if
entry
==
nil
{
return
nil
entry
=
pool
.
findOrNewNode
(
p
.
ID
(),
ip
,
port
)
}
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"connecting to %v, state: %v"
,
p
.
id
,
entry
.
state
)
if
entry
.
state
!=
psDial
ed
{
if
entry
.
state
==
psConnected
||
entry
.
state
==
psRegister
ed
{
return
nil
}
pool
.
connWg
.
Add
(
1
)
...
...
@@ -250,11 +250,17 @@ type poolStatAdjust struct {
// adjustBlockDelay adjusts the block announce delay statistics of a node
func
(
pool
*
serverPool
)
adjustBlockDelay
(
entry
*
poolEntry
,
time
time
.
Duration
)
{
if
entry
==
nil
{
return
}
pool
.
adjustStats
<-
poolStatAdjust
{
pseBlockDelay
,
entry
,
time
}
}
// adjustResponseTime adjusts the request response time statistics of a node
func
(
pool
*
serverPool
)
adjustResponseTime
(
entry
*
poolEntry
,
time
time
.
Duration
,
timeout
bool
)
{
if
entry
==
nil
{
return
}
if
timeout
{
pool
.
adjustStats
<-
poolStatAdjust
{
pseResponseTimeout
,
entry
,
time
}
}
else
{
...
...
@@ -375,11 +381,38 @@ func (pool *serverPool) eventLoop() {
case
node
:=
<-
pool
.
discNodes
:
pool
.
lock
.
Lock
()
entry
:=
pool
.
findOrNewNode
(
discover
.
NodeID
(
node
.
ID
),
node
.
IP
,
node
.
TCP
)
pool
.
updateCheckDial
(
entry
)
pool
.
lock
.
Unlock
()
case
conv
:=
<-
pool
.
discLookups
:
if
conv
{
if
lookupCnt
==
0
{
convTime
=
mclock
.
Now
()
}
lookupCnt
++
if
pool
.
fastDiscover
&&
(
lookupCnt
==
50
||
time
.
Duration
(
mclock
.
Now
()
-
convTime
)
>
time
.
Minute
)
{
pool
.
fastDiscover
=
false
pool
.
discSetPeriod
<-
time
.
Minute
}
}
case
<-
pool
.
quit
:
close
(
pool
.
discSetPeriod
)
pool
.
connWg
.
Wait
()
pool
.
saveNodes
()
pool
.
wg
.
Done
()
return
}
}
}
func
(
pool
*
serverPool
)
findOrNewNode
(
id
discover
.
NodeID
,
ip
net
.
IP
,
port
uint16
)
*
poolEntry
{
now
:=
mclock
.
Now
()
id
:=
discover
.
NodeID
(
node
.
ID
)
entry
:=
pool
.
entries
[
id
]
if
entry
==
nil
{
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"discovered %v"
,
node
.
String
())
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"discovered %v"
,
id
.
String
())
entry
=
&
poolEntry
{
id
:
id
,
addr
:
make
(
map
[
string
]
*
poolEntryAddress
),
...
...
@@ -395,8 +428,8 @@ func (pool *serverPool) eventLoop() {
}
entry
.
lastDiscovered
=
now
addr
:=
&
poolEntryAddress
{
ip
:
node
.
IP
,
port
:
node
.
TCP
,
ip
:
ip
,
port
:
port
,
}
if
a
,
ok
:=
entry
.
addr
[
addr
.
strKey
()];
ok
{
addr
=
a
...
...
@@ -408,30 +441,7 @@ func (pool *serverPool) eventLoop() {
if
!
entry
.
known
{
pool
.
newQueue
.
setLatest
(
entry
)
}
pool
.
updateCheckDial
(
entry
)
pool
.
lock
.
Unlock
()
case
conv
:=
<-
pool
.
discLookups
:
if
conv
{
if
lookupCnt
==
0
{
convTime
=
mclock
.
Now
()
}
lookupCnt
++
if
pool
.
fastDiscover
&&
(
lookupCnt
==
50
||
time
.
Duration
(
mclock
.
Now
()
-
convTime
)
>
time
.
Minute
)
{
pool
.
fastDiscover
=
false
pool
.
discSetPeriod
<-
time
.
Minute
}
}
case
<-
pool
.
quit
:
close
(
pool
.
discSetPeriod
)
pool
.
connWg
.
Wait
()
pool
.
saveNodes
()
pool
.
wg
.
Done
()
return
}
}
return
entry
}
// loadNodes loads known nodes and their statistics from the database
...
...
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