From 996755c4a832afce8629a771cab8879c88c98355 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jano=C5=A1=20Gulja=C5=A1?= Date: Wed, 10 Apr 2019 16:50:58 +0200 Subject: cmd/swarm, swarm: LocalStore storage integration --- swarm/chunk/chunk.go | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) (limited to 'swarm/chunk/chunk.go') diff --git a/swarm/chunk/chunk.go b/swarm/chunk/chunk.go index 7540af8ce..c8551814c 100644 --- a/swarm/chunk/chunk.go +++ b/swarm/chunk/chunk.go @@ -1,6 +1,7 @@ package chunk import ( + "context" "errors" "fmt" @@ -28,7 +29,7 @@ type chunk struct { sdata []byte } -func NewChunk(addr Address, data []byte) *chunk { +func NewChunk(addr Address, data []byte) Chunk { return &chunk{ addr: addr, sdata: data, @@ -107,3 +108,105 @@ func Proximity(one, other []byte) (ret int) { } return MaxPO } + +// ModeGet enumerates different Getter modes. +type ModeGet int + +// Getter modes. +const ( + // ModeGetRequest: when accessed for retrieval + ModeGetRequest ModeGet = iota + // ModeGetSync: when accessed for syncing or proof of custody request + ModeGetSync + // ModeGetLookup: when accessed to lookup a a chunk in feeds or other places + ModeGetLookup +) + +// ModePut enumerates different Putter modes. +type ModePut int + +// Putter modes. +const ( + // ModePutRequest: when a chunk is received as a result of retrieve request and delivery + ModePutRequest ModePut = iota + // ModePutSync: when a chunk is received via syncing + ModePutSync + // ModePutUpload: when a chunk is created by local upload + ModePutUpload +) + +// ModeSet enumerates different Setter modes. +type ModeSet int + +// Setter modes. +const ( + // ModeSetAccess: when an update request is received for a chunk or chunk is retrieved for delivery + ModeSetAccess ModeSet = iota + // ModeSetSync: when push sync receipt is received + ModeSetSync + // ModeSetRemove: when a chunk is removed + ModeSetRemove +) + +// Descriptor holds information required for Pull syncing. This struct +// is provided by subscribing to pull index. +type Descriptor struct { + Address Address + BinID uint64 +} + +func (d *Descriptor) String() string { + if d == nil { + return "" + } + return fmt.Sprintf("%s bin id %v", d.Address.Hex(), d.BinID) +} + +type Store interface { + Get(ctx context.Context, mode ModeGet, addr Address) (ch Chunk, err error) + Put(ctx context.Context, mode ModePut, ch Chunk) (exists bool, err error) + Has(ctx context.Context, addr Address) (yes bool, err error) + Set(ctx context.Context, mode ModeSet, addr Address) (err error) + LastPullSubscriptionBinID(bin uint8) (id uint64, err error) + SubscribePull(ctx context.Context, bin uint8, since, until uint64) (c <-chan Descriptor, stop func()) + Close() (err error) +} + +// FetchStore is a Store which supports syncing +type FetchStore interface { + Store + FetchFunc(ctx context.Context, addr Address) func(context.Context) error +} + +// Validator validates a chunk. +type Validator interface { + Validate(ch Chunk) bool +} + +// ValidatorStore encapsulates Store by decorting the Put method +// with validators check. +type ValidatorStore struct { + Store + validators []Validator +} + +// NewValidatorStore returns a new ValidatorStore which uses +// provided validators to validate chunks on Put. +func NewValidatorStore(store Store, validators ...Validator) (s *ValidatorStore) { + return &ValidatorStore{ + Store: store, + validators: validators, + } +} + +// Put overrides Store put method with validators check. If one of the validators +// return true, the chunk is considered valid and Store Put method is called. +// If all validators return false, ErrChunkInvalid is returned. +func (s *ValidatorStore) Put(ctx context.Context, mode ModePut, ch Chunk) (exists bool, err error) { + for _, v := range s.validators { + if v.Validate(ch) { + return s.Store.Put(ctx, mode, ch) + } + } + return false, ErrChunkInvalid +} -- cgit v1.2.3 From 993b145f25845e50e8af41ffb1116eaee381d693 Mon Sep 17 00:00:00 2001 From: Anton Evangelatov Date: Thu, 11 Apr 2019 10:26:52 +0200 Subject: swarm/storage/localstore: fix export db.Put signature cmd/swarm/swarm-smoke: improve smoke tests (#1337) swarm/network: remove dead code (#1339) swarm/network: remove FetchStore and SyncChunkStore in favor of NetStore (#1342) --- swarm/chunk/chunk.go | 6 ------ 1 file changed, 6 deletions(-) (limited to 'swarm/chunk/chunk.go') diff --git a/swarm/chunk/chunk.go b/swarm/chunk/chunk.go index c8551814c..2455904f3 100644 --- a/swarm/chunk/chunk.go +++ b/swarm/chunk/chunk.go @@ -172,12 +172,6 @@ type Store interface { Close() (err error) } -// FetchStore is a Store which supports syncing -type FetchStore interface { - Store - FetchFunc(ctx context.Context, addr Address) func(context.Context) error -} - // Validator validates a chunk. type Validator interface { Validate(ch Chunk) bool -- cgit v1.2.3 From c1213bd00c2a84a9dfc218e44cc2f85902f91128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jano=C5=A1=20Gulja=C5=A1?= Date: Thu, 25 Apr 2019 10:22:57 +0200 Subject: swarm: LocalStore metrics * swarm/shed: remove metrics fields from DB struct * swarm/schunk: add String methods to modes * swarm/storage/localstore: add metrics and traces * swarm/chunk: unknown modes without spaces in String methods * swarm/storage/localstore: remove bin number from pull subscription metrics * swarm/storage/localstore: add resetting time metrics and code improvements --- swarm/chunk/chunk.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'swarm/chunk/chunk.go') diff --git a/swarm/chunk/chunk.go b/swarm/chunk/chunk.go index 2455904f3..9ae59c95f 100644 --- a/swarm/chunk/chunk.go +++ b/swarm/chunk/chunk.go @@ -112,6 +112,19 @@ func Proximity(one, other []byte) (ret int) { // ModeGet enumerates different Getter modes. type ModeGet int +func (m ModeGet) String() string { + switch m { + case ModeGetRequest: + return "Request" + case ModeGetSync: + return "Sync" + case ModeGetLookup: + return "Lookup" + default: + return "Unknown" + } +} + // Getter modes. const ( // ModeGetRequest: when accessed for retrieval @@ -125,6 +138,19 @@ const ( // ModePut enumerates different Putter modes. type ModePut int +func (m ModePut) String() string { + switch m { + case ModePutRequest: + return "Request" + case ModePutSync: + return "Sync" + case ModePutUpload: + return "Upload" + default: + return "Unknown" + } +} + // Putter modes. const ( // ModePutRequest: when a chunk is received as a result of retrieve request and delivery @@ -138,6 +164,19 @@ const ( // ModeSet enumerates different Setter modes. type ModeSet int +func (m ModeSet) String() string { + switch m { + case ModeSetAccess: + return "Access" + case ModeSetSync: + return "Sync" + case ModeSetRemove: + return "Remove" + default: + return "Unknown" + } +} + // Setter modes. const ( // ModeSetAccess: when an update request is received for a chunk or chunk is retrieved for delivery -- cgit v1.2.3 From 12240baf61e251a80e3759dd22ca5847dcb8d807 Mon Sep 17 00:00:00 2001 From: Elad Date: Tue, 30 Apr 2019 13:10:57 +0900 Subject: swarm/chunk: add tags data type * swarm/chunk: add tags backend to chunk package --- swarm/chunk/chunk.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'swarm/chunk/chunk.go') diff --git a/swarm/chunk/chunk.go b/swarm/chunk/chunk.go index 9ae59c95f..17f49348b 100644 --- a/swarm/chunk/chunk.go +++ b/swarm/chunk/chunk.go @@ -1,3 +1,19 @@ +// Copyright 2019 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + package chunk import ( -- cgit v1.2.3 From 84dfaea246dea179319db90a63afc1189cd09246 Mon Sep 17 00:00:00 2001 From: Elad Date: Thu, 9 May 2019 12:54:06 +0400 Subject: swarm: instrument setNextBatch swarm/storage/localstore: add gc metrics, disable flaky test --- swarm/chunk/chunk.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'swarm/chunk/chunk.go') diff --git a/swarm/chunk/chunk.go b/swarm/chunk/chunk.go index 17f49348b..c44292bb9 100644 --- a/swarm/chunk/chunk.go +++ b/swarm/chunk/chunk.go @@ -197,7 +197,7 @@ func (m ModeSet) String() string { const ( // ModeSetAccess: when an update request is received for a chunk or chunk is retrieved for delivery ModeSetAccess ModeSet = iota - // ModeSetSync: when push sync receipt is received + // ModeSetSync: when a chunk is added to a pull sync batch or when a push sync receipt is received ModeSetSync // ModeSetRemove: when a chunk is removed ModeSetRemove -- cgit v1.2.3