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
c43db8a2
Commit
c43db8a2
authored
Oct 23, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1924 from fjl/eth-status-timeout
eth: time out status message exchange after 5s
parents
0aeab5fd
3cf74336
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
9 deletions
+27
-9
peer.go
eth/peer.go
+27
-9
No files found.
eth/peer.go
View file @
c43db8a2
...
...
@@ -21,6 +21,7 @@ import (
"fmt"
"math/big"
"sync"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
...
...
@@ -38,8 +39,9 @@ var (
)
const
(
maxKnownTxs
=
32768
// Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownBlocks
=
1024
// Maximum block hashes to keep in the known list (prevent DOS)
maxKnownTxs
=
32768
// Maximum transactions hashes to keep in the known list (prevent DOS)
maxKnownBlocks
=
1024
// Maximum block hashes to keep in the known list (prevent DOS)
handshakeTimeout
=
5
*
time
.
Second
)
type
peer
struct
{
...
...
@@ -267,8 +269,8 @@ func (p *peer) RequestReceipts(hashes []common.Hash) error {
// Handshake executes the eth protocol handshake, negotiating version number,
// network IDs, difficulties, head and genesis blocks.
func
(
p
*
peer
)
Handshake
(
td
*
big
.
Int
,
head
common
.
Hash
,
genesis
common
.
Hash
)
error
{
// Send out own handshake in a new thread
errc
:=
make
(
chan
error
,
1
)
errc
:=
make
(
chan
error
,
2
)
var
status
statusData
// safe to read after two values have been received from errc
go
func
()
{
errc
<-
p2p
.
Send
(
p
.
rw
,
StatusMsg
,
&
statusData
{
ProtocolVersion
:
uint32
(
p
.
version
),
...
...
@@ -278,7 +280,26 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, genesis common.Hash) err
GenesisBlock
:
genesis
,
})
}()
// In the mean time retrieve the remote status message
go
func
()
{
errc
<-
p
.
readStatus
(
&
status
,
genesis
)
}()
timeout
:=
time
.
NewTimer
(
handshakeTimeout
)
defer
timeout
.
Stop
()
for
i
:=
0
;
i
<
2
;
i
++
{
select
{
case
err
:=
<-
errc
:
if
err
!=
nil
{
return
err
}
case
<-
timeout
.
C
:
return
p2p
.
DiscReadTimeout
}
}
p
.
td
,
p
.
head
=
status
.
TD
,
status
.
CurrentBlock
return
nil
}
func
(
p
*
peer
)
readStatus
(
status
*
statusData
,
genesis
common
.
Hash
)
(
err
error
)
{
msg
,
err
:=
p
.
rw
.
ReadMsg
()
if
err
!=
nil
{
return
err
...
...
@@ -290,7 +311,6 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, genesis common.Hash) err
return
errResp
(
ErrMsgTooLarge
,
"%v > %v"
,
msg
.
Size
,
ProtocolMaxMsgSize
)
}
// Decode the handshake and make sure everything matches
var
status
statusData
if
err
:=
msg
.
Decode
(
&
status
);
err
!=
nil
{
return
errResp
(
ErrDecode
,
"msg %v: %v"
,
msg
,
err
)
}
...
...
@@ -303,9 +323,7 @@ func (p *peer) Handshake(td *big.Int, head common.Hash, genesis common.Hash) err
if
int
(
status
.
ProtocolVersion
)
!=
p
.
version
{
return
errResp
(
ErrProtocolVersionMismatch
,
"%d (!= %d)"
,
status
.
ProtocolVersion
,
p
.
version
)
}
// Configure the remote peer, and sanity check out handshake too
p
.
td
,
p
.
head
=
status
.
TD
,
status
.
CurrentBlock
return
<-
errc
return
nil
}
// String implements fmt.Stringer.
...
...
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