| 19 | static const int defaultNehTimeOut = 10; |
| 20 | |
| 21 | class TNetworkAddress { |
| 22 | public: |
| 23 | using TPortNum = unsigned short; |
| 24 | |
| 25 | TNetworkAddress() = default; |
| 26 | |
| 27 | TNetworkAddress(const TString& address, TPortNum port) |
| 28 | : Address(address) |
| 29 | , Port(port) |
| 30 | , CachedNehAddr(TStringBuilder() << "tcp2://" << Address << ":" << Port << "/matrixnet") |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | bool operator==(const TNetworkAddress& other) const { |
| 35 | return this->Address == other.Address && this->Port == other.Port; |
| 36 | } |
| 37 | |
| 38 | bool operator!=(const TNetworkAddress& other) const { |
| 39 | return !(*this == other); |
| 40 | } |
| 41 | |
| 42 | const TString& GetNehAddr() const { |
| 43 | return CachedNehAddr; |
| 44 | } |
| 45 | |
| 46 | const NNetliba_v12::TUdpAddress& GetNetlibaAddr() const { |
| 47 | with_lock (NetlibaAddrLock) { |
| 48 | if (NetlibaAddr.Empty()) { |
| 49 | NetlibaAddr = NNetliba_v12::CreateAddress(Address, Port); |
| 50 | } |
| 51 | return NetlibaAddr.GetRef(); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | size_t Hash() const { |
| 56 | return ComputeHash(Address) ^ IntHash(Port); |
| 57 | } |
| 58 | |
| 59 | SAVELOAD(Address, Port, CachedNehAddr); |
| 60 | |
| 61 | private: |
| 62 | TString Address; |
| 63 | TPortNum Port; |
| 64 | TString CachedNehAddr; |
| 65 | |
| 66 | mutable TAdaptiveLock NetlibaAddrLock; |
| 67 | mutable TMaybe<NNetliba_v12::TUdpAddress> NetlibaAddr; |
| 68 | }; |
| 69 | |
| 70 | struct TNetworkRequest { |
| 71 | TGUID ReqId; |
no outgoing calls
no test coverage detected