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
c8130df1
Commit
c8130df1
authored
Dec 06, 2016
by
Zsolt Felfoldi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
les: using random request IDs
parent
af8a742d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
11 deletions
+10
-11
fetcher.go
les/fetcher.go
+1
-1
handler.go
les/handler.go
+2
-2
odr.go
les/odr.go
+7
-8
No files found.
les/fetcher.go
View file @
c8130df1
...
...
@@ -350,7 +350,7 @@ func (f *lightFetcher) request(p *peer, n *fetcherTreeNode, amount uint64) (uint
return
0
,
false
}
reqID
:=
f
.
odr
.
getNextReqID
()
reqID
:=
getNextReqID
()
n
.
requested
=
true
cost
:=
p
.
GetRequestCost
(
GetBlockHeadersMsg
,
int
(
amount
))
p
.
fcServer
.
SendRequest
(
reqID
,
cost
)
...
...
les/handler.go
View file @
c8130df1
...
...
@@ -338,13 +338,13 @@ func (pm *ProtocolManager) handle(p *peer) error {
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"LES: register peer %v"
,
p
.
id
)
if
pm
.
lightSync
{
requestHeadersByHash
:=
func
(
origin
common
.
Hash
,
amount
int
,
skip
int
,
reverse
bool
)
error
{
reqID
:=
pm
.
odr
.
getNextReqID
()
reqID
:=
getNextReqID
()
cost
:=
p
.
GetRequestCost
(
GetBlockHeadersMsg
,
amount
)
p
.
fcServer
.
SendRequest
(
reqID
,
cost
)
return
p
.
RequestHeadersByHash
(
reqID
,
cost
,
origin
,
amount
,
skip
,
reverse
)
}
requestHeadersByNumber
:=
func
(
origin
uint64
,
amount
int
,
skip
int
,
reverse
bool
)
error
{
reqID
:=
pm
.
odr
.
getNextReqID
()
reqID
:=
getNextReqID
()
cost
:=
p
.
GetRequestCost
(
GetBlockHeadersMsg
,
amount
)
p
.
fcServer
.
SendRequest
(
reqID
,
cost
)
return
p
.
RequestHeadersByNumber
(
reqID
,
cost
,
origin
,
amount
,
skip
,
reverse
)
...
...
les/odr.go
View file @
c8130df1
...
...
@@ -17,6 +17,8 @@
package
les
import
(
"crypto/rand"
"encoding/binary"
"sync"
"time"
...
...
@@ -50,7 +52,6 @@ type LesOdr struct {
mlock
,
clock
sync
.
Mutex
sentReqs
map
[
uint64
]
*
sentReq
serverPool
odrPeerSelector
lastReqID
uint64
}
func
NewLesOdr
(
db
ethdb
.
Database
)
*
LesOdr
{
...
...
@@ -167,7 +168,7 @@ func (self *LesOdr) networkRequest(ctx context.Context, lreq LesOdrRequest) erro
sentTo
:
make
(
map
[
*
peer
]
chan
struct
{}),
answered
:
answered
,
// reply delivered by any peer
}
reqID
:=
self
.
getNextReqID
()
reqID
:=
getNextReqID
()
self
.
mlock
.
Lock
()
self
.
sentReqs
[
reqID
]
=
req
self
.
mlock
.
Unlock
()
...
...
@@ -236,10 +237,8 @@ func (self *LesOdr) Retrieve(ctx context.Context, req light.OdrRequest) (err err
return
}
func
(
self
*
LesOdr
)
getNextReqID
()
uint64
{
self
.
clock
.
Lock
()
defer
self
.
clock
.
Unlock
()
self
.
lastReqID
++
return
self
.
lastReqID
func
getNextReqID
()
uint64
{
var
rnd
[
8
]
byte
rand
.
Read
(
rnd
[
:
])
return
binary
.
BigEndian
.
Uint64
(
rnd
[
:
])
}
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