Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/node/extract_addrbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func GetExtractAddrBookCmd() *cobra.Command {
}

lastSuccessThreshold, _ := cmd.Flags().GetDuration(flagLastSuccessThreshold)
livePeers := addrBook.GetLivePeers(lastSuccessThreshold)
livePeers := addrBook.GetLivePeers(lastSuccessThreshold, true)

newAddrBook := types.AddrBook{
Key: addrBook.Key,
Expand Down
2 changes: 1 addition & 1 deletion cmd/node/prune_addrbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetPruneAddrBookCmd() *cobra.Command {
return
}

livePeers := addrBook.GetLivePeers(48 * time.Hour)
livePeers := addrBook.GetLivePeers(48*time.Hour, false)

newAddrBook := types.AddrBook{
Key: addrBook.Key,
Expand Down
2 changes: 1 addition & 1 deletion cmd/node/state_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func GetStateSyncCmd() *cobra.Command {
return
}

livePeers := addrBook.GetLivePeers(5 * time.Hour)
livePeers := addrBook.GetLivePeers(5*time.Hour, true)

if len(livePeers) == 0 {
utils.PrintlnStdErr("WARN: no live peers found in provided address book")
Expand Down
2 changes: 1 addition & 1 deletion services/web_server/download_addrbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func getAddrbook(cfg webtypes.Config) (*types.AddrBook, error) {
return nil, errors.Wrap(err, "failed to read addrbook")
}

livePeers := addrBook.GetLivePeers(48 * time.Hour)
livePeers := addrBook.GetLivePeers(48*time.Hour, false)

if len(livePeers) == 0 && cfg.Debug {
// load random, include dead peers, on debug mode
Expand Down
2 changes: 1 addition & 1 deletion services/web_server/handle_api_node_peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func getLivePeers(cfg webtypes.Config) ([]string, error) {
return nil, errors.Wrap(err, "failed to read addrbook")
}

livePeers := addrBook.GetLivePeers(1 * time.Hour)
livePeers := addrBook.GetLivePeers(1*time.Hour, true)

if len(livePeers) == 0 && cfg.Debug {
// load random, include dead peers, on debug mode
Expand Down
10 changes: 9 additions & 1 deletion types/addrbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/pkg/errors"
"net"
"os"
"strings"
"time"
)

Expand Down Expand Up @@ -46,7 +47,7 @@ func (ab *AddrBook) ReadAddrBook(inputFilePath string) error {
return nil
}

func (ab *AddrBook) GetLivePeers(validDuration time.Duration) []*KnownAddress {
func (ab *AddrBook) GetLivePeers(validDuration time.Duration, excludeIPv6 bool) []*KnownAddress {
var livePeers []*KnownAddress
for _, addr := range ab.Addrs {
if addr.Addr == nil {
Expand All @@ -66,6 +67,13 @@ func (ab *AddrBook) GetLivePeers(validDuration time.Duration) []*KnownAddress {
}
}

if excludeIPv6 {
spl := strings.Split(addr.Addr.IP.String(), ":")
if len(spl) > 2 {
continue
}
}

livePeers = append(livePeers, addr)
}

Expand Down