Skip to content

Commit 69f52c0

Browse files
committed
Merge remote-tracking branch 'origin/master' into asutula/deals-client
Signed-off-by: Aaron Sutula <hi@asutula.com>
2 parents 21aee01 + 1782b47 commit 69f52c0

13 files changed

Lines changed: 131 additions & 479 deletions

File tree

.gitignore

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,5 @@
1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
1616

17-
# JS PB files
18-
*.js
19-
*.d.ts
20-
2117
# vscode config folder
2218
.vscode/
23-
24-
**/node_modules

api/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
pb "github.com/textileio/filecoin/api/pb"
1010
"github.com/textileio/filecoin/deals"
1111
"github.com/textileio/filecoin/lotus/types"
12-
"github.com/textileio/go-threads/util"
12+
"github.com/textileio/filecoin/util"
1313
"google.golang.org/grpc"
1414
)
1515

@@ -126,13 +126,13 @@ func (c *Client) Store(addr string, data io.Reader, dealConfigs []deals.DealConf
126126
cids[i] = id
127127
}
128128

129-
outDealConfigs := make([]deals.DealConfig, len(reply.GetDealConfigs()))
130-
for i, dealConfig := range reply.GetDealConfigs() {
131-
outDealConfigs[i] = deals.DealConfig{
129+
failedDeals := make([]deals.DealConfig, len(reply.GetFailedDeals()))
130+
for i, dealConfig := range reply.GetFailedDeals() {
131+
failedDeals[i] = deals.DealConfig{
132132
Miner: dealConfig.GetMiner(),
133133
EpochPrice: types.NewInt(dealConfig.GetEpochPrice()),
134134
}
135135
}
136136

137-
return cids, outDealConfigs, nil
137+
return cids, failedDeals, nil
138138
}

api/pb/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
PB = $(wildcard *.proto)
22
GO = $(PB:.proto=.pb.go)
3-
PROTOC_GEN_TS_PATH = "./node_modules/.bin/protoc-gen-ts"
43

54
all: $(GO)
65

76
%.pb.go: %.proto
87
protoc -I=. -I=$(GOPATH)/src \
9-
--plugin="protoc-gen-ts=${PROTOC_GEN_TS_PATH}" --js_out="import_style=commonjs,binary:." --ts_out="service=grpc-web:." \
108
--go_out=\
119
plugins=grpc:\
1210
. $<
1311

1412
clean:
1513
rm -f *.pb.go
1614
rm -f *pb_test.go
17-
rm -f *.js
18-
rm -f *.d.ts
1915

2016
.PHONY: clean

api/pb/api.pb.go

Lines changed: 46 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/pb/api.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ message StoreRequest {
6262

6363
message StoreReply {
6464
repeated string cids = 1;
65-
repeated DealConfig dealConfigs = 2;
65+
repeated DealConfig failedDeals = 2;
6666
}
6767

6868
message WatchRequest {

api/pb/package-lock.json

Lines changed: 0 additions & 40 deletions
This file was deleted.

api/pb/package.json

Lines changed: 0 additions & 25 deletions
This file was deleted.

api/server.go

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,56 @@
11
package api
22

33
import (
4-
"context"
54
"net"
6-
"net/http"
75

86
"github.com/ipfs/go-datastore"
7+
ma "github.com/multiformats/go-multiaddr"
98
pb "github.com/textileio/filecoin/api/pb"
109
"github.com/textileio/filecoin/deals"
1110
"github.com/textileio/filecoin/lotus"
11+
"github.com/textileio/filecoin/util"
1212
"google.golang.org/grpc"
1313
)
1414

1515
// Server represents the configured lotus client and filecoin grpc server
1616
type Server struct {
17-
rpc *grpc.Server
18-
proxy *http.Server
19-
service *service
20-
21-
ctx context.Context
22-
cancel context.CancelFunc
17+
rpc *grpc.Server
18+
service *service
19+
closeLotus func()
2320
}
2421

2522
// Config specifies server settings.
2623
type Config struct {
27-
LotusAddress string
24+
LotusAddress ma.Multiaddr
2825
LotusAuthToken string
29-
GrpcHostAddress string
26+
GrpcHostAddress ma.Multiaddr
3027
}
3128

3229
// NewServer starts and returns a new server with the given configuration.
33-
func NewServer(ctx context.Context, conf Config) (*Server, error) {
34-
c, cls, err := lotus.New(conf.LotusAddress, conf.LotusAuthToken)
30+
func NewServer(conf Config) (*Server, error) {
31+
lotusAddr, err := util.TCPAddrFromMultiAddr(conf.LotusAddress)
32+
if err != nil {
33+
return nil, err
34+
}
35+
c, cls, err := lotus.New(lotusAddr, conf.LotusAuthToken)
3536
if err != nil {
3637
panic(err)
3738
}
38-
defer cls()
3939

40+
// ToDo: use some other persistent data store
4041
dm := deals.New(c, datastore.NewMapDatastore())
4142

42-
ctx, cancel := context.WithCancel(ctx)
4343
s := &Server{
44-
rpc: grpc.NewServer(),
45-
service: &service{dealModule: dm},
46-
ctx: ctx,
47-
cancel: cancel,
44+
rpc: grpc.NewServer(),
45+
service: &service{dealModule: dm},
46+
closeLotus: cls,
4847
}
4948

50-
listener, err := net.Listen("tcp", conf.GrpcHostAddress)
49+
grpcAddr, err := util.TCPAddrFromMultiAddr(conf.GrpcHostAddress)
50+
if err != nil {
51+
return nil, err
52+
}
53+
listener, err := net.Listen("tcp", grpcAddr)
5154
if err != nil {
5255
return nil, err
5356
}
@@ -58,3 +61,10 @@ func NewServer(ctx context.Context, conf Config) (*Server, error) {
5861

5962
return s, nil
6063
}
64+
65+
// Close shuts down the server
66+
func (s *Server) Close() {
67+
s.service.dealModule.Close()
68+
s.closeLotus()
69+
s.rpc.Stop()
70+
}

0 commit comments

Comments
 (0)