style(ex:bitswap) put public methods at top
Brian Tiger Chow committed
Sep 18, 2014 at 18:44 UTC
335b50f4c65819f4a3ae6c01614bfe3e905a3fbe
1 file changed
+27
-27
exchange/bitswap/bitswap.go
+27
-27
@@ -35,6 +35,24 @@ type Routing interface {
35
// advertisements. WantLists are sorted in terms of priority.
36
const PartnerWantListMax = 10
37
38
+// NewSession initializes a bitswap session.
39
+func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory Routing) exchange.Interface {
40
+
41
+ // FIXME(brian): instantiate a concrete Strategist
42
+ receiver := bsnet.Forwarder{}
43
+ bs := &bitswap{
44
+ blockstore: blockstore.NewBlockstore(d),
45
+ notifications: notifications.New(),
46
+ strategy: strategy.New(),
47
+ peer: p,
48
+ routing: directory,
49
+ sender: bsnet.NewNetworkAdapter(s, &receiver),
50
+ }
51
+ receiver.Delegate(bs)
52
+
53
+ return bs
54
+}
55
+
56
// bitswap instances implement the bitswap protocol.
57
type bitswap struct {
58
// peer is the identity of this (local) node.
@@ -58,24 +76,6 @@ type bitswap struct {
76
strategy strategy.Strategy
77
}
78
61
-// NewSession initializes a bitswap session.
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{}
66
- bs := &bitswap{
67
- blockstore: blockstore.NewBlockstore(d),
68
- notifications: notifications.New(),
69
- strategy: strategy.New(),
70
- peer: p,
71
- routing: directory,
72
- sender: bsnet.NewNetworkAdapter(s, &receiver),
73
- }
74
- receiver.Delegate(bs)
75
-
76
- return bs
77
-}
78
-
79
// GetBlock attempts to retrieve a particular block from peers, within timeout.
80
func (bs *bitswap) Block(k u.Key, timeout time.Duration) (
81
*blocks.Block, error) {
@@ -149,15 +149,6 @@ func (bs *bitswap) HasBlock(blk blocks.Block) error {
149
return bs.routing.Provide(blk.Key())
150
}
151
152
-// TODO(brian): get a return value
153
-func (bs *bitswap) send(p *peer.Peer, b blocks.Block) {
154
- message := bsmsg.New()
155
- message.AppendBlock(b)
156
- // FIXME(brian): pass ctx
157
- bs.sender.SendMessage(context.Background(), p, message)
158
- bs.strategy.MessageSent(p, message)
159
-}
160
-
152
// TODO(brian): handle errors
153
func (bs *bitswap) ReceiveMessage(
154
ctx context.Context, sender *peer.Peer, incoming bsmsg.BitSwapMessage) (
@@ -187,6 +178,15 @@ func (bs *bitswap) ReceiveMessage(
178
return nil, nil, errors.New("TODO implement")
179
}
180
181
+// TODO(brian): get a return value
182
+func (bs *bitswap) send(p *peer.Peer, b blocks.Block) {
183
+ message := bsmsg.New()
184
+ message.AppendBlock(b)
185
+ // FIXME(brian): pass ctx
186
+ bs.sender.SendMessage(context.Background(), p, message)
187
+ bs.strategy.MessageSent(p, message)
188
+}
189
+
190
func numBytes(b blocks.Block) int {
191
return len(b.Data)
192
}