forked from TrueCloudLab/frostfs-node
[#33] network: Implement tool to work with local address
Implement read-only local network address source. Implement function for check if network address is local. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
d3349a293a
commit
900949c648
1 changed files with 12 additions and 0 deletions
|
@ -12,6 +12,12 @@ type Address struct {
|
||||||
ma multiaddr.Multiaddr
|
ma multiaddr.Multiaddr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LocalAddressSource is an interface of local
|
||||||
|
// network address container with read access.
|
||||||
|
type LocalAddressSource interface {
|
||||||
|
LocalAddress() *Address
|
||||||
|
}
|
||||||
|
|
||||||
func (a Address) String() string {
|
func (a Address) String() string {
|
||||||
return a.ma.String()
|
return a.ma.String()
|
||||||
}
|
}
|
||||||
|
@ -37,3 +43,9 @@ func AddressFromString(s string) (*Address, error) {
|
||||||
ma: ma,
|
ma: ma,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsLocalAddress returns true if network endpoint from local address
|
||||||
|
// source is equal to network endpoint of passed address.
|
||||||
|
func IsLocalAddress(src LocalAddressSource, addr *Address) bool {
|
||||||
|
return src.LocalAddress().NetAddr() == addr.NetAddr()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue