@@ -2,15 +2,17 @@ package api
22
33import (
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
1416type Server struct {
1517 rpc * grpc.Server
1618 proxy * http.Server
@@ -22,22 +24,19 @@ type Server struct {
2224
2325// Config specifies server settings.
2426type 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.
3533func 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}
0 commit comments