Commit 7de1c505 authored by Brian Tiger Chow's avatar Brian Tiger Chow

style(ex:bitswap) put public methods at top

parent d2ea3d25
...@@ -35,6 +35,24 @@ type Routing interface { ...@@ -35,6 +35,24 @@ type Routing interface {
// advertisements. WantLists are sorted in terms of priority. // advertisements. WantLists are sorted in terms of priority.
const PartnerWantListMax = 10 const PartnerWantListMax = 10
// NewSession initializes a bitswap session.
func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory Routing) exchange.Interface {
// FIXME(brian): instantiate a concrete Strategist
receiver := bsnet.Forwarder{}
bs := &bitswap{
blockstore: blockstore.NewBlockstore(d),
notifications: notifications.New(),
strategy: strategy.New(),
peer: p,
routing: directory,
sender: bsnet.NewNetworkAdapter(s, &receiver),
}
receiver.Delegate(bs)
return bs
}
// bitswap instances implement the bitswap protocol. // bitswap instances implement the bitswap protocol.
type bitswap struct { type bitswap struct {
// peer is the identity of this (local) node. // peer is the identity of this (local) node.
...@@ -58,24 +76,6 @@ type bitswap struct { ...@@ -58,24 +76,6 @@ type bitswap struct {
strategy strategy.Strategy strategy strategy.Strategy
} }
// NewSession initializes a bitswap session.
func NewSession(parent context.Context, s bsnet.NetworkService, p *peer.Peer, d ds.Datastore, directory Routing) exchange.Interface {
// FIXME(brian): instantiate a concrete Strategist
receiver := bsnet.Forwarder{}
bs := &bitswap{
blockstore: blockstore.NewBlockstore(d),
notifications: notifications.New(),
strategy: strategy.New(),
peer: p,
routing: directory,
sender: bsnet.NewNetworkAdapter(s, &receiver),
}
receiver.Delegate(bs)
return bs
}
// GetBlock attempts to retrieve a particular block from peers, within timeout. // GetBlock attempts to retrieve a particular block from peers, within timeout.
func (bs *bitswap) Block(k u.Key, timeout time.Duration) ( func (bs *bitswap) Block(k u.Key, timeout time.Duration) (
*blocks.Block, error) { *blocks.Block, error) {
...@@ -149,15 +149,6 @@ func (bs *bitswap) HasBlock(blk blocks.Block) error { ...@@ -149,15 +149,6 @@ func (bs *bitswap) HasBlock(blk blocks.Block) error {
return bs.routing.Provide(blk.Key()) return bs.routing.Provide(blk.Key())
} }
// TODO(brian): get a return value
func (bs *bitswap) send(p *peer.Peer, b blocks.Block) {
message := bsmsg.New()
message.AppendBlock(b)
// FIXME(brian): pass ctx
bs.sender.SendMessage(context.Background(), p, message)
bs.strategy.MessageSent(p, message)
}
// TODO(brian): handle errors // TODO(brian): handle errors
func (bs *bitswap) ReceiveMessage( func (bs *bitswap) ReceiveMessage(
ctx context.Context, sender *peer.Peer, incoming bsmsg.BitSwapMessage) ( ctx context.Context, sender *peer.Peer, incoming bsmsg.BitSwapMessage) (
...@@ -187,6 +178,15 @@ func (bs *bitswap) ReceiveMessage( ...@@ -187,6 +178,15 @@ func (bs *bitswap) ReceiveMessage(
return nil, nil, errors.New("TODO implement") return nil, nil, errors.New("TODO implement")
} }
// TODO(brian): get a return value
func (bs *bitswap) send(p *peer.Peer, b blocks.Block) {
message := bsmsg.New()
message.AppendBlock(b)
// FIXME(brian): pass ctx
bs.sender.SendMessage(context.Background(), p, message)
bs.strategy.MessageSent(p, message)
}
func numBytes(b blocks.Block) int { func numBytes(b blocks.Block) int {
return len(b.Data) return len(b.Data)
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment