mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-20 14:51:58 +00:00
Compare commits
1 Commits
josef/chec
...
v0.26.1-rc
Author | SHA1 | Date | |
---|---|---|---|
|
58574b7372 |
@@ -218,10 +218,22 @@ func (na *NetAddress) Routable() bool {
|
|||||||
// For IPv4 these are either a 0 or all bits set address. For IPv6 a zero
|
// For IPv4 these are either a 0 or all bits set address. For IPv6 a zero
|
||||||
// address or one that matches the RFC3849 documentation address format.
|
// address or one that matches the RFC3849 documentation address format.
|
||||||
func (na *NetAddress) Valid() bool {
|
func (na *NetAddress) Valid() bool {
|
||||||
|
if string(na.ID) != "" {
|
||||||
|
data, err := hex.DecodeString(string(na.ID))
|
||||||
|
if err != nil || len(data) != IDByteLength {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
return na.IP != nil && !(na.IP.IsUnspecified() || na.RFC3849() ||
|
return na.IP != nil && !(na.IP.IsUnspecified() || na.RFC3849() ||
|
||||||
na.IP.Equal(net.IPv4bcast))
|
na.IP.Equal(net.IPv4bcast))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasID returns true if the address has an ID.
|
||||||
|
// NOTE: It does not check whether the ID is valid or not.
|
||||||
|
func (na *NetAddress) HasID() bool {
|
||||||
|
return string(na.ID) != ""
|
||||||
|
}
|
||||||
|
|
||||||
// Local returns true if it is a local address.
|
// Local returns true if it is a local address.
|
||||||
func (na *NetAddress) Local() bool {
|
func (na *NetAddress) Local() bool {
|
||||||
return na.IP.IsLoopback() || zero4.Contains(na.IP)
|
return na.IP.IsLoopback() || zero4.Contains(na.IP)
|
||||||
|
@@ -652,6 +652,10 @@ func (a *addrBook) addAddress(addr, src *p2p.NetAddress) error {
|
|||||||
return ErrAddrBookInvalidAddr{addr}
|
return ErrAddrBookInvalidAddr{addr}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !addr.HasID() {
|
||||||
|
return ErrAddrBookInvalidAddrNoID{addr}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: we should track ourAddrs by ID and by IP:PORT and refuse both.
|
// TODO: we should track ourAddrs by ID and by IP:PORT and refuse both.
|
||||||
if _, ok := a.ourAddrs[addr.String()]; ok {
|
if _, ok := a.ourAddrs[addr.String()]; ok {
|
||||||
return ErrAddrBookSelf{addr}
|
return ErrAddrBookSelf{addr}
|
||||||
|
@@ -54,3 +54,11 @@ type ErrAddrBookInvalidAddr struct {
|
|||||||
func (err ErrAddrBookInvalidAddr) Error() string {
|
func (err ErrAddrBookInvalidAddr) Error() string {
|
||||||
return fmt.Sprintf("Cannot add invalid address %v", err.Addr)
|
return fmt.Sprintf("Cannot add invalid address %v", err.Addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ErrAddrBookInvalidAddrNoID struct {
|
||||||
|
Addr *p2p.NetAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err ErrAddrBookInvalidAddrNoID) Error() string {
|
||||||
|
return fmt.Sprintf("Cannot add address with no ID %v", err.Addr)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user