Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
7de1c505
Commit
7de1c505
authored
Sep 18, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style(ex:bitswap) put public methods at top
parent
d2ea3d25
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
27 deletions
+27
-27
bitswap.go
bitswap.go
+27
-27
No files found.
bitswap.go
View file @
7de1c505
...
...
@@ -35,6 +35,24 @@ type Routing interface {
// advertisements. WantLists are sorted in terms of priority.
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.
type
bitswap
struct
{
// peer is the identity of this (local) node.
...
...
@@ -58,24 +76,6 @@ type bitswap struct {
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.
func
(
bs
*
bitswap
)
Block
(
k
u
.
Key
,
timeout
time
.
Duration
)
(
*
blocks
.
Block
,
error
)
{
...
...
@@ -149,15 +149,6 @@ func (bs *bitswap) HasBlock(blk blocks.Block) error {
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
func
(
bs
*
bitswap
)
ReceiveMessage
(
ctx
context
.
Context
,
sender
*
peer
.
Peer
,
incoming
bsmsg
.
BitSwapMessage
)
(
...
...
@@ -187,6 +178,15 @@ func (bs *bitswap) ReceiveMessage(
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
{
return
len
(
b
.
Data
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment