mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 12:16:44 +00:00
add pull cli flag to start swarm download
This commit is contained in:
parent
41c4e97182
commit
75f0248db0
5 changed files with 33 additions and 9 deletions
|
|
@ -178,14 +178,22 @@ func readAll(reader SectionReader, result []byte) {
|
|||
}
|
||||
|
||||
func benchmarkJoinRandomData(n int, chunks int, t *testing.B) {
|
||||
t.StopTimer()
|
||||
for i := 0; i < t.N; i++ {
|
||||
t.StopTimer()
|
||||
// fmt.Printf("round %v\n", i)
|
||||
chunker, tester := chunkerAndTester()
|
||||
key, _ := tester.Split(chunker, n)
|
||||
key, slice := tester.Split(chunker, n)
|
||||
// fmt.Printf("split done %v, joining...\n", i)
|
||||
t.StartTimer()
|
||||
reader := tester.Join(chunker, key, i)
|
||||
// fmt.Printf("join done %v, reading...\n", i)
|
||||
result := make([]byte, n)
|
||||
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
|
||||
PrintVersion bool
|
||||
Peers string
|
||||
Pull string
|
||||
)
|
||||
|
||||
// flags specific to cli client
|
||||
|
|
@ -105,6 +106,7 @@ func Init() {
|
|||
flag.BoolVar(&Dial, "dial", true, "dial out connections (on)")
|
||||
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, "pull", "", "swarm pull key")
|
||||
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(&LogFile, "logfile", "", "log file (defaults to standard output)")
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ func main() {
|
|||
utils.StartWebSockets(ethereum)
|
||||
}
|
||||
|
||||
utils.StartEthereum(ethereum, UseSeed, Peers)
|
||||
utils.StartEthereum(ethereum, UseSeed, Peers, Pull)
|
||||
|
||||
if StartJsConsole {
|
||||
InitJsConsole(ethereum)
|
||||
|
|
|
|||
|
|
@ -120,9 +120,9 @@ func exit(err error) {
|
|||
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())
|
||||
err := ethereum.Start(UseSeed, Peers)
|
||||
err := ethereum.Start(UseSeed, Peers, Pull)
|
||||
if err != nil {
|
||||
exit(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ package eth
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
|
|
@ -70,6 +72,7 @@ type Ethereum struct {
|
|||
|
||||
RpcServer *rpc.JsonRpcServer
|
||||
keyManager *crypto.KeyManager
|
||||
dpa *bzz.DPA
|
||||
|
||||
clientIdentity p2p.ClientIdentity
|
||||
logger ethlogger.LogSystem
|
||||
|
|
@ -144,12 +147,12 @@ func New(config *Config) (*Ethereum, error) {
|
|||
}
|
||||
chunker := &bzz.TreeChunker{}
|
||||
chunker.Init()
|
||||
dpa := &bzz.DPA{
|
||||
eth.dpa = &bzz.DPA{
|
||||
Chunker: chunker,
|
||||
ChunkStore: netStore,
|
||||
}
|
||||
dpa.Start()
|
||||
go bzz.StartHttpServer(dpa)
|
||||
eth.dpa.Start()
|
||||
go bzz.StartHttpServer(eth.dpa)
|
||||
|
||||
nat, err := p2p.ParseNAT(config.NATType, config.PMPGateway)
|
||||
if err != nil {
|
||||
|
|
@ -234,7 +237,7 @@ func (s *Ethereum) MaxPeers() int {
|
|||
}
|
||||
|
||||
// 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()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -264,6 +267,17 @@ func (s *Ethereum) Start(seed bool, p string) error {
|
|||
}
|
||||
}
|
||||
|
||||
if len(pull) > 0 {
|
||||
key := make([]byte, s.dpa.Chunker.KeySize())
|
||||
reader := s.dpa.Retrieve(key)
|
||||
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
|
||||
if seed {
|
||||
logger.Infof("Connect to seed node %v", seedNodeAddress)
|
||||
|
|
|
|||
Loading…
Reference in a new issue