Commit b5f84f47 authored by Janoš Guljaš's avatar Janoš Guljaš Committed by GitHub

Revert "Fix bzz chunk api (#262)" (#279)

This reverts commit 10ee9ab7.
parent cc2fe7be
......@@ -48,7 +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 (bzz API)
- name: Test pushsync
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 --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 --bzz-chunk
......
......@@ -6,7 +6,6 @@ package api
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
......@@ -82,12 +81,8 @@ 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 {
......@@ -145,5 +140,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()[8:]))
_, _ = io.Copy(w, bytes.NewReader(chunk.Data()))
}
......@@ -6,7 +6,6 @@ package api_test
import (
"bytes"
"encoding/binary"
"io"
"io/ioutil"
"net/http"
......@@ -33,7 +32,7 @@ func TestChunkUploadDownload(t *testing.T) {
invalidHash = swarm.MustParseHexAddress("bbccdd")
validContent = []byte("bbaatt")
invalidContent = []byte("bbaattss")
mockValidator = validator.NewMockValidator(validHash, append(newSpan(uint64(len(validContent))), validContent...))
mockValidator = validator.NewMockValidator(validHash, validContent)
tag = tags.NewTags()
mockValidatingStorer = mock.NewValidatingStorer(mockValidator, tag)
client = newTestServer(t, testServerOptions{
......@@ -137,9 +136,3 @@ 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
}
......@@ -27,7 +27,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, append(newSpan(uint64(len(validContent))), validContent...))
mockValidator = validator.NewMockValidator(validHash, validContent)
tag = tags.NewTags()
mockValidatingStorer = mock.NewValidatingStorer(mockValidator, tag)
mockPusher = mp.NewMockPusher(tag)
......@@ -97,7 +97,7 @@ func TestTags(t *testing.T) {
// Add asecond valid contentto validator
secondValidHash := swarm.MustParseHexAddress("deadbeaf")
secondValidContent := []byte("123456")
mockValidator.AddPair(secondValidHash, append(newSpan(uint64(len(secondValidContent))), secondValidContent...))
mockValidator.AddPair(secondValidHash, secondValidContent)
sentHheaders = make(http.Header)
sentHheaders.Set(api.TagHeaderUid, strconv.FormatUint(uint64(ta.Uid), 10))
......
......@@ -6,7 +6,6 @@ package debugapi_test
import (
"bytes"
"encoding/binary"
"net/http"
"testing"
......@@ -27,7 +26,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, append(newSpan(uint64(len(data))), data...))
mockValidator := validator.NewMockValidator(hash, data)
tag := tags.NewTags()
mockValidatingStorer := mock.NewValidatingStorer(mockValidator, tag)
debugTestServer := newTestServer(t, testServerOptions{
......@@ -149,7 +148,7 @@ func TestPinChunkHandler(t *testing.T) {
// post another chunk
hash2 := swarm.MustParseHexAddress("ddeeff")
data2 := []byte("eagle")
mockValidator.AddPair(hash2, append(newSpan(uint64(len(data2))), data2...))
mockValidator.AddPair(hash2, data2)
jsonhttptest.ResponseDirect(t, bzzTestServer, http.MethodPost, resource(hash2), bytes.NewReader(data2), http.StatusOK, jsonhttp.StatusResponse{
Message: http.StatusText(http.StatusOK),
Code: http.StatusOK,
......@@ -173,9 +172,3 @@ func TestPinChunkHandler(t *testing.T) {
})
})
}
func newSpan(size uint64) []byte {
b := make([]byte, 8)
binary.LittleEndian.PutUint64(b, size)
return b
}
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