Skip to content

Commit 64d3cb7

Browse files
committed
Merge branch 'master' into issue-1703
2 parents 11e79b5 + 3fd9021 commit 64d3cb7

File tree

97 files changed

+5314
-7523
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+5314
-7523
lines changed

.travis.yml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,25 @@ jobs:
1515
- stage: lint
1616
os: linux
1717
dist: trusty
18-
go: 1.12.x
18+
go: 1.13.x
1919
env:
2020
- lint
2121
script:
2222
- go run build/ci.go lint
2323

24+
# Go 1.12.x is needed because of the Ubuntu PPA builds
25+
- stage: build
26+
os: linux
27+
dist: trusty
28+
sudo: required
29+
go: 1.12.x
30+
script:
31+
- sudo modprobe fuse
32+
- sudo chmod 666 /dev/fuse
33+
- sudo chown root:$USER /etc/fuse.conf
34+
- go run build/ci.go install
35+
- go run build/ci.go test -coverage $TEST_PACKAGES
36+
2437
# Go 1.11.x is needed because of the Ubuntu PPA builds
2538
- stage: build
2639
os: linux
@@ -39,7 +52,7 @@ jobs:
3952
os: linux
4053
dist: trusty
4154
sudo: required
42-
go: 1.12.x
55+
go: 1.13.x
4356
script:
4457
- sudo modprobe fuse
4558
- sudo chmod 666 /dev/fuse
@@ -49,7 +62,7 @@ jobs:
4962

5063
- stage: build
5164
os: osx
52-
go: 1.12.x
65+
go: 1.13.x
5366
script:
5467
- echo "Increase the maximum number of open file descriptors on macOS"
5568
- NOFILE=20480
@@ -68,7 +81,7 @@ jobs:
6881
if: type = push
6982
os: linux
7083
dist: trusty
71-
go: 1.12.x
84+
go: 1.13.x
7285
env:
7386
- ubuntu-ppa
7487
addons:
@@ -90,7 +103,7 @@ jobs:
90103
os: linux
91104
dist: trusty
92105
sudo: required
93-
go: 1.12.x
106+
go: 1.13.x
94107
env:
95108
- azure-linux
96109
addons:
@@ -124,7 +137,7 @@ jobs:
124137
dist: trusty
125138
services:
126139
- docker
127-
go: 1.12.x
140+
go: 1.13.x
128141
env:
129142
- azure-linux-mips
130143
script:
@@ -148,7 +161,7 @@ jobs:
148161
- stage: deploy
149162
if: type = push
150163
os: osx
151-
go: 1.12.x
164+
go: 1.13.x
152165
env:
153166
- azure-osx
154167
script:
@@ -161,7 +174,7 @@ jobs:
161174
if: type = cron
162175
os: linux
163176
dist: trusty
164-
go: 1.12.x
177+
go: 1.13.x
165178
env:
166179
- azure-purge
167180
script:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.12-alpine as builder
1+
FROM golang:1.13-alpine as builder
22
RUN apk add --no-cache make gcc musl-dev linux-headers git
33
ADD . /swarm
44
WORKDIR /swarm

Dockerfile.alltools

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.12-alpine as builder
1+
FROM golang:1.13-alpine as builder
22
RUN apk add --no-cache make gcc musl-dev linux-headers git
33
ADD . /swarm
44
WORKDIR /swarm

api/api_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"context"
2222
crand "crypto/rand"
2323
"errors"
24-
"flag"
2524
"fmt"
2625
"io"
2726
"io/ioutil"
@@ -34,15 +33,14 @@ import (
3433
"github.com/ethereum/go-ethereum/core/types"
3534
"github.com/ethereum/go-ethereum/log"
3635
"github.com/ethersphere/swarm/chunk"
36+
chunktesting "github.com/ethersphere/swarm/chunk/testing"
3737
"github.com/ethersphere/swarm/sctx"
3838
"github.com/ethersphere/swarm/storage"
3939
"github.com/ethersphere/swarm/testutil"
4040
)
4141

4242
func init() {
43-
loglevel := flag.Int("loglevel", 2, "loglevel")
44-
flag.Parse()
45-
log.Root().SetHandler(log.CallerFileHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(os.Stderr, log.TerminalFormat(true)))))
43+
testutil.Init()
4644
}
4745

4846
func testAPI(t *testing.T, f func(*API, *chunk.Tags, bool)) {
@@ -143,7 +141,7 @@ func TestApiPut(t *testing.T) {
143141
resp := testGet(t, api, addr.Hex(), "")
144142
checkResponse(t, resp, exp)
145143
tag := tags.All()[0]
146-
testutil.CheckTag(t, tag, 2, 2, 0, 2) //1 chunk data, 1 chunk manifest
144+
chunktesting.CheckTag(t, tag, 2, 2, 0, 2) //1 chunk data, 1 chunk manifest
147145
})
148146
}
149147

@@ -170,11 +168,11 @@ func TestApiTagLarge(t *testing.T) {
170168
if toEncrypt {
171169
tag := tags.All()[0]
172170
expect := int64(4095 + 64 + 1)
173-
testutil.CheckTag(t, tag, expect, expect, 0, expect)
171+
chunktesting.CheckTag(t, tag, expect, expect, 0, expect)
174172
} else {
175173
tag := tags.All()[0]
176174
expect := int64(4095 + 32 + 1)
177-
testutil.CheckTag(t, tag, expect, expect, 0, expect)
175+
chunktesting.CheckTag(t, tag, expect, expect, 0, expect)
178176
}
179177
})
180178
}

api/client/client_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/ethereum/go-ethereum/crypto"
3030
"github.com/ethersphere/swarm/api"
3131
swarmhttp "github.com/ethersphere/swarm/api/http"
32+
chunktesting "github.com/ethersphere/swarm/chunk/testing"
3233
"github.com/ethersphere/swarm/storage"
3334
"github.com/ethersphere/swarm/storage/feed"
3435
"github.com/ethersphere/swarm/storage/feed/lookup"
@@ -50,7 +51,7 @@ func TestClientUploadDownloadRaw(t *testing.T) {
5051

5152
// check the tag was created successfully
5253
tag := srv.Tags.All()[0]
53-
testutil.CheckTag(t, tag, 1, 1, 0, 1)
54+
chunktesting.CheckTag(t, tag, 1, 1, 0, 1)
5455
}
5556

5657
func TestClientUploadDownloadRawEncrypted(t *testing.T) {
@@ -68,7 +69,7 @@ func TestClientUploadDownloadRawEncrypted(t *testing.T) {
6869

6970
// check the tag was created successfully
7071
tag := srv.Tags.All()[0]
71-
testutil.CheckTag(t, tag, 1, 1, 0, 1)
72+
chunktesting.CheckTag(t, tag, 1, 1, 0, 1)
7273
}
7374

7475
func testClientUploadDownloadRaw(srv *swarmhttp.TestSwarmServer, toEncrypt bool, t *testing.T, data []byte, toPin bool) string {
@@ -227,7 +228,7 @@ func TestClientUploadDownloadDirectory(t *testing.T) {
227228

228229
// check the tag was created successfully
229230
tag := srv.Tags.All()[0]
230-
testutil.CheckTag(t, tag, 9, 9, 0, 9)
231+
chunktesting.CheckTag(t, tag, 9, 9, 0, 9)
231232

232233
// check we can download the individual files
233234
checkDownloadFile := func(path string, expected []byte) {
@@ -371,7 +372,7 @@ func TestClientMultipartUpload(t *testing.T) {
371372

372373
// check the tag was created successfully
373374
tag := srv.Tags.All()[0]
374-
testutil.CheckTag(t, tag, 9, 9, 0, 9)
375+
chunktesting.CheckTag(t, tag, 9, 9, 0, 9)
375376

376377
// check we can download the individual files
377378
checkDownloadFile := func(path string) {

api/http/server_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"encoding/hex"
2424
"encoding/json"
2525
"errors"
26-
"flag"
2726
"fmt"
2827
"io"
2928
"io/ioutil"
@@ -44,6 +43,7 @@ import (
4443
"github.com/ethereum/go-ethereum/log"
4544
"github.com/ethersphere/swarm/api"
4645
"github.com/ethersphere/swarm/chunk"
46+
chunktesting "github.com/ethersphere/swarm/chunk/testing"
4747
"github.com/ethersphere/swarm/storage"
4848
"github.com/ethersphere/swarm/storage/feed"
4949
"github.com/ethersphere/swarm/storage/feed/lookup"
@@ -52,9 +52,7 @@ import (
5252
)
5353

5454
func init() {
55-
loglevel := flag.Int("loglevel", 2, "loglevel")
56-
flag.Parse()
57-
log.Root().SetHandler(log.CallerFileHandler(log.LvlFilterHandler(log.Lvl(*loglevel), log.StreamHandler(os.Stderr, log.TerminalFormat(true)))))
55+
testutil.Init()
5856
}
5957

6058
func serverFunc(api *api.API, pinAPI *pin.API) TestServer {
@@ -947,7 +945,7 @@ func testBzzTar(encrypted bool, t *testing.T) {
947945

948946
// check that the tag was written correctly
949947
tag := srv.Tags.All()[0]
950-
testutil.CheckTag(t, tag, 4, 4, 0, 4)
948+
chunktesting.CheckTag(t, tag, 4, 4, 0, 4)
951949

952950
swarmHash, err := ioutil.ReadAll(resp2.Body)
953951
resp2.Body.Close()
@@ -1083,7 +1081,7 @@ func TestBzzCorrectTagEstimate(t *testing.T) {
10831081
<-time.After(10 * time.Millisecond)
10841082
case 1:
10851083
tag := srv.Tags.All()[0]
1086-
testutil.CheckTag(t, tag, 0, 0, 0, v.expChunks)
1084+
chunktesting.CheckTag(t, tag, 0, 0, 0, v.expChunks)
10871085
srv.Tags.Delete(tag.Uid)
10881086
done = true
10891087
}

api/http/test_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewTestSwarmServer(t *testing.T, serverFunc func(*api.API, *pin.API) TestSe
5757
}
5858

5959
tags := chunk.NewTags()
60-
fileStore := storage.NewFileStore(localStore, storage.NewFileStoreParams(), tags)
60+
fileStore := storage.NewFileStore(localStore, localStore, storage.NewFileStoreParams(), tags)
6161

6262
// Swarm feeds test setup
6363
feedsDir, err := ioutil.TempDir("", "swarm-feeds-test")

api/inspector.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,29 @@ package api
1818

1919
import (
2020
"context"
21+
"encoding/json"
2122
"fmt"
2223
"strings"
2324
"time"
2425

2526
"github.com/ethereum/go-ethereum/metrics"
2627
"github.com/ethersphere/swarm/log"
2728
"github.com/ethersphere/swarm/network"
29+
stream "github.com/ethersphere/swarm/network/stream/v2"
2830
"github.com/ethersphere/swarm/storage"
2931
)
3032

33+
const InspectorIsPullSyncingTolerance = 15 * time.Second
34+
3135
type Inspector struct {
3236
api *API
3337
hive *network.Hive
3438
netStore *storage.NetStore
39+
stream *stream.Registry
3540
}
3641

37-
func NewInspector(api *API, hive *network.Hive, netStore *storage.NetStore) *Inspector {
38-
return &Inspector{api, hive, netStore}
42+
func NewInspector(api *API, hive *network.Hive, netStore *storage.NetStore, pullSyncer *stream.Registry) *Inspector {
43+
return &Inspector{api, hive, netStore, pullSyncer}
3944
}
4045

4146
// Hive prints the kademlia table
@@ -49,15 +54,12 @@ func (i *Inspector) KademliaInfo() network.KademliaInfo {
4954
}
5055

5156
func (i *Inspector) IsPullSyncing() bool {
52-
lastReceivedChunksMsg := metrics.GetOrRegisterGauge("network.stream.received_chunks", nil)
53-
54-
// last received chunks msg time
55-
lrct := time.Unix(0, lastReceivedChunksMsg.Value())
57+
t := i.stream.LastReceivedChunkTime()
5658

5759
// if last received chunks msg time is after now-15sec. (i.e. within the last 15sec.) then we say that the node is still syncing
5860
// technically this is not correct, because this might have been a retrieve request, but for the time being it works for our purposes
5961
// because we know we are not making retrieve requests on the node while checking this
60-
return lrct.After(time.Now().Add(-15 * time.Second))
62+
return t.After(time.Now().Add(-InspectorIsPullSyncingTolerance))
6163
}
6264

6365
// DeliveriesPerPeer returns the sum of chunks we received from a given peer
@@ -96,3 +98,15 @@ func (i *Inspector) Has(chunkAddresses []storage.Address) string {
9698

9799
return strings.Join(hostChunks, "")
98100
}
101+
102+
func (i *Inspector) PeerStreams() (string, error) {
103+
peerInfo, err := i.stream.PeerInfo()
104+
if err != nil {
105+
return "", err
106+
}
107+
v, err := json.Marshal(peerInfo)
108+
if err != nil {
109+
return "", err
110+
}
111+
return string(v), nil
112+
}

api/inspector_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package api
2+
3+
import (
4+
"crypto/rand"
5+
"encoding/hex"
6+
"io/ioutil"
7+
"os"
8+
"strings"
9+
"testing"
10+
11+
"github.com/ethersphere/swarm/network"
12+
stream "github.com/ethersphere/swarm/network/stream/v2"
13+
"github.com/ethersphere/swarm/storage"
14+
"github.com/ethersphere/swarm/storage/localstore"
15+
16+
"github.com/ethereum/go-ethereum/p2p/enode"
17+
"github.com/ethereum/go-ethereum/rpc"
18+
"github.com/ethersphere/swarm/state"
19+
)
20+
21+
// TestInspectorPeerStreams validates that response from RPC peerStream has at
22+
// least some data.
23+
func TestInspectorPeerStreams(t *testing.T) {
24+
dir, err := ioutil.TempDir("", "swarm-")
25+
if err != nil {
26+
t.Fatal(err)
27+
}
28+
defer os.RemoveAll(dir)
29+
30+
baseKey := make([]byte, 32)
31+
_, err = rand.Read(baseKey)
32+
if err != nil {
33+
t.Fatal(err)
34+
}
35+
36+
localStore, err := localstore.New(dir, baseKey, &localstore.Options{})
37+
if err != nil {
38+
t.Fatal(err)
39+
}
40+
netStore := storage.NewNetStore(localStore, baseKey, enode.ID{})
41+
42+
i := NewInspector(nil, nil, netStore, stream.New(state.NewInmemoryStore(), baseKey, stream.NewSyncProvider(netStore, network.NewKademlia(
43+
baseKey,
44+
network.NewKadParams(),
45+
), false, false)))
46+
47+
server := rpc.NewServer()
48+
if err := server.RegisterName("inspector", i); err != nil {
49+
t.Fatal(err)
50+
}
51+
52+
client := rpc.DialInProc(server)
53+
54+
var peerInfo string
55+
56+
err = client.Call(&peerInfo, "inspector_peerStreams")
57+
if err != nil {
58+
t.Fatal(err)
59+
}
60+
61+
if !strings.Contains(peerInfo, `"base":"`+hex.EncodeToString(baseKey)[:16]+`"`) {
62+
t.Error("missing base key in response")
63+
}
64+
65+
t.Log(peerInfo)
66+
}

0 commit comments

Comments
 (0)