refac(exchange) rename exchange.Interface to match golang conventions
examples: http://golang.org/pkg/container/heap/#Interface http://golang.org/pkg/net/#Interface http://golang.org/pkg/sort/#Interface
Brian Tiger Chow committed
Sep 18, 2014 at 17:30 UTC
e1fe4f6d60620d14bb7f2f300c30204589ca3040
5 files changed
+21
-15
blockservice/blockservice.go
+2
-2
@@ -16,11 +16,11 @@ import (
16
// It uses an internal `datastore.Datastore` instance to store values.
17
type BlockService struct {
18
Datastore ds.Datastore
19
- Remote exchange.Exchange
19
+ Remote exchange.Interface
20
}
21
22
// NewBlockService creates a BlockService with given datastore instance.
23
-func NewBlockService(d ds.Datastore, rem exchange.Exchange) (*BlockService, error) {
23
+func NewBlockService(d ds.Datastore, rem exchange.Interface) (*BlockService, error) {
24
if d == nil {
25
return nil, fmt.Errorf("BlockService requires valid datastore")
26
}
core/core.go
+3
-3
@@ -48,7 +48,7 @@ type IpfsNode struct {
48
Routing routing.IpfsRouting
49
50
// the block exchange + strategy (bitswap)
51
- BitSwap exchange.Exchange
51
+ Exchange exchange.Interface
52
53
// the block service, get/add blocks.
54
Blocks *bserv.BlockService
@@ -89,7 +89,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
89
net inet.Network
90
// TODO: refactor so we can use IpfsRouting interface instead of being DHT-specific
91
route *dht.IpfsDHT
92
- exchangeSession exchange.Exchange
92
+ exchangeSession exchange.Interface
93
)
94
95
if online {
@@ -141,7 +141,7 @@ func NewIpfsNode(cfg *config.Config, online bool) (*IpfsNode, error) {
141
Blocks: bs,
142
DAG: dag,
143
Resolver: &path.Resolver{DAG: dag},
144
- BitSwap: exchangeSession,
144
+ Exchange: exchangeSession,
145
Identity: local,
146
Routing: route,
147
}, nil
exchange/bitswap/bitswap.go
+12
-2
@@ -18,6 +18,16 @@ import (
18
u "github.com/jbenet/go-ipfs/util"
19
)
20
21
+// TODO rename -> Router?
22
+type Routing interface {
23
+ // FindProvidersAsync returns a channel of providers for the given key
24
+ // TODO replace with timeout with context
25
+ FindProvidersAsync(u.Key, int, time.Duration) <-chan *peer.Peer
26
+
27
+ // Provide provides the key to the network
28
+ Provide(key u.Key) error
29
+}
30
+
31
// TODO(brian): ensure messages are being received
32
33
// PartnerWantListMax is the bound for the number of keys we'll store per
@@ -38,7 +48,7 @@ type bitswap struct {
48
blockstore blockstore.Blockstore
49
50
// routing interface for communication
41
- routing exchange.Directory
51
+ routing Routing
52
53
notifications notifications.PubSub
54
@@ -49,7 +59,7 @@ type bitswap struct {
59
}
60
61
// NewSession initializes a bitswap session.
52
-func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory exchange.Directory) exchange.Exchange {
62
+func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory Routing) exchange.Interface {
63
64
// FIXME(brian): instantiate a concrete Strategist
65
receiver := bsnet.Forwarder{}
exchange/bitswap/offline.go
+1
-1
@@ -9,7 +9,7 @@ import (
9
u "github.com/jbenet/go-ipfs/util"
10
)
11
12
-func NewOfflineExchange() exchange.Exchange {
12
+func NewOfflineExchange() exchange.Interface {
13
return &offlineExchange{}
14
}
15
exchange/interface.go
+3
-7
@@ -4,11 +4,12 @@ import (
4
"time"
5
6
blocks "github.com/jbenet/go-ipfs/blocks"
7
- peer "github.com/jbenet/go-ipfs/peer"
7
u "github.com/jbenet/go-ipfs/util"
8
)
9
11
-type Exchange interface {
10
+// Any type that implements exchange.Interface may be used as an IPFS block
11
+// exchange protocol.
12
+type Interface interface {
13
14
// Block returns the block associated with a given key.
15
// TODO(brian): pass a context instead of a timeout
@@ -21,8 +22,3 @@ type Exchange interface {
22
// whether the block was made available on the network?
23
HasBlock(blocks.Block) error
24
}
24
-
25
-type Directory interface {
26
- FindProvidersAsync(u.Key, int, time.Duration) <-chan *peer.Peer
27
- Provide(key u.Key) error
28
-}