mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
add pull cli flag to start swarm download
This commit is contained in:
parent
41c4e97182
commit
706f3eddad
5 changed files with 32 additions and 9 deletions
|
|
@ -178,14 +178,22 @@ func readAll(reader SectionReader, result []byte) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func benchmarkJoinRandomData(n int, chunks int, t *testing.B) {
|
func benchmarkJoinRandomData(n int, chunks int, t *testing.B) {
|
||||||
for i := 0; i < t.N; i++ {
|
|
||||||
t.StopTimer()
|
t.StopTimer()
|
||||||
|
for i := 0; i < t.N; i++ {
|
||||||
|
// fmt.Printf("round %v\n", i)
|
||||||
chunker, tester := chunkerAndTester()
|
chunker, tester := chunkerAndTester()
|
||||||
key, _ := tester.Split(chunker, n)
|
key, slice := tester.Split(chunker, n)
|
||||||
|
// fmt.Printf("split done %v, joining...\n", i)
|
||||||
t.StartTimer()
|
t.StartTimer()
|
||||||
reader := tester.Join(chunker, key, i)
|
reader := tester.Join(chunker, key, i)
|
||||||
|
// fmt.Printf("join done %v, reading...\n", i)
|
||||||
result := make([]byte, n)
|
result := make([]byte, n)
|
||||||
readAll(reader, result)
|
readAll(reader, result)
|
||||||
|
// fmt.Printf("read done %v\n", i)
|
||||||
|
t.StopTimer()
|
||||||
|
if !bytes.Equal(slice, result) {
|
||||||
|
t.Errorf("input output mismatch")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ var (
|
||||||
Dial bool
|
Dial bool
|
||||||
PrintVersion bool
|
PrintVersion bool
|
||||||
Peers string
|
Peers string
|
||||||
|
Pull string
|
||||||
)
|
)
|
||||||
|
|
||||||
// flags specific to cli client
|
// flags specific to cli client
|
||||||
|
|
@ -105,6 +106,7 @@ func Init() {
|
||||||
flag.BoolVar(&Dial, "dial", true, "dial out connections (on)")
|
flag.BoolVar(&Dial, "dial", true, "dial out connections (on)")
|
||||||
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
|
||||||
flag.StringVar(&Peers, "peers", "", "imports the file given (hex or mnemonic formats)")
|
flag.StringVar(&Peers, "peers", "", "imports the file given (hex or mnemonic formats)")
|
||||||
|
flag.StringVar(&Pull, "pull", "", "swarm pull key")
|
||||||
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
|
||||||
flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
|
flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
|
||||||
flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
|
flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ func main() {
|
||||||
utils.StartWebSockets(ethereum)
|
utils.StartWebSockets(ethereum)
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.StartEthereum(ethereum, UseSeed, Peers)
|
utils.StartEthereum(ethereum, UseSeed, Peers, Pull)
|
||||||
|
|
||||||
if StartJsConsole {
|
if StartJsConsole {
|
||||||
InitJsConsole(ethereum)
|
InitJsConsole(ethereum)
|
||||||
|
|
|
||||||
|
|
@ -120,9 +120,9 @@ func exit(err error) {
|
||||||
os.Exit(status)
|
os.Exit(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartEthereum(ethereum *eth.Ethereum, UseSeed bool, Peers string) {
|
func StartEthereum(ethereum *eth.Ethereum, UseSeed bool, Peers string, Pull string) {
|
||||||
clilogger.Infof("Starting %s", ethereum.ClientIdentity())
|
clilogger.Infof("Starting %s", ethereum.ClientIdentity())
|
||||||
err := ethereum.Start(UseSeed, Peers)
|
err := ethereum.Start(UseSeed, Peers, Pull)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exit(err)
|
exit(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@ package eth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
|
@ -70,6 +72,7 @@ type Ethereum struct {
|
||||||
|
|
||||||
RpcServer *rpc.JsonRpcServer
|
RpcServer *rpc.JsonRpcServer
|
||||||
keyManager *crypto.KeyManager
|
keyManager *crypto.KeyManager
|
||||||
|
dpa *bzz.DPA
|
||||||
|
|
||||||
clientIdentity p2p.ClientIdentity
|
clientIdentity p2p.ClientIdentity
|
||||||
logger ethlogger.LogSystem
|
logger ethlogger.LogSystem
|
||||||
|
|
@ -144,12 +147,12 @@ func New(config *Config) (*Ethereum, error) {
|
||||||
}
|
}
|
||||||
chunker := &bzz.TreeChunker{}
|
chunker := &bzz.TreeChunker{}
|
||||||
chunker.Init()
|
chunker.Init()
|
||||||
dpa := &bzz.DPA{
|
eth.dpa = &bzz.DPA{
|
||||||
Chunker: chunker,
|
Chunker: chunker,
|
||||||
ChunkStore: netStore,
|
ChunkStore: netStore,
|
||||||
}
|
}
|
||||||
dpa.Start()
|
eth.dpa.Start()
|
||||||
go bzz.StartHttpServer(dpa)
|
go bzz.StartHttpServer(eth.dpa)
|
||||||
|
|
||||||
nat, err := p2p.ParseNAT(config.NATType, config.PMPGateway)
|
nat, err := p2p.ParseNAT(config.NATType, config.PMPGateway)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -234,7 +237,7 @@ func (s *Ethereum) MaxPeers() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the ethereum
|
// Start the ethereum
|
||||||
func (s *Ethereum) Start(seed bool, p string) error {
|
func (s *Ethereum) Start(seed bool, p string, pull string) error {
|
||||||
err := s.net.Start()
|
err := s.net.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -264,6 +267,16 @@ func (s *Ethereum) Start(seed bool, p string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(pull) > 0 {
|
||||||
|
reader := s.dpa.Retrieve(pull)
|
||||||
|
fo, err := os.Open("/tmp/swarm.tmp")
|
||||||
|
if err != nil {
|
||||||
|
logger.Warnf("file open error %v", err)
|
||||||
|
} else {
|
||||||
|
io.Copy(fo, reader)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: read peers here
|
// TODO: read peers here
|
||||||
if seed {
|
if seed {
|
||||||
logger.Infof("Connect to seed node %v", seedNodeAddress)
|
logger.Infof("Connect to seed node %v", seedNodeAddress)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue