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-bitswap
Commits
cedc1c38
Commit
cedc1c38
authored
Sep 19, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refac(exch:offline) move offline exchange to its own package
parent
4ba46347
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
60 deletions
+0
-60
offline.go
offline.go
+0
-32
offline_test.go
offline_test.go
+0
-28
No files found.
offline.go
deleted
100644 → 0
View file @
4ba46347
package
bitswap
import
(
"errors"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
blocks
"github.com/jbenet/go-ipfs/blocks"
exchange
"github.com/jbenet/go-ipfs/exchange"
u
"github.com/jbenet/go-ipfs/util"
)
func
NewOfflineExchange
()
exchange
.
Interface
{
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
(
context
.
Context
,
u
.
Key
)
(
*
blocks
.
Block
,
error
)
{
return
nil
,
errors
.
New
(
"Block unavailable. Operating in offline mode"
)
}
// HasBlock always returns nil.
func
(
_
*
offlineExchange
)
HasBlock
(
context
.
Context
,
blocks
.
Block
)
error
{
return
nil
}
offline_test.go
deleted
100644 → 0
View file @
4ba46347
package
bitswap
import
(
"testing"
context
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
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
(
context
.
Background
(),
u
.
Key
(
"foo"
))
if
err
!=
nil
{
return
// as desired
}
t
.
Fail
()
}
func
TestHasBlockReturnsNil
(
t
*
testing
.
T
)
{
off
:=
NewOfflineExchange
()
block
:=
testutil
.
NewBlockOrFail
(
t
,
"data"
)
err
:=
off
.
HasBlock
(
context
.
Background
(),
block
)
if
err
!=
nil
{
t
.
Fatal
(
""
)
}
}
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