mirror of
https://github.com/PeernetOfficial/core.git
synced 2026-07-17 02:47:51 +01:00
Global Blockchain Cache implementation. Automatically download other blockchains based on the limits in the config.
Started with a unified backend struct. Long term all lose vars should be put there, which in term will support multiple concurrent Peernet instances (users) within the same process.
This commit is contained in:
18
Peernet.go
18
Peernet.go
@@ -10,7 +10,7 @@ var userAgent = "Peernet Core/0.1" // must be overwritten by the caller
|
||||
|
||||
// Init initializes the client. The config must be loaded first!
|
||||
// The User Agent must be provided in the form "Application Name/1.0".
|
||||
func Init(UserAgent string) {
|
||||
func Init(UserAgent string) (backend *Backend) {
|
||||
if userAgent = UserAgent; userAgent == "" {
|
||||
return
|
||||
}
|
||||
@@ -26,6 +26,13 @@ func Init(UserAgent string) {
|
||||
initBroadcastIPv4()
|
||||
initStore()
|
||||
initNetwork()
|
||||
|
||||
backend = &Backend{}
|
||||
backend.GlobalBlockchainCache = initBlockchainCache(config.BlockchainGlobal, config.CacheMaxBlockSize, config.CacheMaxBlockCount, config.LimitTotalRecords)
|
||||
|
||||
currentBackend = backend
|
||||
|
||||
return backend
|
||||
}
|
||||
|
||||
// Connect starts bootstrapping and local peer discovery.
|
||||
@@ -38,3 +45,12 @@ func Connect() {
|
||||
go networks.startUPnP()
|
||||
go autoBucketRefresh()
|
||||
}
|
||||
|
||||
// The Backend represents an instance of a Peernet client to be used by a frontend.
|
||||
// Global variables and init functions are to be merged.
|
||||
type Backend struct {
|
||||
GlobalBlockchainCache *BlockchainCache // stores other peers blockchains
|
||||
}
|
||||
|
||||
// This variable is to be replaced later by pointers in structures.
|
||||
var currentBackend *Backend
|
||||
|
||||
Reference in New Issue
Block a user