Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
10ee9ab7
Unverified
Commit
10ee9ab7
authored
Jun 05, 2020
by
Janoš Guljaš
Committed by
GitHub
Jun 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bzz chunk api (#262)
Co-authored-by:
svetomir
<
svetomirsmiljkovic@gmail.com
>
parent
0b7f1c63
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
8 deletions
+29
-8
beekeeper.yaml
.github/workflows/beekeeper.yaml
+3
-1
bzzchunk.go
pkg/api/bzzchunk.go
+7
-2
bzzchunk_test.go
pkg/api/bzzchunk_test.go
+8
-1
tag_test.go
pkg/api/tag_test.go
+2
-2
pin_test.go
pkg/debugapi/pin_test.go
+9
-2
No files found.
.github/workflows/beekeeper.yaml
View file @
10ee9ab7
...
...
@@ -48,5 +48,7 @@ jobs:
run
:
./beekeeper check fullconnectivity --api-scheme http --debug-api-scheme http --disable-namespace --debug-api-domain localhost --api-domain localhost --node-count "${REPLICA}"
-
name
:
Test pingpong
run
:
./beekeeper check pingpong --api-scheme http --debug-api-scheme http --disable-namespace --debug-api-domain localhost --api-domain localhost --node-count "${REPLICA}"
-
name
:
Test pushsync
-
name
:
Test pushsync
(bzz API)
run
:
./beekeeper check pushsync --api-scheme http --debug-api-scheme http --disable-namespace --debug-api-domain localhost --api-domain localhost --node-count "${REPLICA}" --upload-node-count "${REPLICA}" --chunks-per-node
3
-
name
:
Test pushsync (bzz-chunk API)
run
:
./beekeeper check pushsync --bzz-chunk --api-scheme http --debug-api-scheme http --disable-namespace --debug-api-domain localhost --api-domain localhost --node-count "${REPLICA}" --upload-node-count "${REPLICA}" --chunks-per-node
3
pkg/api/bzzchunk.go
View file @
10ee9ab7
...
...
@@ -6,6 +6,7 @@ package api
import
(
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
...
...
@@ -81,9 +82,13 @@ func (s *server) chunkUploadHandler(w http.ResponseWriter, r *http.Request) {
s
.
Logger
.
Error
(
"bzz-chunk: read chunk data error"
)
jsonhttp
.
InternalServerError
(
w
,
"cannot read chunk data"
)
return
}
span
:=
len
(
data
)
b
:=
make
([]
byte
,
8
)
binary
.
LittleEndian
.
PutUint64
(
b
,
uint64
(
span
))
data
=
append
(
b
,
data
...
)
seen
,
err
:=
s
.
Storer
.
Put
(
ctx
,
storage
.
ModePutUpload
,
swarm
.
NewChunk
(
address
,
data
))
if
err
!=
nil
{
s
.
Logger
.
Debugf
(
"bzz-chunk: chunk write error: %v, addr %s"
,
err
,
address
)
...
...
@@ -141,5 +146,5 @@ func (s *server) chunkGetHandler(w http.ResponseWriter, r *http.Request) {
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"binary/octet-stream"
)
_
,
_
=
io
.
Copy
(
w
,
bytes
.
NewReader
(
chunk
.
Data
()))
_
,
_
=
io
.
Copy
(
w
,
bytes
.
NewReader
(
chunk
.
Data
()
[
8
:
]
))
}
pkg/api/bzzchunk_test.go
View file @
10ee9ab7
...
...
@@ -6,6 +6,7 @@ package api_test
import
(
"bytes"
"encoding/binary"
"io"
"io/ioutil"
"net/http"
...
...
@@ -32,7 +33,7 @@ func TestChunkUploadDownload(t *testing.T) {
invalidHash
=
swarm
.
MustParseHexAddress
(
"bbccdd"
)
validContent
=
[]
byte
(
"bbaatt"
)
invalidContent
=
[]
byte
(
"bbaattss"
)
mockValidator
=
validator
.
NewMockValidator
(
validHash
,
validContent
)
mockValidator
=
validator
.
NewMockValidator
(
validHash
,
append
(
newSpan
(
uint64
(
len
(
validContent
))),
validContent
...
)
)
tag
=
tags
.
NewTags
()
mockValidatingStorer
=
mock
.
NewValidatingStorer
(
mockValidator
,
tag
)
client
=
newTestServer
(
t
,
testServerOptions
{
...
...
@@ -136,3 +137,9 @@ func request(t *testing.T, client *http.Client, method string, resource string,
}
return
resp
}
func
newSpan
(
size
uint64
)
[]
byte
{
b
:=
make
([]
byte
,
8
)
binary
.
LittleEndian
.
PutUint64
(
b
,
size
)
return
b
}
pkg/api/tag_test.go
View file @
10ee9ab7
...
...
@@ -28,7 +28,7 @@ func TestTags(t *testing.T) {
tagResourceUUid
=
func
(
uuid
uint64
)
string
{
return
"/bzz-tag/uuid/"
+
strconv
.
FormatUint
(
uuid
,
10
)
}
validHash
=
swarm
.
MustParseHexAddress
(
"aabbcc"
)
validContent
=
[]
byte
(
"bbaatt"
)
mockValidator
=
validator
.
NewMockValidator
(
validHash
,
validContent
)
mockValidator
=
validator
.
NewMockValidator
(
validHash
,
append
(
newSpan
(
uint64
(
len
(
validContent
))),
validContent
...
)
)
tag
=
tags
.
NewTags
()
mockValidatingStorer
=
mock
.
NewValidatingStorer
(
mockValidator
,
tag
)
mockPusher
=
mp
.
NewMockPusher
(
tag
)
...
...
@@ -98,7 +98,7 @@ func TestTags(t *testing.T) {
// Add asecond valid contentto validator
secondValidHash
:=
swarm
.
MustParseHexAddress
(
"deadbeaf"
)
secondValidContent
:=
[]
byte
(
"123456"
)
mockValidator
.
AddPair
(
secondValidHash
,
secondValidContent
)
mockValidator
.
AddPair
(
secondValidHash
,
append
(
newSpan
(
uint64
(
len
(
secondValidContent
))),
secondValidContent
...
)
)
sentHheaders
=
make
(
http
.
Header
)
sentHheaders
.
Set
(
api
.
TagHeaderUid
,
strconv
.
FormatUint
(
uint64
(
ta
.
Uid
),
10
))
...
...
pkg/debugapi/pin_test.go
View file @
10ee9ab7
...
...
@@ -6,6 +6,7 @@ package debugapi_test
import
(
"bytes"
"encoding/binary"
"net/http"
"testing"
...
...
@@ -26,7 +27,7 @@ func TestPinChunkHandler(t *testing.T) {
resource
:=
func
(
addr
swarm
.
Address
)
string
{
return
"/bzz-chunk/"
+
addr
.
String
()
}
hash
:=
swarm
.
MustParseHexAddress
(
"aabbcc"
)
data
:=
[]
byte
(
"bbaatt"
)
mockValidator
:=
validator
.
NewMockValidator
(
hash
,
data
)
mockValidator
:=
validator
.
NewMockValidator
(
hash
,
append
(
newSpan
(
uint64
(
len
(
data
))),
data
...
)
)
tag
:=
tags
.
NewTags
()
mockValidatingStorer
:=
mock
.
NewValidatingStorer
(
mockValidator
,
tag
)
debugTestServer
:=
newTestServer
(
t
,
testServerOptions
{
...
...
@@ -148,7 +149,7 @@ func TestPinChunkHandler(t *testing.T) {
// post another chunk
hash2
:=
swarm
.
MustParseHexAddress
(
"ddeeff"
)
data2
:=
[]
byte
(
"eagle"
)
mockValidator
.
AddPair
(
hash2
,
data2
)
mockValidator
.
AddPair
(
hash2
,
append
(
newSpan
(
uint64
(
len
(
data2
))),
data2
...
)
)
jsonhttptest
.
ResponseDirect
(
t
,
bzzTestServer
,
http
.
MethodPost
,
resource
(
hash2
),
bytes
.
NewReader
(
data2
),
http
.
StatusOK
,
jsonhttp
.
StatusResponse
{
Message
:
http
.
StatusText
(
http
.
StatusOK
),
Code
:
http
.
StatusOK
,
...
...
@@ -172,3 +173,9 @@ func TestPinChunkHandler(t *testing.T) {
})
})
}
func
newSpan
(
size
uint64
)
[]
byte
{
b
:=
make
([]
byte
,
8
)
binary
.
LittleEndian
.
PutUint64
(
b
,
size
)
return
b
}
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