Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
5f5d0aa4
Commit
5f5d0aa4
authored
Dec 10, 2016
by
zelig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/swarm: subsume cmd/bzz* as subcommands under swarm
cmd/swarm: subsume cmd/bzz* under cmd/swarm as subcommands
parent
a98e8c08
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
27 deletions
+90
-27
hash.go
cmd/swarm/hash.go
+9
-10
main.go
cmd/swarm/main.go
+68
-3
upload.go
cmd/swarm/upload.go
+13
-14
No files found.
cmd/
bzzhash/main
.go
→
cmd/
swarm/hash
.go
View file @
5f5d0aa4
...
@@ -19,22 +19,21 @@ package main
...
@@ -19,22 +19,21 @@ package main
import
(
import
(
"fmt"
"fmt"
"log"
"os"
"os"
"runtime"
"github.com/ethereum/go-ethereum/swarm/storage"
"github.com/ethereum/go-ethereum/swarm/storage"
"gopkg.in/urfave/cli.v1"
)
)
func
main
()
{
func
hash
(
ctx
*
cli
.
Context
)
{
runtime
.
GOMAXPROCS
(
runtime
.
NumCPU
())
args
:=
ctx
.
Args
()
if
len
(
args
)
<
1
{
if
len
(
os
.
Args
)
<
2
{
log
.
Fatal
(
"Usage: swarm hash <file name>"
)
fmt
.
Println
(
"Usage: bzzhash <file name>"
)
os
.
Exit
(
0
)
}
}
f
,
err
:=
os
.
Open
(
os
.
Args
[
1
])
f
,
err
:=
os
.
Open
(
args
[
0
])
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Println
(
"Error opening file "
+
os
.
A
rgs
[
1
])
fmt
.
Println
(
"Error opening file "
+
a
rgs
[
1
])
os
.
Exit
(
1
)
os
.
Exit
(
1
)
}
}
...
@@ -42,7 +41,7 @@ func main() {
...
@@ -42,7 +41,7 @@ func main() {
chunker
:=
storage
.
NewTreeChunker
(
storage
.
NewChunkerParams
())
chunker
:=
storage
.
NewTreeChunker
(
storage
.
NewChunkerParams
())
key
,
err
:=
chunker
.
Split
(
f
,
stat
.
Size
(),
nil
,
nil
,
nil
)
key
,
err
:=
chunker
.
Split
(
f
,
stat
.
Size
(),
nil
,
nil
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%v
\n
"
,
err
)
log
.
Fatalf
(
"%v
\n
"
,
err
)
}
else
{
}
else
{
fmt
.
Printf
(
"%v
\n
"
,
key
)
fmt
.
Printf
(
"%v
\n
"
,
key
)
}
}
...
...
cmd/
bzzd
/main.go
→
cmd/
swarm
/main.go
View file @
5f5d0aa4
...
@@ -43,11 +43,14 @@ import (
...
@@ -43,11 +43,14 @@ import (
"gopkg.in/urfave/cli.v1"
"gopkg.in/urfave/cli.v1"
)
)
const
clientIdentifier
=
"bzzd"
const
(
clientIdentifier
=
"swarm"
versionString
=
"0.2"
)
var
(
var
(
gitCommit
string
// Git SHA1 commit hash of the release (set via linker flags)
gitCommit
string
// Git SHA1 commit hash of the release (set via linker flags)
app
=
utils
.
NewApp
(
gitCommit
,
"Ethereum Swarm
server daemon
"
)
app
=
utils
.
NewApp
(
gitCommit
,
"Ethereum Swarm"
)
)
)
var
(
var
(
...
@@ -85,6 +88,19 @@ var (
...
@@ -85,6 +88,19 @@ var (
Usage
:
"URL of the Ethereum API provider"
,
Usage
:
"URL of the Ethereum API provider"
,
Value
:
node
.
DefaultIPCEndpoint
(
"geth"
),
Value
:
node
.
DefaultIPCEndpoint
(
"geth"
),
}
}
SwarmApiFlag
=
cli
.
StringFlag
{
Name
:
"bzzapi"
,
Usage
:
"Swarm HTTP endpoint"
,
Value
:
"http://127.0.0.1:8500"
,
}
SwarmRecursiveUploadFlag
=
cli
.
BoolFlag
{
Name
:
"recursive"
,
Usage
:
"Upload directories recursively"
,
}
SwarmWantManifestFlag
=
cli
.
BoolTFlag
{
Name
:
"manifest"
,
Usage
:
"Automatic manifest upload"
,
}
)
)
var
defaultBootnodes
=
[]
string
{}
var
defaultBootnodes
=
[]
string
{}
...
@@ -96,8 +112,39 @@ func init() {
...
@@ -96,8 +112,39 @@ func init() {
utils
.
IPCApiFlag
.
Value
=
"admin, bzz, chequebook, debug, rpc, web3"
utils
.
IPCApiFlag
.
Value
=
"admin, bzz, chequebook, debug, rpc, web3"
// Set up the cli app.
// Set up the cli app.
app
.
Commands
=
nil
app
.
Action
=
bzzd
app
.
Action
=
bzzd
app
.
HideVersion
=
true
// we have a command to print the version
app
.
Copyright
=
"Copyright 2013-2016 The go-ethereum Authors"
app
.
Commands
=
[]
cli
.
Command
{
cli
.
Command
{
Action
:
version
,
Name
:
"version"
,
Usage
:
"Print version numbers"
,
ArgsUsage
:
" "
,
Description
:
`
The output of this command is supposed to be machine-readable.
`
,
},
cli
.
Command
{
Action
:
upload
,
Name
:
"up"
,
Usage
:
"upload a file or directory to swarm using the HTTP API"
,
ArgsUsage
:
" <file>"
,
Description
:
`
"upload a file or directory to swarm using the HTTP API and prints the root hash",
`
,
},
cli
.
Command
{
Action
:
hash
,
Name
:
"hash"
,
Usage
:
"print the swarm hash of a file or directory"
,
ArgsUsage
:
" <file>"
,
Description
:
`
Prints the swarm hash of file or directory.
`
,
},
}
app
.
Flags
=
[]
cli
.
Flag
{
app
.
Flags
=
[]
cli
.
Flag
{
utils
.
IdentityFlag
,
utils
.
IdentityFlag
,
utils
.
DataDirFlag
,
utils
.
DataDirFlag
,
...
@@ -123,6 +170,10 @@ func init() {
...
@@ -123,6 +170,10 @@ func init() {
SwarmAccountFlag
,
SwarmAccountFlag
,
SwarmNetworkIdFlag
,
SwarmNetworkIdFlag
,
ChequebookAddrFlag
,
ChequebookAddrFlag
,
// upload flags
SwarmApiFlag
,
SwarmRecursiveUploadFlag
,
SwarmWantManifestFlag
,
}
}
app
.
Flags
=
append
(
app
.
Flags
,
debug
.
Flags
...
)
app
.
Flags
=
append
(
app
.
Flags
,
debug
.
Flags
...
)
app
.
Before
=
func
(
ctx
*
cli
.
Context
)
error
{
app
.
Before
=
func
(
ctx
*
cli
.
Context
)
error
{
...
@@ -142,6 +193,20 @@ func main() {
...
@@ -142,6 +193,20 @@ func main() {
}
}
}
}
func
version
(
ctx
*
cli
.
Context
)
error
{
fmt
.
Println
(
strings
.
Title
(
clientIdentifier
))
fmt
.
Println
(
"Version:"
,
versionString
)
if
gitCommit
!=
""
{
fmt
.
Println
(
"Git Commit:"
,
gitCommit
)
}
fmt
.
Println
(
"Network Id:"
,
ctx
.
GlobalInt
(
utils
.
NetworkIdFlag
.
Name
))
fmt
.
Println
(
"Go Version:"
,
runtime
.
Version
())
fmt
.
Println
(
"OS:"
,
runtime
.
GOOS
)
fmt
.
Printf
(
"GOPATH=%s
\n
"
,
os
.
Getenv
(
"GOPATH"
))
fmt
.
Printf
(
"GOROOT=%s
\n
"
,
runtime
.
GOROOT
())
return
nil
}
func
bzzd
(
ctx
*
cli
.
Context
)
error
{
func
bzzd
(
ctx
*
cli
.
Context
)
error
{
stack
:=
utils
.
MakeNode
(
ctx
,
clientIdentifier
,
gitCommit
)
stack
:=
utils
.
MakeNode
(
ctx
,
clientIdentifier
,
gitCommit
)
registerBzzService
(
ctx
,
stack
)
registerBzzService
(
ctx
,
stack
)
...
...
cmd/
bzzup/main
.go
→
cmd/
swarm/upload
.go
View file @
5f5d0aa4
...
@@ -20,7 +20,6 @@ package main
...
@@ -20,7 +20,6 @@ package main
import
(
import
(
"bytes"
"bytes"
"encoding/json"
"encoding/json"
"flag"
"fmt"
"fmt"
"io"
"io"
"io/ioutil"
"io/ioutil"
...
@@ -30,24 +29,24 @@ import (
...
@@ -30,24 +29,24 @@ import (
"os"
"os"
"path/filepath"
"path/filepath"
"strings"
"strings"
"gopkg.in/urfave/cli.v1"
)
)
func
main
()
{
func
upload
(
ctx
*
cli
.
Context
)
{
args
:=
ctx
.
Args
()
var
(
var
(
bzzapi
Flag
=
flag
.
String
(
"bzzapi"
,
"http://127.0.0.1:8500"
,
"Swarm HTTP endpoint"
)
bzzapi
=
ctx
.
GlobalString
(
SwarmApiFlag
.
Name
)
recursive
Flag
=
flag
.
Bool
(
"recursive"
,
false
,
"Upload directories recursively"
)
recursive
=
ctx
.
GlobalBool
(
SwarmRecursiveUploadFlag
.
Name
)
manifestFlag
=
flag
.
Bool
(
"manifest"
,
true
,
"Skip automatic manifest upload"
)
wantManifest
=
ctx
.
GlobalBoolT
(
SwarmWantManifestFlag
.
Name
)
)
)
log
.
SetOutput
(
os
.
Stderr
)
if
len
(
args
)
!=
1
{
log
.
SetFlags
(
0
)
flag
.
Parse
()
if
flag
.
NArg
()
!=
1
{
log
.
Fatal
(
"need filename as the first and only argument"
)
log
.
Fatal
(
"need filename as the first and only argument"
)
}
}
var
(
var
(
file
=
flag
.
Arg
(
0
)
file
=
args
[
0
]
client
=
&
client
{
api
:
*
bzzapiFlag
}
client
=
&
client
{
api
:
bzzapi
}
mroot
manifest
mroot
manifest
)
)
fi
,
err
:=
os
.
Stat
(
file
)
fi
,
err
:=
os
.
Stat
(
file
)
...
@@ -55,13 +54,13 @@ func main() {
...
@@ -55,13 +54,13 @@ func main() {
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
if
fi
.
IsDir
()
{
if
fi
.
IsDir
()
{
if
!
*
recursiveFlag
{
if
!
recursive
{
log
.
Fatal
(
"argument is a directory and recursive upload is disabled"
)
log
.
Fatal
(
"argument is a directory and recursive upload is disabled"
)
}
}
mroot
,
err
=
client
.
uploadDirectory
(
file
)
mroot
,
err
=
client
.
uploadDirectory
(
file
)
}
else
{
}
else
{
mroot
,
err
=
client
.
uploadFile
(
file
,
fi
)
mroot
,
err
=
client
.
uploadFile
(
file
,
fi
)
if
*
manifestFlag
{
if
wantManifest
{
// Wrap the raw file entry in a proper manifest so both hashes get printed.
// Wrap the raw file entry in a proper manifest so both hashes get printed.
mroot
=
manifest
{
Entries
:
[]
manifest
{
mroot
}}
mroot
=
manifest
{
Entries
:
[]
manifest
{
mroot
}}
}
}
...
@@ -69,7 +68,7 @@ func main() {
...
@@ -69,7 +68,7 @@ func main() {
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalln
(
"upload failed:"
,
err
)
log
.
Fatalln
(
"upload failed:"
,
err
)
}
}
if
*
manifestFlag
{
if
wantManifest
{
hash
,
err
:=
client
.
uploadManifest
(
mroot
)
hash
,
err
:=
client
.
uploadManifest
(
mroot
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatalln
(
"manifest upload failed:"
,
err
)
log
.
Fatalln
(
"manifest upload failed:"
,
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment