Skip to content

Commit c442340

Browse files
committed
Addressing pr feedback
Signed-off-by: Aaron Sutula <hi@asutula.com>
1 parent 396695b commit c442340

8 files changed

Lines changed: 82 additions & 155 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/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: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package api
33
import (
44
"context"
55
"net"
6-
"net/http"
76

87
"github.com/ipfs/go-datastore"
98
pb "github.com/textileio/filecoin/api/pb"
@@ -15,11 +14,10 @@ import (
1514
// Server represents the configured lotus client and filecoin grpc server
1615
type Server struct {
1716
rpc *grpc.Server
18-
proxy *http.Server
1917
service *service
2018

21-
ctx context.Context
22-
cancel context.CancelFunc
19+
cancel context.CancelFunc
20+
closeLotus func()
2321
}
2422

2523
// Config specifies server settings.
@@ -35,16 +33,16 @@ func NewServer(ctx context.Context, conf Config) (*Server, error) {
3533
if err != nil {
3634
panic(err)
3735
}
38-
defer cls()
3936

37+
// ToDo: use some other persistent data store
4038
dm := deals.New(c, datastore.NewMapDatastore())
4139

42-
ctx, cancel := context.WithCancel(ctx)
40+
_, cancel := context.WithCancel(ctx)
4341
s := &Server{
44-
rpc: grpc.NewServer(),
45-
service: &service{dealModule: dm},
46-
ctx: ctx,
47-
cancel: cancel,
42+
rpc: grpc.NewServer(),
43+
service: &service{dealModule: dm},
44+
cancel: cancel,
45+
closeLotus: cls,
4846
}
4947

5048
listener, err := net.Listen("tcp", conf.GrpcHostAddress)
@@ -58,3 +56,11 @@ func NewServer(ctx context.Context, conf Config) (*Server, error) {
5856

5957
return s, nil
6058
}
59+
60+
// Close shuts down the server
61+
func (s *Server) Close() {
62+
s.cancel()
63+
s.closeLotus()
64+
s.rpc.Stop()
65+
s.service.dealModule.Close()
66+
}

api/service.go

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type service struct {
2020

2121
type storeResult struct {
2222
Cids []cid.Cid
23-
DealConfigs []deals.DealConfig
23+
FailedDeals []deals.DealConfig
2424
Err error
2525
}
2626

@@ -33,12 +33,12 @@ func store(ctx context.Context, dealModule *deals.DealModule, storeParams *pb.St
3333
EpochPrice: types.NewInt(dealConfig.GetEpochPrice()),
3434
}
3535
}
36-
cids, dealConfigs, err := dealModule.Store(ctx, storeParams.GetAddress(), reader, dealConfigs, storeParams.GetDuration())
36+
cids, failedDeals, err := dealModule.Store(ctx, storeParams.GetAddress(), reader, dealConfigs, storeParams.GetDuration())
3737
if err != nil {
3838
ch <- storeResult{Err: err}
3939
return
4040
}
41-
ch <- storeResult{Cids: cids, DealConfigs: dealConfigs}
41+
ch <- storeResult{Cids: cids, FailedDeals: failedDeals}
4242
}
4343

4444
func (s *service) AvailableAsks(ctx context.Context, req *pb.AvailableAsksRequest) (*pb.AvailableAsksReply, error) {
@@ -75,7 +75,7 @@ func (s *service) Store(srv pb.API_StoreServer) error {
7575
case *pb.StoreRequest_StoreParams:
7676
storeParams = payload.StoreParams
7777
default:
78-
return status.Errorf(codes.InvalidArgument, "expexted StoreParams for StoreRequest.Payload but got %T", payload)
78+
return status.Errorf(codes.InvalidArgument, "expected StoreParams for StoreRequest.Payload but got %T", payload)
7979
}
8080

8181
reader, writer := io.Pipe()
@@ -113,12 +113,12 @@ func (s *service) Store(srv pb.API_StoreServer) error {
113113
replyCids[i] = cid.String()
114114
}
115115

116-
replyDealConfigs := make([]*pb.DealConfig, len(storeResult.DealConfigs))
117-
for i, dealConfig := range storeResult.DealConfigs {
118-
replyDealConfigs[i] = &pb.DealConfig{Miner: dealConfig.Miner, EpochPrice: dealConfig.EpochPrice.Uint64()}
116+
replyFailedDeals := make([]*pb.DealConfig, len(storeResult.FailedDeals))
117+
for i, dealConfig := range storeResult.FailedDeals {
118+
replyFailedDeals[i] = &pb.DealConfig{Miner: dealConfig.Miner, EpochPrice: dealConfig.EpochPrice.Uint64()}
119119
}
120120

121-
return srv.SendAndClose(&pb.StoreReply{Cids: replyCids, DealConfigs: replyDealConfigs})
121+
return srv.SendAndClose(&pb.StoreReply{Cids: replyCids, FailedDeals: replyFailedDeals})
122122
}
123123

124124
func (s *service) Watch(req *pb.WatchRequest, srv pb.API_WatchServer) error {
@@ -135,23 +135,18 @@ func (s *service) Watch(req *pb.WatchRequest, srv pb.API_WatchServer) error {
135135
return err
136136
}
137137

138-
for {
139-
update, ok := <-ch
140-
if ok == false {
141-
break
142-
} else {
143-
dealInfo := &pb.DealInfo{
144-
ProposalCid: update.ProposalCid.String(),
145-
StateID: update.StateID,
146-
StateName: update.StateName,
147-
Miner: update.Miner,
148-
PieceRef: update.PieceRef,
149-
Size: update.Size,
150-
PricePerEpoch: update.PricePerEpoch.Uint64(),
151-
Duration: update.Duration,
152-
}
153-
srv.Send(&pb.WatchReply{DealInfo: dealInfo})
138+
for update := range ch {
139+
dealInfo := &pb.DealInfo{
140+
ProposalCid: update.ProposalCid.String(),
141+
StateID: update.StateID,
142+
StateName: update.StateName,
143+
Miner: update.Miner,
144+
PieceRef: update.PieceRef,
145+
Size: update.Size,
146+
PricePerEpoch: update.PricePerEpoch.Uint64(),
147+
Duration: update.Duration,
154148
}
149+
srv.Send(&pb.WatchReply{DealInfo: dealInfo})
155150
}
156151
return nil
157152
}

0 commit comments

Comments
 (0)