github.com/zignig/go-ipfs@v0.0.0-20141111235910-c9e5fdf55a52/exchange/offline/offline.go (about)

     1  // package offline implements an object that implements the exchange
     2  // interface but returns nil values to every request.
     3  package offline
     4  
     5  import (
     6  	"errors"
     7  
     8  	context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
     9  
    10  	blocks "github.com/jbenet/go-ipfs/blocks"
    11  	exchange "github.com/jbenet/go-ipfs/exchange"
    12  	u "github.com/jbenet/go-ipfs/util"
    13  )
    14  
    15  var OfflineMode = errors.New("Block unavailable. Operating in offline mode")
    16  
    17  func NewOfflineExchange() exchange.Interface {
    18  	return &offlineExchange{}
    19  }
    20  
    21  // offlineExchange implements the Exchange interface but doesn't return blocks.
    22  // For use in offline mode.
    23  type offlineExchange struct {
    24  }
    25  
    26  // Block returns nil to signal that a block could not be retrieved for the
    27  // given key.
    28  // NB: This function may return before the timeout expires.
    29  func (_ *offlineExchange) Block(context.Context, u.Key) (*blocks.Block, error) {
    30  	return nil, OfflineMode
    31  }
    32  
    33  // HasBlock always returns nil.
    34  func (_ *offlineExchange) HasBlock(context.Context, blocks.Block) error {
    35  	return nil
    36  }