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-unixfs
Commits
770cdebf
Commit
770cdebf
authored
10 years ago
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(bitswap) impl offline exchange
parent
adf62a39
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
+57
-0
bitswap/offline.go
bitswap/offline.go
+30
-0
bitswap/offline_test.go
bitswap/offline_test.go
+27
-0
No files found.
bitswap/offline.go
0 → 100644
View file @
770cdebf
package
bitswap
import
(
"errors"
"time"
blocks
"github.com/jbenet/go-ipfs/blocks"
u
"github.com/jbenet/go-ipfs/util"
)
func
NewOfflineExchange
()
Exchange
{
return
&
offlineExchange
{}
}
// offlineExchange implements the Exchange interface but doesn't return blocks.
// For use in offline mode.
type
offlineExchange
struct
{
}
// Block returns nil to signal that a block could not be retrieved for the
// given key.
// NB: This function may return before the timeout expires.
func
(
_
*
offlineExchange
)
Block
(
k
u
.
Key
,
timeout
time
.
Duration
)
(
*
blocks
.
Block
,
error
)
{
return
nil
,
errors
.
New
(
"Block unavailable. Operating in offline mode"
)
}
// HasBlock always returns nil.
func
(
_
*
offlineExchange
)
HasBlock
(
*
blocks
.
Block
)
error
{
return
nil
}
This diff is collapsed.
Click to expand it.
bitswap/offline_test.go
0 → 100644
View file @
770cdebf
package
bitswap
import
(
"testing"
"time"
u
"github.com/jbenet/go-ipfs/util"
testutil
"github.com/jbenet/go-ipfs/util/testutil"
)
func
TestBlockReturnsErr
(
t
*
testing
.
T
)
{
off
:=
NewOfflineExchange
()
_
,
err
:=
off
.
Block
(
u
.
Key
(
"foo"
),
time
.
Second
)
if
err
!=
nil
{
return
// as desired
}
t
.
Fail
()
}
func
TestHasBlockReturnsNil
(
t
*
testing
.
T
)
{
off
:=
NewOfflineExchange
()
block
:=
testutil
.
NewBlockOrFail
(
t
,
"data"
)
err
:=
off
.
HasBlock
(
&
block
)
if
err
!=
nil
{
t
.
Fatal
(
""
)
}
}
This diff is collapsed.
Click to expand it.
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