From 52ecb3e0edde940bf645035a6781e3577f9e723a Mon Sep 17 00:00:00 2001 From: Andrenerd Date: Sun, 2 May 2021 23:36:25 +0200 Subject: [PATCH 1/6] add geolocation fields to the config --- code/go/0chain.net/blobbercore/config/config.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/code/go/0chain.net/blobbercore/config/config.go b/code/go/0chain.net/blobbercore/config/config.go index bf95a8d8f..d651338e5 100644 --- a/code/go/0chain.net/blobbercore/config/config.go +++ b/code/go/0chain.net/blobbercore/config/config.go @@ -63,6 +63,12 @@ const ( DeploymentMainNet = 2 ) +type GeolocationConfig struct { + Latitude float64 `mapstructure:"latitude"` + Longitude float64 `mapstructure:"longitude"` + // reserved / Accuracy float64 `mapstructure:"accuracy"` +} + type Config struct { *config.Config DBHost string @@ -118,6 +124,8 @@ type Config struct { NumDelegates int `json:"num_delegates"` // ServiceCharge for blobber. ServiceCharge float64 `json:"service_charge"` + + Geolocation GeolocationConfig `mapstructure:"geolocation"` } /*Configuration of the system */ From b56d049f2bcfb7e6ab0b5b8ef64da5c9f1f6b578 Mon Sep 17 00:00:00 2001 From: Andrenerd Date: Tue, 25 May 2021 06:20:02 +0200 Subject: [PATCH 2/6] add geeolocation properties --- .../blobbercore/handler/protocol.go | 1 + .../blobbercore/readmarker/entity.go | 1 - code/go/0chain.net/core/transaction/entity.go | 20 +++++++++++++------ config/0chain_blobber.yaml | 4 ++++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/code/go/0chain.net/blobbercore/handler/protocol.go b/code/go/0chain.net/blobbercore/handler/protocol.go index 9a4bfa9e8..64b171848 100644 --- a/code/go/0chain.net/blobbercore/handler/protocol.go +++ b/code/go/0chain.net/blobbercore/handler/protocol.go @@ -151,6 +151,7 @@ func getStorageNode() (*transaction.StorageNode, error) { sn := &transaction.StorageNode{} sn.ID = node.Self.ID sn.BaseURL = node.Self.GetURLBase() + sn.Geolocation = config.Configuration.Geolocation sn.Capacity = config.Configuration.Capacity readPrice := config.Configuration.ReadPrice writePrice := config.Configuration.WritePrice diff --git a/code/go/0chain.net/blobbercore/readmarker/entity.go b/code/go/0chain.net/blobbercore/readmarker/entity.go index be13cd12c..f816554e3 100644 --- a/code/go/0chain.net/blobbercore/readmarker/entity.go +++ b/code/go/0chain.net/blobbercore/readmarker/entity.go @@ -106,7 +106,6 @@ func GetLatestReadMarkerEntity(ctx context.Context, clientID string) (*ReadMarke } func SaveLatestReadMarker(ctx context.Context, rm *ReadMarker, isCreate bool) error { - var ( db = datastore.GetStore().GetTransaction(ctx) rmEntity = &ReadMarkerEntity{} diff --git a/code/go/0chain.net/core/transaction/entity.go b/code/go/0chain.net/core/transaction/entity.go index 72f8eabe5..e84f19321 100644 --- a/code/go/0chain.net/core/transaction/entity.go +++ b/code/go/0chain.net/core/transaction/entity.go @@ -68,13 +68,21 @@ type StakePoolSettings struct { ServiceCharge float64 `json:"service_charge"` } +// Move to the core one day +type StorageNodeGeolocation struct { + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + // reserved / Accuracy float64 `mapstructure:"accuracy"` +} + type StorageNode struct { - ID string `json:"id"` - BaseURL string `json:"url"` - Terms Terms `json:"terms"` - Capacity int64 `json:"capacity"` - PublicKey string `json:"-"` - StakePoolSettings StakePoolSettings `json:"stake_pool_settings"` + ID string `json:"id"` + BaseURL string `json:"url"` + Geolocation StorageNodeGeolocation `json:"geolocation"` + Terms Terms `json:"terms"` + Capacity int64 `json:"capacity"` + PublicKey string `json:"-"` + StakePoolSettings StakePoolSettings `json:"stake_pool_settings"` } type BlobberAllocation struct { diff --git a/config/0chain_blobber.yaml b/config/0chain_blobber.yaml index b43b2502d..c084f4821 100755 --- a/config/0chain_blobber.yaml +++ b/config/0chain_blobber.yaml @@ -87,6 +87,10 @@ db: host: postgres port: 5432 +geolocation: + latitude: 0 + longitude: 0 + minio: # Enable or disable minio backup service start: false From ed0ec93e24b09b799b79cb5960182176e5cd92bc Mon Sep 17 00:00:00 2001 From: Andrenerd Date: Mon, 7 Jun 2021 06:01:36 +0200 Subject: [PATCH 3/6] add geolocation validation --- code/go/0chain.net/blobbercore/config/config.go | 11 +++++++++++ code/go/0chain.net/blobbercore/handler/protocol.go | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/code/go/0chain.net/blobbercore/config/config.go b/code/go/0chain.net/blobbercore/config/config.go index d651338e5..f81805cca 100644 --- a/code/go/0chain.net/blobbercore/config/config.go +++ b/code/go/0chain.net/blobbercore/config/config.go @@ -141,6 +141,17 @@ func Development() bool { return Configuration.DeploymentMode == DeploymentDevelopment } +// get validated geolocatiion +func Geolocation() GeolocationConfig { + g := Configuration.Geolocation + if g.Latitude > 90.00 || g.Latitude < -90.00 || + g.Longitude > 180.00 || g.Longitude < -180.00 { + g.Latitude = float64(0.00) + g.Longitude = float64(0.00) + } + return g +} + /*ErrSupportedChain error for indicating which chain is supported by the server */ var ErrSupportedChain error diff --git a/code/go/0chain.net/blobbercore/handler/protocol.go b/code/go/0chain.net/blobbercore/handler/protocol.go index 64b171848..ddaf45315 100644 --- a/code/go/0chain.net/blobbercore/handler/protocol.go +++ b/code/go/0chain.net/blobbercore/handler/protocol.go @@ -151,7 +151,7 @@ func getStorageNode() (*transaction.StorageNode, error) { sn := &transaction.StorageNode{} sn.ID = node.Self.ID sn.BaseURL = node.Self.GetURLBase() - sn.Geolocation = config.Configuration.Geolocation + sn.Geolocation = config.Geolocation() sn.Capacity = config.Configuration.Capacity readPrice := config.Configuration.ReadPrice writePrice := config.Configuration.WritePrice From f86aeeb0ad6c0a890f0221ab746851958614eeee Mon Sep 17 00:00:00 2001 From: Andrenerd Date: Wed, 9 Jun 2021 01:39:16 +0200 Subject: [PATCH 4/6] fixes --- code/go/0chain.net/blobbercore/config/config.go | 4 ++-- code/go/0chain.net/blobbercore/handler/protocol.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/code/go/0chain.net/blobbercore/config/config.go b/code/go/0chain.net/blobbercore/config/config.go index f81805cca..172968905 100644 --- a/code/go/0chain.net/blobbercore/config/config.go +++ b/code/go/0chain.net/blobbercore/config/config.go @@ -146,8 +146,8 @@ func Geolocation() GeolocationConfig { g := Configuration.Geolocation if g.Latitude > 90.00 || g.Latitude < -90.00 || g.Longitude > 180.00 || g.Longitude < -180.00 { - g.Latitude = float64(0.00) - g.Longitude = float64(0.00) + panic("Fatal error in config file") + } return g } diff --git a/code/go/0chain.net/blobbercore/handler/protocol.go b/code/go/0chain.net/blobbercore/handler/protocol.go index ddaf45315..b19c42d8a 100644 --- a/code/go/0chain.net/blobbercore/handler/protocol.go +++ b/code/go/0chain.net/blobbercore/handler/protocol.go @@ -151,7 +151,7 @@ func getStorageNode() (*transaction.StorageNode, error) { sn := &transaction.StorageNode{} sn.ID = node.Self.ID sn.BaseURL = node.Self.GetURLBase() - sn.Geolocation = config.Geolocation() + sn.Geolocation = transaction.StorageNodeGeolocation(config.Geolocation()) sn.Capacity = config.Configuration.Capacity readPrice := config.Configuration.ReadPrice writePrice := config.Configuration.WritePrice From e92275f7fe3261e2befa65941690c94879c33280 Mon Sep 17 00:00:00 2001 From: Andrei Vasin <3892914+andrenerd@users.noreply.github.com> Date: Thu, 10 Jun 2021 01:46:10 +0200 Subject: [PATCH 5/6] Update entity.go --- code/go/0chain.net/core/transaction/entity.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/code/go/0chain.net/core/transaction/entity.go b/code/go/0chain.net/core/transaction/entity.go index e84f19321..0f17ae06e 100644 --- a/code/go/0chain.net/core/transaction/entity.go +++ b/code/go/0chain.net/core/transaction/entity.go @@ -68,11 +68,9 @@ type StakePoolSettings struct { ServiceCharge float64 `json:"service_charge"` } -// Move to the core one day type StorageNodeGeolocation struct { Latitude float64 `json:"latitude"` Longitude float64 `json:"longitude"` - // reserved / Accuracy float64 `mapstructure:"accuracy"` } type StorageNode struct { From 2509a567d3541c3d6c80a8fdc4606a3f5f02ba33 Mon Sep 17 00:00:00 2001 From: Andrei Vasin <3892914+andrenerd@users.noreply.github.com> Date: Thu, 10 Jun 2021 01:46:55 +0200 Subject: [PATCH 6/6] Update config.go --- code/go/0chain.net/blobbercore/config/config.go | 1 - 1 file changed, 1 deletion(-) diff --git a/code/go/0chain.net/blobbercore/config/config.go b/code/go/0chain.net/blobbercore/config/config.go index 172968905..2830bda9d 100644 --- a/code/go/0chain.net/blobbercore/config/config.go +++ b/code/go/0chain.net/blobbercore/config/config.go @@ -66,7 +66,6 @@ const ( type GeolocationConfig struct { Latitude float64 `mapstructure:"latitude"` Longitude float64 `mapstructure:"longitude"` - // reserved / Accuracy float64 `mapstructure:"accuracy"` } type Config struct {