Added Past peers option

This commit is contained in:
obscuren 2014-09-17 15:57:44 +02:00
parent eb32fe20c8
commit 9559b53228

View File

@ -399,9 +399,7 @@ func (s *Ethereum) Start(seed bool) {
} }
func (s *Ethereum) Seed() { func (s *Ethereum) Seed() {
var ips []string ips := PastPeers()
data, _ := ethutil.ReadAllFile(path.Join(ethutil.Config.ExecPath, "known_peers.json"))
json.Unmarshal([]byte(data), &ips)
if len(ips) > 0 { if len(ips) > 0 {
for _, ip := range ips { for _, ip := range ips {
ethlogger.Infoln("Connecting to previous peer ", ip) ethlogger.Infoln("Connecting to previous peer ", ip)
@ -473,8 +471,11 @@ func (s *Ethereum) Stop() {
eachPeer(s.peers, func(p *Peer, e *list.Element) { eachPeer(s.peers, func(p *Peer, e *list.Element) {
ips = append(ips, p.conn.RemoteAddr().String()) ips = append(ips, p.conn.RemoteAddr().String())
}) })
if len(ips) > 0 {
d, _ := json.MarshalIndent(ips, "", " ") d, _ := json.MarshalIndent(ips, "", " ")
ethutil.WriteFile(path.Join(ethutil.Config.ExecPath, "known_peers.json"), d) ethutil.WriteFile(path.Join(ethutil.Config.ExecPath, "known_peers.json"), d)
}
eachPeer(s.peers, func(p *Peer, e *list.Element) { eachPeer(s.peers, func(p *Peer, e *list.Element) {
p.Stop() p.Stop()
@ -620,3 +621,11 @@ func bootstrapDb(db ethutil.Database) {
db.Put([]byte("ProtocolVersion"), ethutil.NewValue(ProtocolVersion).Bytes()) 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
}