Skip to content

Commit

Permalink
Revert "populate dial attempts (might revert)"
Browse files Browse the repository at this point in the history
This reverts commit 3a474a4.
  • Loading branch information
czarcas7ic committed Jun 29, 2024
1 parent a77c49d commit 12eb426
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 47 deletions.
9 changes: 0 additions & 9 deletions p2p/pex/addrbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ type AddrBook interface {

// Persist to disk
Save()

LoadDialAttempts(*Reactor) bool
}

var _ AddrBook = (*addrBook)(nil)
Expand Down Expand Up @@ -958,10 +956,3 @@ func (a *addrBook) hash(b []byte) ([]byte, error) {
hasher.Write(b)
return hasher.Sum(nil), nil
}

func (a *addrBook) LoadDialAttempts(r *Reactor) bool {
a.mtx.Lock()
defer a.mtx.Unlock()

return a.loadDialAttempts(a.filePath, r)
}
35 changes: 0 additions & 35 deletions p2p/pex/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,38 +81,3 @@ func (a *addrBook) loadFromFile(filePath string) bool {
}
return true
}

func (a *addrBook) loadDialAttempts(filePath string, r *Reactor) bool {
// If doesn't exist, do nothing.
_, err := os.Stat(filePath)
if os.IsNotExist(err) {
return false
}

// Load addrBookJSON{}
addrBook, err := os.Open(filePath)
if err != nil {
panic(fmt.Sprintf("Error opening file %s: %v", filePath, err))
}
defer addrBook.Close()
aJSON := &addrBookJSON{}
dec := json.NewDecoder(addrBook)
err = dec.Decode(aJSON)
if err != nil {
panic(fmt.Sprintf("Error reading file %s: %v", filePath, err))
}

// Restore all the fields...
// Restore the key
a.key = aJSON.Key
// Restore .bucketsNew & .bucketsOld
for _, ka := range aJSON.Addrs {
// Populate attemptsToDial in Reactor
r.attemptsToDial.Store(ka.Addr.String(), _attemptsToDial{
number: int(ka.Attempts),
lastDialed: ka.LastAttempt,
})
}

return true
}
3 changes: 0 additions & 3 deletions p2p/pex/pex_reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ func (r *Reactor) OnStart() error {

r.seedAddrs = seedAddrs

r.book.LoadDialAttempts(r)

// Check if this node should run
// in seed/crawler mode
if r.config.SeedMode {
Expand Down Expand Up @@ -830,7 +828,6 @@ func (r *Reactor) attemptDisconnects() {
func markAddrInBookBasedOnErr(addr *p2p.NetAddress, book AddrBook, err error) {
// TODO: detect more "bad peer" scenarios
// TODO, blacklist peer if fmt.Errorf("peer is on a different network. Got %v, expected %v", other.Network, info.Network)
// TODO, connect: no route to host block
switch err.(type) {
case p2p.ErrSwitchAuthenticationFailure:
book.MarkBad(addr, defaultBanTime)
Expand Down

0 comments on commit 12eb426

Please sign in to comment.