From 9559b5322857edfc819f7888a791d4f2a396fd17 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 17 Sep 2014 15:57:44 +0200 Subject: Added Past peers option --- ethereum.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'ethereum.go') diff --git a/ethereum.go b/ethereum.go index 729f81926..4cf1ce9e7 100644 --- a/ethereum.go +++ b/ethereum.go @@ -399,9 +399,7 @@ func (s *Ethereum) Start(seed bool) { } func (s *Ethereum) Seed() { - var ips []string - data, _ := ethutil.ReadAllFile(path.Join(ethutil.Config.ExecPath, "known_peers.json")) - json.Unmarshal([]byte(data), &ips) + ips := PastPeers() if len(ips) > 0 { for _, ip := range ips { ethlogger.Infoln("Connecting to previous peer ", ip) @@ -473,8 +471,11 @@ func (s *Ethereum) Stop() { eachPeer(s.peers, func(p *Peer, e *list.Element) { ips = append(ips, p.conn.RemoteAddr().String()) }) - d, _ := json.MarshalIndent(ips, "", " ") - ethutil.WriteFile(path.Join(ethutil.Config.ExecPath, "known_peers.json"), d) + + if len(ips) > 0 { + d, _ := json.MarshalIndent(ips, "", " ") + ethutil.WriteFile(path.Join(ethutil.Config.ExecPath, "known_peers.json"), d) + } eachPeer(s.peers, func(p *Peer, e *list.Element) { p.Stop() @@ -620,3 +621,11 @@ func bootstrapDb(db ethutil.Database) { db.Put([]byte("ProtocolVersion"), ethutil.NewValue(ProtocolVersion).Bytes()) } } + +func PastPeers() []string { + var ips []string + data, _ := ethutil.ReadAllFile(path.Join(ethutil.Config.ExecPath, "known_peers.json")) + json.Unmarshal([]byte(data), &ips) + + return ips +} -- cgit