mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
parent
90daa7a68b
commit
5cb586c8ac
2 changed files with 26 additions and 29 deletions
|
|
@ -219,7 +219,7 @@ func handler(w http.ResponseWriter, r *http.Request, a *api.Api) {
|
||||||
w.Header().Set("Content-Type", mimeType)
|
w.Header().Set("Content-Type", mimeType)
|
||||||
http.ServeContent(w, r, uri, forever(), reader)
|
http.ServeContent(w, r, uri, forever(), reader)
|
||||||
glog.V(logger.Debug).Infof("Serve raw content '%s' (%d bytes) as '%s'", uri, size, mimeType)
|
glog.V(logger.Debug).Infof("Serve raw content '%s' (%d bytes) as '%s'", uri, size, mimeType)
|
||||||
|
|
||||||
// retrieve path via manifest
|
// retrieve path via manifest
|
||||||
} else {
|
} else {
|
||||||
glog.V(logger.Debug).Infof("Structured GET request '%s' received.", uri)
|
glog.V(logger.Debug).Infof("Structured GET request '%s' received.", uri)
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,45 @@
|
||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"bytes"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/swarm/storage"
|
|
||||||
"github.com/ethereum/go-ethereum/swarm/api"
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
|
"github.com/ethereum/go-ethereum/swarm/api"
|
||||||
|
"github.com/ethereum/go-ethereum/swarm/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBzzrGetPath(t *testing.T) {
|
func TestBzzrGetPath(t *testing.T) {
|
||||||
|
|
||||||
glog.SetToStderr(true)
|
glog.SetToStderr(true)
|
||||||
glog.SetV(6)
|
glog.SetV(6)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
maxproxyattempts := 3
|
maxproxyattempts := 3
|
||||||
|
|
||||||
testmanifest := []string{
|
testmanifest := []string{
|
||||||
`{"entries":[{"path":"a/","hash":"674af7073604ebfc0282a4ab21e5ef1a3c22913866879ebc0816f8a89896b2ed","contentType":"application/bzz-manifest+json","status":0}]}`,
|
`{"entries":[{"path":"a/","hash":"674af7073604ebfc0282a4ab21e5ef1a3c22913866879ebc0816f8a89896b2ed","contentType":"application/bzz-manifest+json","status":0}]}`,
|
||||||
`{"entries":[{"path":"a","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0},{"path":"b/","hash":"0a87b1c3e4bf013686cdf107ec58590f2004610ee58cc2240f26939f691215f5","contentType":"application/bzz-manifest+json","status":0}]}`,
|
`{"entries":[{"path":"a","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0},{"path":"b/","hash":"0a87b1c3e4bf013686cdf107ec58590f2004610ee58cc2240f26939f691215f5","contentType":"application/bzz-manifest+json","status":0}]}`,
|
||||||
`{"entries":[{"path":"b","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0},{"path":"c","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0}]}`,
|
`{"entries":[{"path":"b","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0},{"path":"c","hash":"011b4d03dd8c01f1049143cf9c4c817e4b167f1d1b83e5c6f0f10d89ba1e7bce","contentType":"","status":0}]}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
testrequests := make(map[string]int)
|
testrequests := make(map[string]int)
|
||||||
testrequests["/"] = 0
|
testrequests["/"] = 0
|
||||||
testrequests["/a"] = 1
|
testrequests["/a"] = 1
|
||||||
testrequests["/a/b"] = 2
|
testrequests["/a/b"] = 2
|
||||||
|
|
||||||
reader := [3]*bytes.Reader{}
|
reader := [3]*bytes.Reader{}
|
||||||
|
|
||||||
key := [3]storage.Key{}
|
key := [3]storage.Key{}
|
||||||
|
|
||||||
dir, _ := ioutil.TempDir("", "bzz-storage-test")
|
dir, _ := ioutil.TempDir("", "bzz-storage-test")
|
||||||
|
|
||||||
storeparams := &storage.StoreParams{
|
storeparams := &storage.StoreParams{
|
||||||
dir,
|
dir,
|
||||||
5000000,
|
5000000,
|
||||||
|
|
@ -58,9 +58,9 @@ func TestBzzrGetPath(t *testing.T) {
|
||||||
}
|
}
|
||||||
dpa.Start()
|
dpa.Start()
|
||||||
defer dpa.Stop()
|
defer dpa.Stop()
|
||||||
|
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
|
|
||||||
for i, mf := range testmanifest {
|
for i, mf := range testmanifest {
|
||||||
reader[i] = bytes.NewReader([]byte(mf))
|
reader[i] = bytes.NewReader([]byte(mf))
|
||||||
key[i], err = dpa.Store(reader[i], int64(len(mf)), wg, nil)
|
key[i], err = dpa.Store(reader[i], int64(len(mf)), wg, nil)
|
||||||
|
|
@ -69,28 +69,26 @@ func TestBzzrGetPath(t *testing.T) {
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
a := api.NewApi(dpa, nil)
|
a := api.NewApi(dpa, nil)
|
||||||
|
|
||||||
// iterate port numbers up if fail
|
// iterate port numbers up if fail
|
||||||
StartHttpServer(a, "8504")
|
StartHttpServer(a, "8504")
|
||||||
// how to wait for ListenAndServe to have initialized? This is pretty cruuuude
|
// how to wait for ListenAndServe to have initialized? This is pretty cruuuude
|
||||||
// if we fix it we don't need maxproxyattempts anymore either
|
// if we fix it we don't need maxproxyattempts anymore either
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
for i := 0; i <= maxproxyattempts; i++ {
|
for i := 0; i <= maxproxyattempts; i++ {
|
||||||
_, err := http.Get("http://127.0.0.1:8504/bzzr:/" + common.ToHex(key[0])[2:] + "/a")
|
_, err := http.Get("http://127.0.0.1:8504/bzzr:/" + common.ToHex(key[0])[2:] + "/a")
|
||||||
if i == maxproxyattempts {
|
if i == maxproxyattempts {
|
||||||
t.Fatalf("Failed to connect to proxy after %v attempts: %v", i, err)
|
t.Fatalf("Failed to connect to proxy after %v attempts: %v", i, err)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
t.Logf("Proxy connect failed: %v", err)
|
t.Logf("Proxy connect failed: %v", err)
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for k, v := range testrequests {
|
for k, v := range testrequests {
|
||||||
var body []byte
|
var body []byte
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
|
|
@ -99,13 +97,12 @@ func TestBzzrGetPath(t *testing.T) {
|
||||||
resp, err = http.Get(url)
|
resp, err = http.Get(url)
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err = ioutil.ReadAll(resp.Body)
|
body, err = ioutil.ReadAll(resp.Body)
|
||||||
|
|
||||||
if string(body) != testmanifest[v] {
|
if string(body) != testmanifest[v] {
|
||||||
t.Fatalf("Response body does not match, expected: %v, got %v", testmanifest[v], string(body))
|
t.Fatalf("Response body does not match, expected: %v, got %v", testmanifest[v], string(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Log(string(body))
|
t.Log(string(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue