Add Session API
This commit is contained in:
parent
b74a3229f8
commit
68be28ca6d
@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-jsonrpc/auth"
|
"github.com/filecoin-project/go-jsonrpc/auth"
|
||||||
metrics "github.com/libp2p/go-libp2p-core/metrics"
|
metrics "github.com/libp2p/go-libp2p-core/metrics"
|
||||||
"github.com/libp2p/go-libp2p-core/network"
|
"github.com/libp2p/go-libp2p-core/network"
|
||||||
@ -58,6 +60,9 @@ type Common interface {
|
|||||||
// trigger graceful shutdown
|
// trigger graceful shutdown
|
||||||
Shutdown(context.Context) error
|
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)
|
Closing(context.Context) (<-chan struct{}, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
stnetwork "github.com/filecoin-project/go-state-types/network"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
metrics "github.com/libp2p/go-libp2p-core/metrics"
|
metrics "github.com/libp2p/go-libp2p-core/metrics"
|
||||||
"github.com/libp2p/go-libp2p-core/network"
|
"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/big"
|
||||||
"github.com/filecoin-project/go-state-types/crypto"
|
"github.com/filecoin-project/go-state-types/crypto"
|
||||||
"github.com/filecoin-project/go-state-types/dline"
|
"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/fsutil"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/sealtasks"
|
"github.com/filecoin-project/lotus/extern/sector-storage/sealtasks"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
"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"`
|
LogSetLevel func(context.Context, string, string) error `perm:"write"`
|
||||||
|
|
||||||
Shutdown func(context.Context) error `perm:"admin"`
|
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"`
|
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)
|
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) {
|
func (c *CommonStruct) Closing(ctx context.Context) (<-chan struct{}, error) {
|
||||||
return c.Internal.Closing(ctx)
|
return c.Internal.Closing(ctx)
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
logging "github.com/ipfs/go-log/v2"
|
|
||||||
|
|
||||||
"github.com/gbrlsnchs/jwt/v3"
|
"github.com/gbrlsnchs/jwt/v3"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
logging "github.com/ipfs/go-log/v2"
|
||||||
"github.com/libp2p/go-libp2p-core/host"
|
"github.com/libp2p/go-libp2p-core/host"
|
||||||
metrics "github.com/libp2p/go-libp2p-core/metrics"
|
metrics "github.com/libp2p/go-libp2p-core/metrics"
|
||||||
"github.com/libp2p/go-libp2p-core/network"
|
"github.com/libp2p/go-libp2p-core/network"
|
||||||
@ -27,6 +27,8 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/node/modules/lp2p"
|
"github.com/filecoin-project/lotus/node/modules/lp2p"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var session = uuid.New()
|
||||||
|
|
||||||
type CommonAPI struct {
|
type CommonAPI struct {
|
||||||
fx.In
|
fx.In
|
||||||
|
|
||||||
@ -202,6 +204,10 @@ func (a *CommonAPI) Shutdown(ctx context.Context) error {
|
|||||||
return nil
|
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) {
|
func (a *CommonAPI) Closing(ctx context.Context) (<-chan struct{}, error) {
|
||||||
return make(chan struct{}), nil // relies on jsonrpc closing
|
return make(chan struct{}), nil // relies on jsonrpc closing
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user