From 68be28ca6dfce8d77120f90450c25b98d675de08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sat, 17 Oct 2020 12:53:42 +0200 Subject: [PATCH] Add Session API --- api/api_common.go | 5 +++++ api/apistruct/struct.go | 9 +++++++-- node/impl/common/common.go | 10 ++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/api/api_common.go b/api/api_common.go index f8fcbe8c5..5b036d1f6 100644 --- a/api/api_common.go +++ b/api/api_common.go @@ -4,6 +4,8 @@ import ( "context" "fmt" + "github.com/google/uuid" + "github.com/filecoin-project/go-jsonrpc/auth" metrics "github.com/libp2p/go-libp2p-core/metrics" "github.com/libp2p/go-libp2p-core/network" @@ -58,6 +60,9 @@ type Common interface { // trigger graceful shutdown Shutdown(context.Context) error + // Session returns a random UUID of api provider session + Session(context.Context) (uuid.UUID, error) + Closing(context.Context) (<-chan struct{}, error) } diff --git a/api/apistruct/struct.go b/api/apistruct/struct.go index edf119114..b664f594f 100644 --- a/api/apistruct/struct.go +++ b/api/apistruct/struct.go @@ -5,8 +5,7 @@ import ( "io" "time" - stnetwork "github.com/filecoin-project/go-state-types/network" - + "github.com/google/uuid" "github.com/ipfs/go-cid" metrics "github.com/libp2p/go-libp2p-core/metrics" "github.com/libp2p/go-libp2p-core/network" @@ -24,6 +23,7 @@ import ( "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/go-state-types/crypto" "github.com/filecoin-project/go-state-types/dline" + stnetwork "github.com/filecoin-project/go-state-types/network" "github.com/filecoin-project/lotus/extern/sector-storage/fsutil" "github.com/filecoin-project/lotus/extern/sector-storage/sealtasks" "github.com/filecoin-project/lotus/extern/sector-storage/stores" @@ -67,6 +67,7 @@ type CommonStruct struct { LogSetLevel func(context.Context, string, string) error `perm:"write"` Shutdown func(context.Context) error `perm:"admin"` + Session func(context.Context) (uuid.UUID, error) `perm:"read"` Closing func(context.Context) (<-chan struct{}, error) `perm:"read"` } } @@ -487,6 +488,10 @@ func (c *CommonStruct) Shutdown(ctx context.Context) error { return c.Internal.Shutdown(ctx) } +func (c *CommonStruct) Session(ctx context.Context) (uuid.UUID, error) { + return c.Internal.Session(ctx) +} + func (c *CommonStruct) Closing(ctx context.Context) (<-chan struct{}, error) { return c.Internal.Closing(ctx) } diff --git a/node/impl/common/common.go b/node/impl/common/common.go index da7cfff25..79478e489 100644 --- a/node/impl/common/common.go +++ b/node/impl/common/common.go @@ -5,9 +5,9 @@ import ( "sort" "strings" - logging "github.com/ipfs/go-log/v2" - "github.com/gbrlsnchs/jwt/v3" + "github.com/google/uuid" + logging "github.com/ipfs/go-log/v2" "github.com/libp2p/go-libp2p-core/host" metrics "github.com/libp2p/go-libp2p-core/metrics" "github.com/libp2p/go-libp2p-core/network" @@ -27,6 +27,8 @@ import ( "github.com/filecoin-project/lotus/node/modules/lp2p" ) +var session = uuid.New() + type CommonAPI struct { fx.In @@ -202,6 +204,10 @@ func (a *CommonAPI) Shutdown(ctx context.Context) error { return nil } +func (a *CommonAPI) Session(ctx context.Context) (uuid.UUID, error) { + return session, nil +} + func (a *CommonAPI) Closing(ctx context.Context) (<-chan struct{}, error) { return make(chan struct{}), nil // relies on jsonrpc closing }