2019-06-25 11:42:17 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2019-07-23 17:27:45 +00:00
|
|
|
"context"
|
2019-07-23 15:33:25 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/lib/auth"
|
2019-06-25 11:42:17 +00:00
|
|
|
"net/http"
|
|
|
|
|
2019-06-29 09:19:06 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/api"
|
2019-07-08 15:14:36 +00:00
|
|
|
"github.com/filecoin-project/go-lotus/lib/jsonrpc"
|
2019-06-25 11:42:17 +00:00
|
|
|
)
|
|
|
|
|
2019-07-23 17:27:45 +00:00
|
|
|
func serveRPC(a api.API, addr string, verify func(ctx context.Context, token string) ([]string, error)) error {
|
2019-07-08 12:46:30 +00:00
|
|
|
rpcServer := jsonrpc.NewServer()
|
2019-07-18 16:51:21 +00:00
|
|
|
rpcServer.Register("Filecoin", api.Permissioned(a))
|
2019-07-23 15:33:25 +00:00
|
|
|
|
|
|
|
authHandler := &auth.Handler{
|
2019-07-23 17:27:45 +00:00
|
|
|
Verify: verify,
|
2019-07-23 15:33:25 +00:00
|
|
|
Next: rpcServer.ServeHTTP,
|
|
|
|
}
|
|
|
|
|
|
|
|
http.Handle("/rpc/v0", authHandler)
|
2019-07-08 20:50:13 +00:00
|
|
|
return http.ListenAndServe(addr, http.DefaultServeMux)
|
2019-06-25 11:42:17 +00:00
|
|
|
}
|