offline.go 885 Bytes
Newer Older
1 2 3 4
package bitswap

import (
	"errors"
5 6

	context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
7 8 9 10 11 12

	blocks "github.com/jbenet/go-ipfs/blocks"
	exchange "github.com/jbenet/go-ipfs/exchange"
	u "github.com/jbenet/go-ipfs/util"
)

13
func NewOfflineExchange() exchange.Interface {
14 15 16 17 18 19 20 21 22 23 24
	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.
25
func (_ *offlineExchange) Block(context.Context, u.Key) (*blocks.Block, error) {
26 27 28 29 30 31 32
	return nil, errors.New("Block unavailable. Operating in offline mode")
}

// HasBlock always returns nil.
func (_ *offlineExchange) HasBlock(blocks.Block) error {
	return nil
}