diff --git a/bzz/protocol.go b/bzz/protocol.go index a298370a25..9b26d4331e 100644 --- a/bzz/protocol.go +++ b/bzz/protocol.go @@ -209,6 +209,9 @@ func (self *bzzProtocol) handle() error { return self.protoError(ErrDecode, "->msg %v: %v", msg, err) } dpaLogger.Warnf("Request message: %#v", req) + if req.Key == nil || req.Timeout == nil { + return self.protoError(ErrDecode, "protocol handler: req.Key == nil || req.Timeout == nil") + } req.peer = peer{bzzProtocol: self} self.netStore.addRetrieveRequest(&req) diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go index f829744dc9..d69ea5cfb6 100644 --- a/cmd/ethereum/flags.go +++ b/cmd/ethereum/flags.go @@ -65,6 +65,7 @@ var ( SHH bool Dial bool PrintVersion bool + Peers string ) // flags specific to cli client @@ -103,6 +104,7 @@ func Init() { flag.BoolVar(&SHH, "shh", true, "whisper protocol (on)") 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(&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)") diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index b816c678e7..ea53b9a304 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -134,7 +134,7 @@ func main() { utils.StartWebSockets(ethereum) } - utils.StartEthereum(ethereum, UseSeed) + utils.StartEthereum(ethereum, UseSeed, Peers) if StartJsConsole { InitJsConsole(ethereum) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index a57d3266f1..06e3fb93f1 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -120,9 +120,9 @@ func exit(err error) { os.Exit(status) } -func StartEthereum(ethereum *eth.Ethereum, UseSeed bool) { +func StartEthereum(ethereum *eth.Ethereum, UseSeed bool, Peers string) { clilogger.Infof("Starting %s", ethereum.ClientIdentity()) - err := ethereum.Start(UseSeed) + err := ethereum.Start(UseSeed, Peers) if err != nil { exit(err) } diff --git a/eth/backend.go b/eth/backend.go index 0e51f3a277..db8a246055 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -233,7 +233,7 @@ func (s *Ethereum) MaxPeers() int { } // Start the ethereum -func (s *Ethereum) Start(seed bool) error { +func (s *Ethereum) Start(seed bool, p string) error { err := s.net.Start() if err != nil { return err @@ -255,6 +255,12 @@ func (s *Ethereum) Start(seed bool) error { s.blockSub = s.eventMux.Subscribe(core.NewMinedBlockEvent{}) go s.blockBroadcastLoop() + if len(p) > 0 { + if err := s.SuggestPeer(p); err != nil { + return err + } + } + // TODO: read peers here if seed { logger.Infof("Connect to seed node %v", seedNodeAddress)