refactoring: more refactoring to break import cycles
This commit is contained in:
parent
b2c06590b1
commit
3b3a50e419
|
@ -21,6 +21,10 @@ type P2PNodeResponse struct {
|
||||||
Uris []string `json:"uris"`
|
Uris []string `json:"uris"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HTTPServiceInterface interface {
|
||||||
|
GetHttpRouter(inject map[string]jape.Handler) *httprouter.Router
|
||||||
|
}
|
||||||
|
|
||||||
type HTTPService struct {
|
type HTTPService struct {
|
||||||
ServiceBase
|
ServiceBase
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/protocol"
|
"git.lumeweb.com/LumeWeb/libs5-go/protocol"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/protocol/base"
|
"git.lumeweb.com/LumeWeb/libs5-go/protocol/base"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/protocol/signed"
|
"git.lumeweb.com/LumeWeb/libs5-go/protocol/signed"
|
||||||
|
"git.lumeweb.com/LumeWeb/libs5-go/storage"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/structs"
|
"git.lumeweb.com/LumeWeb/libs5-go/structs"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/utils"
|
"git.lumeweb.com/LumeWeb/libs5-go/utils"
|
||||||
|
@ -24,6 +25,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ Service = (*P2PService)(nil)
|
var _ Service = (*P2PService)(nil)
|
||||||
|
var _ storage.StorageLocationProviderP2PService = (*P2PService)(nil)
|
||||||
|
var _ P2PServiceInterface = (*P2PService)(nil)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errUnsupportedProtocol = errors.New("unsupported protocol")
|
errUnsupportedProtocol = errors.New("unsupported protocol")
|
||||||
|
@ -32,6 +35,26 @@ var (
|
||||||
|
|
||||||
const nodeBucketName = "nodes"
|
const nodeBucketName = "nodes"
|
||||||
|
|
||||||
|
type P2PServiceInterface interface {
|
||||||
|
SelfConnectionUris() []*url.URL
|
||||||
|
Peers() structs.Map
|
||||||
|
ConnectToNode(connectionUris []*url.URL, retried bool, fromPeer net.Peer) error
|
||||||
|
OnNewPeer(peer net.Peer, verifyId bool) error
|
||||||
|
GetNodeScore(nodeId *encoding.NodeId) (float64, error)
|
||||||
|
SortNodesByScore(nodes []*encoding.NodeId) ([]*encoding.NodeId, error)
|
||||||
|
SignMessageSimple(message []byte) ([]byte, error)
|
||||||
|
AddPeer(peer net.Peer) error
|
||||||
|
SendPublicPeersToPeer(peer net.Peer, peersToSend []net.Peer) error
|
||||||
|
SendHashRequest(hash *encoding.Multihash, kinds []types.StorageLocationType) error
|
||||||
|
UpVote(nodeId *encoding.NodeId) error
|
||||||
|
DownVote(nodeId *encoding.NodeId) error
|
||||||
|
NodeId() *encoding.NodeId
|
||||||
|
WaitOnConnectedPeers()
|
||||||
|
ConnectionTracker() *sync.WaitGroup
|
||||||
|
NetworkId() string
|
||||||
|
HashQueryRoutingTable() structs.Map
|
||||||
|
}
|
||||||
|
|
||||||
type P2PService struct {
|
type P2PService struct {
|
||||||
nodeKeyPair *ed25519.KeyPairEd25519
|
nodeKeyPair *ed25519.KeyPairEd25519
|
||||||
localNodeID *encoding.NodeId
|
localNodeID *encoding.NodeId
|
||||||
|
|
|
@ -18,9 +18,18 @@ import (
|
||||||
const registryBucketName = "registry"
|
const registryBucketName = "registry"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ Service = (*RegistryService)(nil)
|
_ Service = (*RegistryService)(nil)
|
||||||
|
_ RegistryServiceInterface = (*RegistryService)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RegistryServiceInterface interface {
|
||||||
|
Set(sre protocol.SignedRegistryEntry, trusted bool, receivedFrom net.Peer) error
|
||||||
|
BroadcastEntry(sre protocol.SignedRegistryEntry, receivedFrom net.Peer) error
|
||||||
|
SendRegistryRequest(pk []byte) error
|
||||||
|
Get(pk []byte) (protocol.SignedRegistryEntry, error)
|
||||||
|
Listen(pk []byte, cb func(sre protocol.SignedRegistryEntry)) (func(), error)
|
||||||
|
}
|
||||||
|
|
||||||
type RegistryService struct {
|
type RegistryService struct {
|
||||||
streams structs.Map
|
streams structs.Map
|
||||||
subs structs.Map
|
subs structs.Map
|
||||||
|
|
|
@ -13,15 +13,16 @@ type Service interface {
|
||||||
SetServices(services Services)
|
SetServices(services Services)
|
||||||
}
|
}
|
||||||
type Services interface {
|
type Services interface {
|
||||||
P2P() *P2PService
|
P2P() P2PServiceInterface
|
||||||
Registry() *RegistryService
|
Registry() RegistryServiceInterface
|
||||||
HTTP() *HTTPService
|
HTTP() HTTPServiceInterface
|
||||||
Storage() *StorageService
|
Storage() StorageServiceInterface
|
||||||
All() []Service
|
All() []Service
|
||||||
IsStarted() bool
|
IsStarted() bool
|
||||||
Start() error
|
Start() error
|
||||||
Stop() error
|
Stop() error
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServiceParams struct {
|
type ServiceParams struct {
|
||||||
Logger *zap.Logger
|
Logger *zap.Logger
|
||||||
Config *config.NodeConfig
|
Config *config.NodeConfig
|
||||||
|
|
|
@ -20,9 +20,21 @@ import (
|
||||||
const cacheBucketName = "object-cache"
|
const cacheBucketName = "object-cache"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ Service = (*StorageService)(nil)
|
_ Service = (*StorageService)(nil)
|
||||||
|
_ storage.StorageLocationProviderStorageService = (*StorageService)(nil)
|
||||||
|
_ StorageServiceInterface = (*StorageService)(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type StorageServiceInterface interface {
|
||||||
|
SetProviderStore(store storage.ProviderStore)
|
||||||
|
ProviderStore() storage.ProviderStore
|
||||||
|
GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType) (map[string]storage.StorageLocation, error)
|
||||||
|
AddStorageLocation(hash *encoding.Multihash, nodeId *encoding.NodeId, location storage.StorageLocation, message []byte) error
|
||||||
|
DownloadBytesByHash(hash *encoding.Multihash) ([]byte, error)
|
||||||
|
DownloadBytesByCID(cid *encoding.CID) ([]byte, error)
|
||||||
|
GetMetadataByCID(cid *encoding.CID) (metadata.Metadata, error)
|
||||||
|
}
|
||||||
|
|
||||||
type StorageService struct {
|
type StorageService struct {
|
||||||
httpClient *resty.Client
|
httpClient *resty.Client
|
||||||
metadataCache structs.Map
|
metadataCache structs.Map
|
||||||
|
@ -198,7 +210,7 @@ func (s *StorageService) AddStorageLocation(hash *encoding.Multihash, nodeId *en
|
||||||
func (s *StorageService) DownloadBytesByHash(hash *encoding.Multihash) ([]byte, error) {
|
func (s *StorageService) DownloadBytesByHash(hash *encoding.Multihash) ([]byte, error) {
|
||||||
// Initialize the download URI provider
|
// Initialize the download URI provider
|
||||||
dlUriProvider := provider.NewStorageLocationProvider(provider.StorageLocationProviderParams{
|
dlUriProvider := provider.NewStorageLocationProvider(provider.StorageLocationProviderParams{
|
||||||
Services: s.services,
|
Services: storage.NewStorageLocationProviderServices(s.services.P2P(), s.services.Storage()),
|
||||||
Hash: hash,
|
Hash: hash,
|
||||||
LocationTypes: []types.StorageLocationType{
|
LocationTypes: []types.StorageLocationType{
|
||||||
types.StorageLocationTypeFull,
|
types.StorageLocationTypeFull,
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
var _ storage.StorageLocationProvider = (*StorageLocationProviderImpl)(nil)
|
var _ storage.StorageLocationProvider = (*StorageLocationProviderImpl)(nil)
|
||||||
|
|
||||||
type StorageLocationProviderImpl struct {
|
type StorageLocationProviderImpl struct {
|
||||||
services service.Services
|
services storage.StorageLocationProviderServices
|
||||||
hash *encoding.Multihash
|
hash *encoding.Multihash
|
||||||
types []types.StorageLocationType
|
types []types.StorageLocationType
|
||||||
timeoutDuration time.Duration
|
timeoutDuration time.Duration
|
||||||
|
@ -192,7 +192,7 @@ func containsNode(slice []*encoding.NodeId, item *encoding.NodeId) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
type StorageLocationProviderParams struct {
|
type StorageLocationProviderParams struct {
|
||||||
Services service.Services
|
Services storage.StorageLocationProviderServices
|
||||||
Hash *encoding.Multihash
|
Hash *encoding.Multihash
|
||||||
LocationTypes []types.StorageLocationType
|
LocationTypes []types.StorageLocationType
|
||||||
service.ServiceParams
|
service.ServiceParams
|
||||||
|
|
|
@ -3,6 +3,7 @@ package storage
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
"git.lumeweb.com/LumeWeb/libs5-go/encoding"
|
||||||
|
"git.lumeweb.com/LumeWeb/libs5-go/types"
|
||||||
"github.com/vmihailenco/msgpack/v5"
|
"github.com/vmihailenco/msgpack/v5"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
@ -127,3 +128,34 @@ type StorageLocationProvider interface {
|
||||||
Upvote(uri SignedStorageLocation) error
|
Upvote(uri SignedStorageLocation) error
|
||||||
Downvote(uri SignedStorageLocation) error
|
Downvote(uri SignedStorageLocation) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StorageLocationProviderServices interface {
|
||||||
|
P2P() StorageLocationProviderP2PService
|
||||||
|
Storage() StorageLocationProviderStorageService
|
||||||
|
}
|
||||||
|
type StorageLocationProviderP2PService interface {
|
||||||
|
SortNodesByScore(nodes []*encoding.NodeId) ([]*encoding.NodeId, error)
|
||||||
|
SendHashRequest(hash *encoding.Multihash, kinds []types.StorageLocationType) error
|
||||||
|
UpVote(nodeId *encoding.NodeId) error
|
||||||
|
DownVote(nodeId *encoding.NodeId) error
|
||||||
|
}
|
||||||
|
type StorageLocationProviderStorageService interface {
|
||||||
|
GetCachedStorageLocations(hash *encoding.Multihash, kinds []types.StorageLocationType) (map[string]StorageLocation, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type StorageLocationProviderServicesImpl struct {
|
||||||
|
p2p StorageLocationProviderP2PService
|
||||||
|
storage StorageLocationProviderStorageService
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewStorageLocationProviderServices(p2p StorageLocationProviderP2PService, storage StorageLocationProviderStorageService) *StorageLocationProviderServicesImpl {
|
||||||
|
return &StorageLocationProviderServicesImpl{p2p: p2p, storage: storage}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StorageLocationProviderServicesImpl) P2P() StorageLocationProviderP2PService {
|
||||||
|
return s.p2p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StorageLocationProviderServicesImpl) Storage() StorageLocationProviderStorageService {
|
||||||
|
return s.storage
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue