Skip to content

Commit dbe4bc7

Browse files
committed
Wrap up server api
Signed-off-by: Aaron Sutula <hi@asutula.com>
1 parent edc80cd commit dbe4bc7

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

api/server.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ package api
22

33
import (
44
"context"
5+
"net"
56
"net/http"
67

78
"github.com/ipfs/go-datastore"
9+
pb "github.com/textileio/filecoin/api/pb"
810
"github.com/textileio/filecoin/client"
911
"github.com/textileio/filecoin/deals"
1012
"google.golang.org/grpc"
1113
)
1214

13-
// Server represents the configured filecoin grpc server
15+
// Server represents the configured lotus client and filecoin grpc server
1416
type Server struct {
1517
rpc *grpc.Server
1618
proxy *http.Server
@@ -22,22 +24,19 @@ type Server struct {
2224

2325
// Config specifies server settings.
2426
type Config struct {
25-
LotusAddress string
26-
LotusAuthToken string
27-
// RepoPath string
28-
// Addr ma.Multiaddr
29-
// ProxyAddr ma.Multiaddr
30-
// Debug bool
27+
LotusAddress string
28+
LotusAuthToken string
29+
GrpcHostAddress string
3130
}
3231

33-
// NewServer starts and returns a new server with the given threadservice.
34-
// The threadservice is *not* managed by the server.
32+
// NewServer starts and returns a new server with the given configuration.
3533
func NewServer(ctx context.Context, conf Config) (*Server, error) {
3634
c, cls, err := client.New(conf.LotusAddress, conf.LotusAuthToken)
3735
if err != nil {
3836
panic(err)
3937
}
4038
defer cls()
39+
4140
dm := deals.New(c, datastore.NewMapDatastore())
4241

4342
ctx, cancel := context.WithCancel(ctx)
@@ -48,5 +47,14 @@ func NewServer(ctx context.Context, conf Config) (*Server, error) {
4847
cancel: cancel,
4948
}
5049

51-
return nil, nil
50+
listener, err := net.Listen("tcp", conf.GrpcHostAddress)
51+
if err != nil {
52+
return nil, err
53+
}
54+
go func() {
55+
pb.RegisterAPIServer(s.rpc, s.service)
56+
s.rpc.Serve(listener)
57+
}()
58+
59+
return s, nil
5260
}

api/service.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,11 @@ func (s *service) Store(srv pb.API_StoreServer) error {
109109
}
110110

111111
replyCids := make([]string, len(storeResult.Cids))
112-
replyDealConfigs := make([]*pb.DealConfig, len(storeResult.DealConfigs))
113-
114112
for i, cid := range storeResult.Cids {
115113
replyCids[i] = cid.String()
116114
}
117115

116+
replyDealConfigs := make([]*pb.DealConfig, len(storeResult.DealConfigs))
118117
for i, dealConfig := range storeResult.DealConfigs {
119118
replyDealConfigs[i] = &pb.DealConfig{Miner: dealConfig.Miner, EpochPrice: dealConfig.EpochPrice.Uint64()}
120119
}

0 commit comments

Comments
 (0)