Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-blockservice
Commits
39f3c34e
Commit
39f3c34e
authored
Apr 01, 2021
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: handle missing session exchange in Session
Otherwise, we'll panic.
parent
622c072d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
2 deletions
+38
-2
blockservice.go
blockservice.go
+10
-2
blockservice_test.go
blockservice_test.go
+28
-0
No files found.
blockservice.go
View file @
39f3c34e
...
...
@@ -366,12 +366,20 @@ func (s *Session) getSession() exchange.Fetcher {
// GetBlock gets a block in the context of a request session
func
(
s
*
Session
)
GetBlock
(
ctx
context
.
Context
,
c
cid
.
Cid
)
(
blocks
.
Block
,
error
)
{
return
getBlock
(
ctx
,
c
,
s
.
bs
,
s
.
getSession
)
// hash security
var
f
func
()
exchange
.
Fetcher
if
s
.
sessEx
!=
nil
{
f
=
s
.
getSession
}
return
getBlock
(
ctx
,
c
,
s
.
bs
,
f
)
// hash security
}
// GetBlocks gets blocks in the context of a request session
func
(
s
*
Session
)
GetBlocks
(
ctx
context
.
Context
,
ks
[]
cid
.
Cid
)
<-
chan
blocks
.
Block
{
return
getBlocks
(
ctx
,
ks
,
s
.
bs
,
s
.
getSession
)
// hash security
var
f
func
()
exchange
.
Fetcher
if
s
.
sessEx
!=
nil
{
f
=
s
.
getSession
}
return
getBlocks
(
ctx
,
ks
,
s
.
bs
,
f
)
// hash security
}
var
_
BlockGetter
=
(
*
Session
)(
nil
)
blockservice_test.go
View file @
39f3c34e
...
...
@@ -119,3 +119,31 @@ func (fe *fakeSessionExchange) NewSession(ctx context.Context) exchange.Fetcher
}
return
fe
.
session
}
func
TestNilExchange
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
ctx
,
cancel
:=
context
.
WithCancel
(
ctx
)
defer
cancel
()
bgen
:=
butil
.
NewBlockGenerator
()
block
:=
bgen
.
Next
()
bs
:=
blockstore
.
NewBlockstore
(
dssync
.
MutexWrap
(
ds
.
NewMapDatastore
()))
bserv
:=
NewWriteThrough
(
bs
,
nil
)
sess
:=
NewSession
(
ctx
,
bserv
)
_
,
err
:=
sess
.
GetBlock
(
ctx
,
block
.
Cid
())
if
err
!=
ErrNotFound
{
t
.
Fatal
(
"expected block to not be found"
)
}
err
=
bs
.
Put
(
block
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
b
,
err
:=
sess
.
GetBlock
(
ctx
,
block
.
Cid
())
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
b
.
Cid
()
!=
block
.
Cid
()
{
t
.
Fatal
(
"got the wrong block"
)
}
}
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