mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-28 12:11:44 +00:00
don't add our listener address into addrbook.
This commit is contained in:
1
main.go
1
main.go
@ -80,6 +80,7 @@ func (n *Node) Stop() {
|
|||||||
func (n *Node) AddListener(l p2p.Listener) {
|
func (n *Node) AddListener(l p2p.Listener) {
|
||||||
log.Info("Added %v", l)
|
log.Info("Added %v", l)
|
||||||
n.lz = append(n.lz, l)
|
n.lz = append(n.lz, l)
|
||||||
|
n.book.AddOurAddress(l.ExternalAddress())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) inboundConnectionHandler(l p2p.Listener) {
|
func (n *Node) inboundConnectionHandler(l p2p.Listener) {
|
||||||
|
@ -19,29 +19,6 @@ import (
|
|||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
/* AddrBook - concurrency safe peer address manager */
|
|
||||||
type AddrBook struct {
|
|
||||||
filePath string
|
|
||||||
|
|
||||||
mtx sync.Mutex
|
|
||||||
rand *rand.Rand
|
|
||||||
key string
|
|
||||||
addrLookup map[string]*knownAddress // new & old
|
|
||||||
addrNew []map[string]*knownAddress
|
|
||||||
addrOld []map[string]*knownAddress
|
|
||||||
started uint32
|
|
||||||
stopped uint32
|
|
||||||
wg sync.WaitGroup
|
|
||||||
quit chan struct{}
|
|
||||||
nOld int
|
|
||||||
nNew int
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
bucketTypeNew = 0x01
|
|
||||||
bucketTypeOld = 0x02
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// addresses under which the address manager will claim to need more addresses.
|
// addresses under which the address manager will claim to need more addresses.
|
||||||
needAddressThreshold = 1000
|
needAddressThreshold = 1000
|
||||||
@ -96,10 +73,36 @@ const (
|
|||||||
serializationVersion = 1
|
serializationVersion = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/* AddrBook - concurrency safe peer address manager */
|
||||||
|
type AddrBook struct {
|
||||||
|
filePath string
|
||||||
|
|
||||||
|
mtx sync.Mutex
|
||||||
|
rand *rand.Rand
|
||||||
|
key string
|
||||||
|
ourAddrs map[string]struct{}
|
||||||
|
addrLookup map[string]*knownAddress // new & old
|
||||||
|
addrNew []map[string]*knownAddress
|
||||||
|
addrOld []map[string]*knownAddress
|
||||||
|
started uint32
|
||||||
|
stopped uint32
|
||||||
|
wg sync.WaitGroup
|
||||||
|
quit chan struct{}
|
||||||
|
nOld int
|
||||||
|
nNew int
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
bucketTypeNew = 0x01
|
||||||
|
bucketTypeOld = 0x02
|
||||||
|
)
|
||||||
|
|
||||||
// Use Start to begin processing asynchronous address updates.
|
// Use Start to begin processing asynchronous address updates.
|
||||||
func NewAddrBook(filePath string) *AddrBook {
|
func NewAddrBook(filePath string) *AddrBook {
|
||||||
am := AddrBook{
|
am := AddrBook{
|
||||||
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
|
rand: rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||||
|
ourAddrs: make(map[string]struct{}),
|
||||||
|
addrLookup: make(map[string]*knownAddress),
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
filePath: filePath,
|
filePath: filePath,
|
||||||
}
|
}
|
||||||
@ -110,8 +113,6 @@ func NewAddrBook(filePath string) *AddrBook {
|
|||||||
// When modifying this, don't forget to update loadFromFile()
|
// When modifying this, don't forget to update loadFromFile()
|
||||||
func (a *AddrBook) init() {
|
func (a *AddrBook) init() {
|
||||||
a.key = RandHex(24) // 24/2 * 8 = 96 bits
|
a.key = RandHex(24) // 24/2 * 8 = 96 bits
|
||||||
// addr -> ka index
|
|
||||||
a.addrLookup = make(map[string]*knownAddress)
|
|
||||||
// New addr buckets
|
// New addr buckets
|
||||||
a.addrNew = make([]map[string]*knownAddress, newBucketCount)
|
a.addrNew = make([]map[string]*knownAddress, newBucketCount)
|
||||||
for i := range a.addrNew {
|
for i := range a.addrNew {
|
||||||
@ -141,6 +142,12 @@ func (a *AddrBook) Stop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AddrBook) AddOurAddress(addr *NetAddress) {
|
||||||
|
a.mtx.Lock()
|
||||||
|
defer a.mtx.Unlock()
|
||||||
|
a.ourAddrs[addr.String()] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
func (a *AddrBook) AddAddress(addr *NetAddress, src *NetAddress) {
|
func (a *AddrBook) AddAddress(addr *NetAddress, src *NetAddress) {
|
||||||
a.mtx.Lock()
|
a.mtx.Lock()
|
||||||
defer a.mtx.Unlock()
|
defer a.mtx.Unlock()
|
||||||
@ -267,7 +274,6 @@ func (a *AddrBook) GetSelection() []*NetAddress {
|
|||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
numAddresses := MaxInt(
|
numAddresses := MaxInt(
|
||||||
MinInt(minGetSelection, len(allAddr)),
|
MinInt(minGetSelection, len(allAddr)),
|
||||||
len(allAddr)*getSelectionPercent/100)
|
len(allAddr)*getSelectionPercent/100)
|
||||||
@ -505,6 +511,10 @@ func (a *AddrBook) addAddress(addr, src *NetAddress) {
|
|||||||
log.Warning("Cannot add non-routable address %v", addr)
|
log.Warning("Cannot add non-routable address %v", addr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if _, ok := a.ourAddrs[addr.String()]; ok {
|
||||||
|
// Ignore our own listener address.
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ka := a.addrLookup[addr.String()]
|
ka := a.addrLookup[addr.String()]
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user