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
540558d2
Commit
540558d2
authored
Sep 01, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
integrate CIDv0
License: MIT Signed-off-by:
Jeromy
<
why@ipfs.io
>
parent
03f53fc9
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
21 additions
and
18 deletions
+21
-18
bitswap.go
bitswap.go
+9
-9
bitswap_test.go
bitswap_test.go
+5
-2
decision/engine.go
decision/engine.go
+3
-3
decision/engine_test.go
decision/engine_test.go
+1
-1
message/message.go
message/message.go
+1
-1
notifications/notifications_test.go
notifications/notifications_test.go
+1
-1
testnet/network_test.go
testnet/network_test.go
+1
-1
No files found.
bitswap.go
View file @
540558d2
...
...
@@ -8,12 +8,6 @@ import (
"sync"
"time"
process
"gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess"
procctx
"gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
peer
"gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer"
context
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
blocks
"github.com/ipfs/go-ipfs/blocks"
blockstore
"github.com/ipfs/go-ipfs/blocks/blockstore"
key
"github.com/ipfs/go-ipfs/blocks/key"
...
...
@@ -26,6 +20,12 @@ import (
flags
"github.com/ipfs/go-ipfs/flags"
"github.com/ipfs/go-ipfs/thirdparty/delay"
loggables
"github.com/ipfs/go-ipfs/thirdparty/loggables"
process
"gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess"
procctx
"gx/ipfs/QmQopLATEYMNg7dVqZRNDfeE2S1yKy8zrRh5xnYiuqeZBn/goprocess/context"
logging
"gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
peer
"gx/ipfs/QmWtbQU15LaB5B1JC2F7TV9P4K88vD3PpA4AJrwfCjhML8/go-libp2p-peer"
context
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
)
var
log
=
logging
.
Logger
(
"bitswap"
)
...
...
@@ -252,8 +252,8 @@ func (bs *Bitswap) GetBlocks(ctx context.Context, keys []key.Key) (<-chan blocks
}
// CancelWant removes a given key from the wantlist
func
(
bs
*
Bitswap
)
CancelWants
(
ks
[]
key
.
Key
)
{
bs
.
wm
.
CancelWants
(
ks
)
func
(
bs
*
Bitswap
)
CancelWants
(
k
ey
s
[]
key
.
Key
)
{
bs
.
wm
.
CancelWants
(
k
ey
s
)
}
// HasBlock announces the existance of a block to this bitswap service. The
...
...
@@ -343,7 +343,7 @@ func (bs *Bitswap) updateReceiveCounters(b blocks.Block) error {
}
if
err
==
nil
&&
has
{
bs
.
dupBlocksRecvd
++
bs
.
dupDataRecvd
+=
uint64
(
len
(
b
.
Data
()))
bs
.
dupDataRecvd
+=
uint64
(
len
(
b
.
Raw
Data
()))
}
if
has
{
...
...
bitswap_test.go
View file @
540558d2
...
...
@@ -90,7 +90,7 @@ func TestGetBlockFromPeerAfterPeerAnnounces(t *testing.T) {
t
.
Fatal
(
"Expected to succeed"
)
}
if
!
bytes
.
Equal
(
block
.
Data
(),
received
.
Data
())
{
if
!
bytes
.
Equal
(
block
.
Raw
Data
(),
received
.
Raw
Data
())
{
t
.
Fatal
(
"Data doesn't match"
)
}
}
...
...
@@ -289,7 +289,10 @@ func TestEmptyKey(t *testing.T) {
defer
sg
.
Close
()
bs
:=
sg
.
Instances
(
1
)[
0
]
.
Exchange
_
,
err
:=
bs
.
GetBlock
(
context
.
Background
(),
key
.
Key
(
""
))
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
5
)
defer
cancel
()
_
,
err
:=
bs
.
GetBlock
(
ctx
,
key
.
Key
(
""
))
if
err
!=
blockstore
.
ErrNotFound
{
t
.
Error
(
"empty str key should return ErrNotFound"
)
}
...
...
decision/engine.go
View file @
540558d2
...
...
@@ -247,8 +247,8 @@ func (e *Engine) MessageReceived(p peer.ID, m bsmsg.BitSwapMessage) error {
}
for
_
,
block
:=
range
m
.
Blocks
()
{
log
.
Debugf
(
"got block %s %d bytes"
,
block
.
Key
()
,
len
(
block
.
Data
()))
l
.
ReceivedBytes
(
len
(
block
.
Data
()))
log
.
Debugf
(
"got block %s %d bytes"
,
block
,
len
(
block
.
Raw
Data
()))
l
.
ReceivedBytes
(
len
(
block
.
Raw
Data
()))
}
return
nil
}
...
...
@@ -286,7 +286,7 @@ func (e *Engine) AddBlock(block blocks.Block) {
func
(
e
*
Engine
)
MessageSent
(
p
peer
.
ID
,
m
bsmsg
.
BitSwapMessage
)
error
{
l
:=
e
.
findOrCreate
(
p
)
for
_
,
block
:=
range
m
.
Blocks
()
{
l
.
SentBytes
(
len
(
block
.
Data
()))
l
.
SentBytes
(
len
(
block
.
Raw
Data
()))
l
.
wantList
.
Remove
(
block
.
Key
())
e
.
peerRequestQueue
.
Remove
(
block
.
Key
(),
p
)
}
...
...
decision/engine_test.go
View file @
540558d2
...
...
@@ -188,7 +188,7 @@ func checkHandledInOrder(t *testing.T, e *Engine, keys []string) error {
received
:=
envelope
.
Block
expected
:=
blocks
.
NewBlock
([]
byte
(
k
))
if
received
.
Key
()
!=
expected
.
Key
()
{
return
errors
.
New
(
fmt
.
Sprintln
(
"received"
,
string
(
received
.
Data
()),
"expected"
,
string
(
expected
.
Data
())))
return
errors
.
New
(
fmt
.
Sprintln
(
"received"
,
string
(
received
.
Raw
Data
()),
"expected"
,
string
(
expected
.
Raw
Data
())))
}
}
return
nil
...
...
message/message.go
View file @
540558d2
...
...
@@ -159,7 +159,7 @@ func (m *impl) ToProto() *pb.Message {
})
}
for
_
,
b
:=
range
m
.
Blocks
()
{
pbm
.
Blocks
=
append
(
pbm
.
Blocks
,
b
.
Data
())
pbm
.
Blocks
=
append
(
pbm
.
Blocks
,
b
.
Raw
Data
())
}
return
pbm
}
...
...
notifications/notifications_test.go
View file @
540558d2
...
...
@@ -159,7 +159,7 @@ func assertBlockChannelNil(t *testing.T, blockChannel <-chan blocks.Block) {
}
func
assertBlocksEqual
(
t
*
testing
.
T
,
a
,
b
blocks
.
Block
)
{
if
!
bytes
.
Equal
(
a
.
Data
(),
b
.
Data
())
{
if
!
bytes
.
Equal
(
a
.
Raw
Data
(),
b
.
Raw
Data
())
{
t
.
Fatal
(
"blocks aren't equal"
)
}
if
a
.
Key
()
!=
b
.
Key
()
{
...
...
testnet/network_test.go
View file @
540558d2
...
...
@@ -44,7 +44,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
// TODO assert that this came from the correct peer and that the message contents are as expected
ok
:=
false
for
_
,
b
:=
range
msgFromResponder
.
Blocks
()
{
if
string
(
b
.
Data
())
==
expectedStr
{
if
string
(
b
.
Raw
Data
())
==
expectedStr
{
wg
.
Done
()
ok
=
true
}
...
...
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