Skip to content

Commit

Permalink
Adds lowMem option from older dep state (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewxhill authored Apr 8, 2020
1 parent b6c005c commit 2f4d253
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 61 deletions.
48 changes: 0 additions & 48 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,6 @@ checkout-linux: &checkout-linux
at: /root

jobs:
persist-checkout:
docker:
- image: python
steps:
- checkout
- run:
name: clean up git
command: |
rm -rf .git
- persist_to_workspace:
root: /root
paths:
- project

unit-test:
docker:
- image: textile/builder:1.12.5
steps:
- *checkout-linux
- restore_cache:
key: go-mod-v1-{{ checksum "go.sum" }}-{{ arch }}
- run:
name: cache mods
command: |
go mod download
- save_cache:
key: go-mod-v1-{{ checksum "go.sum" }}-{{ arch }}
paths:
- /go/pkg/mod
- run:
name: run tests
command: |
make test
build-ios-framework:
macos:
xcode: "10.2.1"
Expand Down Expand Up @@ -245,27 +211,13 @@ workflows:
version: 2
grpc-ipfs-lite:
jobs:
- persist-checkout:
filters:
tags:
only: /.*/
- unit-test:
requires:
- persist-checkout
filters:
tags:
only: /.*/
- build-ios-framework:
requires:
- unit-test
filters:
branches:
only: master
tags:
only: /.*/
- build-android-aar:
requires:
- unit-test
filters:
branches:
only: master
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Tests
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
- name: Check out code
uses: actions/checkout@v1
- name: Cache dependencies
id: cache-dependencies
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get dependencies
if: steps.cache-dependencies.outputs.cache-hit != 'true'
run: |
go get -v -t -d ./...
- name: Test
run: go test ./...
14 changes: 8 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ module github.com/textileio/grpc-ipfs-lite
go 1.13

require (
github.com/golang/protobuf v1.3.4
github.com/hsanjuan/ipfs-lite v0.2.0
github.com/dgraph-io/badger v1.6.0
github.com/golang/protobuf v1.3.2
github.com/hsanjuan/ipfs-lite v0.1.8
github.com/ipfs/go-block-format v0.0.2
github.com/ipfs/go-cid v0.0.4
github.com/ipfs/go-datastore v0.4.4
github.com/ipfs/go-datastore v0.3.1
github.com/ipfs/go-ds-badger v0.2.0
github.com/ipfs/go-ipld-cbor v0.0.3
github.com/ipfs/go-ipld-format v0.0.2
github.com/ipfs/go-log v0.0.1
github.com/ipfs/go-merkledag v0.3.1
github.com/libp2p/go-libp2p-core v0.5.0
github.com/libp2p/go-libp2p-kad-dht v0.5.1
github.com/libp2p/go-libp2p-core v0.2.3
github.com/libp2p/go-libp2p-kad-dht v0.2.1
github.com/multiformats/go-multiaddr v0.2.0
github.com/multiformats/go-multihash v0.0.10
golang.org/x/mobile v0.0.0-20191210151939-1a1fef82734d // indirect
google.golang.org/grpc v1.28.1
google.golang.org/grpc v1.26.0
)
4 changes: 2 additions & 2 deletions mobile/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ const ipfsPort = 4006
const grpcPort = 10001

// Start starts the mobile ipfs-lite peer and gRPC server
func Start(datastorePath string, debug bool) (int, error) {
func Start(datastorePath string, debug bool, lowMem bool) (int, error) {
var ctx context.Context
ctx, cancel = context.WithCancel(context.Background())

peerManager, err := util.NewPeerManager(ctx, datastorePath, ipfsPort, debug)
peerManager, err := util.NewPeerManager(ctx, datastorePath, ipfsPort, debug, lowMem)
if err != nil {
return 0, err
}
Expand Down
4 changes: 2 additions & 2 deletions mobile/mobile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

func TestStart(t *testing.T) {
port, err := Start("/tmp/mobile-ipfs-lite", false)
port, err := Start("/tmp/mobile-ipfs-lite", false, true)
if err != nil {
t.Fatalf("failed to Start: %v", err)
}
Expand All @@ -24,7 +24,7 @@ func TestStop(t *testing.T) {
}

func TestStartAgain(t *testing.T) {
port, err := Start("/tmp/mobile-ipfs-lite", false)
port, err := Start("/tmp/mobile-ipfs-lite", false, true)
if err != nil {
t.Fatalf("failed to Start again: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestSetup(t *testing.T) {
ctx, cancel = context.WithCancel(context.Background())

var err error
peerManager, err = util.NewPeerManager(ctx, "/tmp/ipfs-lite", 4005, false)
peerManager, err = util.NewPeerManager(ctx, "/tmp/ipfs-lite", 4005, false, false)
if err != nil {
t.Fatalf("failed to create peer: %v", err)
}
Expand Down
10 changes: 8 additions & 2 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"fmt"

"github.com/dgraph-io/badger/options"
ipfslite "github.com/hsanjuan/ipfs-lite"
"github.com/ipfs/go-datastore"
badger "github.com/ipfs/go-ds-badger"
"github.com/ipfs/go-log"
crypto "github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/host"
Expand Down Expand Up @@ -42,7 +44,7 @@ func (m *StandardManager) Stop() error {
}

// NewPeerManager creates a new server.PeerManager
func NewPeerManager(ctx context.Context, datastorePath string, port int, debug bool) (*StandardManager, error) {
func NewPeerManager(ctx context.Context, datastorePath string, port int, debug bool, lowMem bool) (*StandardManager, error) {
logLevel := "WARNING"
if debug {
logLevel = "DEBUG"
Expand All @@ -58,7 +60,11 @@ func NewPeerManager(ctx context.Context, datastorePath string, port int, debug b
var peerManager = StandardManager{}

var err error
peerManager.datastore, err = ipfslite.BadgerDatastore(datastorePath)
opts := badger.DefaultOptions
if lowMem {
opts.TableLoadingMode = options.FileIO
}
peerManager.datastore, err = badger.NewDatastore(datastorePath, &opts)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 2f4d253

Please sign in to comment.