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>support/v0.27
parent
d3349a293a
commit
900949c648
|
@ -12,6 +12,12 @@ type Address struct {
|
|||
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 {
|
||||
return a.ma.String()
|
||||
}
|
||||
|
@ -37,3 +43,9 @@ func AddressFromString(s string) (*Address, error) {
|
|||
ma: ma,
|
||||
}, 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 New Issue