good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
github
maticnetwork
bor
Commits
7f55b0cb
Commit
7f55b0cb
authored
6 years ago
by
holisticode
Committed by
Anton Evangelatov
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
cmd/swarm: hashes command (#19008)
parent
85b3b1c8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
cmd/swarm/explore.go
+59
-0
59 additions, 0 deletions
cmd/swarm/explore.go
cmd/swarm/main.go
+2
-0
2 additions, 0 deletions
cmd/swarm/main.go
swarm/storage/filestore.go
+3
-3
3 additions, 3 deletions
swarm/storage/filestore.go
swarm/storage/filestore_test.go
+7
-11
7 additions, 11 deletions
swarm/storage/filestore_test.go
with
71 additions
and
14 deletions
cmd/swarm/explore.go
0 → 100644
+
59
−
0
View file @
7f55b0cb
// Copyright 2019 The go-ethereum Authors
// This file is part of go-ethereum.
//
// go-ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// go-ethereum 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
// Command bzzhash computes a swarm tree hash.
package
main
import
(
"context"
"fmt"
"os"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/swarm/storage"
"gopkg.in/urfave/cli.v1"
)
var
hashesCommand
=
cli
.
Command
{
Action
:
hashes
,
CustomHelpTemplate
:
helpTemplate
,
Name
:
"hashes"
,
Usage
:
"print all hashes of a file to STDOUT"
,
ArgsUsage
:
"<file>"
,
Description
:
"Prints all hashes of a file to STDOUT"
,
}
func
hashes
(
ctx
*
cli
.
Context
)
{
args
:=
ctx
.
Args
()
if
len
(
args
)
<
1
{
utils
.
Fatalf
(
"Usage: swarm hashes <file name>"
)
}
f
,
err
:=
os
.
Open
(
args
[
0
])
if
err
!=
nil
{
utils
.
Fatalf
(
"Error opening file "
+
args
[
1
])
}
defer
f
.
Close
()
fileStore
:=
storage
.
NewFileStore
(
&
storage
.
FakeChunkStore
{},
storage
.
NewFileStoreParams
())
refs
,
err
:=
fileStore
.
GetAllReferences
(
context
.
TODO
(),
f
,
false
)
if
err
!=
nil
{
utils
.
Fatalf
(
"%v
\n
"
,
err
)
}
else
{
for
_
,
r
:=
range
refs
{
fmt
.
Println
(
r
.
String
())
}
}
}
This diff is collapsed.
Click to expand it.
cmd/swarm/main.go
+
2
−
0
View file @
7f55b0cb
...
...
@@ -142,6 +142,8 @@ func init() {
dbCommand
,
// See config.go
DumpConfigCommand
,
// hashesCommand
hashesCommand
,
}
// append a hidden help subcommand to all commands that have subcommands
...
...
This diff is collapsed.
Click to expand it.
swarm/storage/filestore.go
+
3
−
3
View file @
7f55b0cb
...
...
@@ -75,7 +75,7 @@ func NewFileStore(store ChunkStore, params *FileStoreParams) *FileStore {
}
}
//
P
ublic API. Main entry point for document retrieval directly. Used by the
//
Retrieve is a p
ublic API. Main entry point for document retrieval directly. Used by the
// FS-aware API and httpaccess
// Chunk retrieval blocks on netStore requests with a timeout so reader will
// report error if retrieval of chunks within requested range time out.
...
...
@@ -87,7 +87,7 @@ func (f *FileStore) Retrieve(ctx context.Context, addr Address) (reader *LazyChu
return
}
//
P
ublic API. Main entry point for document storage directly. Used by the
//
Store is a p
ublic API. Main entry point for document storage directly. Used by the
// FS-aware API and httpaccess
func
(
f
*
FileStore
)
Store
(
ctx
context
.
Context
,
data
io
.
Reader
,
size
int64
,
toEncrypt
bool
)
(
addr
Address
,
wait
func
(
context
.
Context
)
error
,
err
error
)
{
putter
:=
NewHasherStore
(
f
.
ChunkStore
,
f
.
hashFunc
,
toEncrypt
)
...
...
@@ -98,7 +98,7 @@ func (f *FileStore) HashSize() int {
return
f
.
hashFunc
()
.
Size
()
}
//
P
ublic API. This endpoint returns all chunk hashes (only) for a given file
//
GetAllReferences is a p
ublic API. This endpoint returns all chunk hashes (only) for a given file
func
(
f
*
FileStore
)
GetAllReferences
(
ctx
context
.
Context
,
data
io
.
Reader
,
toEncrypt
bool
)
(
addrs
AddressCollection
,
err
error
)
{
// create a special kind of putter, which only will store the references
putter
:=
&
HashExplorer
{
...
...
This diff is collapsed.
Click to expand it.
swarm/storage/filestore_test.go
+
7
−
11
View file @
7f55b0cb
...
...
@@ -190,22 +190,18 @@ func TestGetAllReferences(t *testing.T) {
}
fileStore
:=
NewFileStore
(
localStore
,
NewFileStoreParams
())
checkRefs
:=
func
(
dataSize
int
,
expectedLen
int
)
{
slice
:=
testutil
.
RandomBytes
(
1
,
dataSize
)
// testRuns[i] and expectedLen[i] are dataSize and expected length respectively
testRuns
:=
[]
int
{
1024
,
8192
,
16000
,
30000
,
1000000
}
expectedLens
:=
[]
int
{
1
,
3
,
5
,
9
,
248
}
for
i
,
r
:=
range
testRuns
{
slice
:=
testutil
.
RandomBytes
(
1
,
r
)
addrs
,
err
:=
fileStore
.
GetAllReferences
(
context
.
Background
(),
bytes
.
NewReader
(
slice
),
false
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
addrs
)
!=
expectedLen
{
t
.
Fatalf
(
"Expected reference array length to be %d, but is %d"
,
expectedLen
,
len
(
addrs
))
if
len
(
addrs
)
!=
expectedLen
s
[
i
]
{
t
.
Fatalf
(
"Expected reference array length to be %d, but is %d"
,
expectedLen
s
[
i
]
,
len
(
addrs
))
}
}
// testRuns[i] and expectedLen[i] are dataSize and expected length respectively
testRuns
:=
[]
int
{
1024
,
8192
,
16000
,
30000
,
1000000
}
expectedLens
:=
[]
int
{
1
,
3
,
5
,
9
,
248
}
for
i
,
r
:=
range
testRuns
{
checkRefs
(
r
,
expectedLens
[
i
])
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment