diff options
author | obscuren <geffobscura@gmail.com> | 2014-09-17 21:57:44 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-09-17 21:57:44 +0800 |
commit | 9559b5322857edfc819f7888a791d4f2a396fd17 (patch) | |
tree | d6c721fa110707d7fcc164979104c2f09544395d | |
parent | eb32fe20c8513b936faf908985d021caa87d5b0d (diff) | |
download | go-tangerine-9559b5322857edfc819f7888a791d4f2a396fd17.tar go-tangerine-9559b5322857edfc819f7888a791d4f2a396fd17.tar.gz go-tangerine-9559b5322857edfc819f7888a791d4f2a396fd17.tar.bz2 go-tangerine-9559b5322857edfc819f7888a791d4f2a396fd17.tar.lz go-tangerine-9559b5322857edfc819f7888a791d4f2a396fd17.tar.xz go-tangerine-9559b5322857edfc819f7888a791d4f2a396fd17.tar.zst go-tangerine-9559b5322857edfc819f7888a791d4f2a396fd17.zip |
Added Past peers option
-rw-r--r-- | ethereum.go | 19 |
1 files changed, 14 insertions, 5 deletions
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 +} |