Skip to content

Commit

Permalink
Merge bitcoin#19360: net: improve encapsulation of CNetAddr
Browse files Browse the repository at this point in the history
bc74a40 net: improve encapsulation of CNetAddr (Vasil Dimov)

Pull request description:

  Do not access `CNetAddr::ip` directly from `CService` methods.

  This improvement will help later when we change the type of
  `CNetAddr::ip` (in the BIP155 implementation).

  (chopped off from bitcoin#19031 to ease review)

ACKs for top commit:
  dongcarl:
    ACK bc74a40
  naumenkogs:
    ACK bc74a40
  fjahr:
    Code review ACK bc74a40
  laanwj:
    code review ACK bc74a40
  jonatack:
    ACK bc74a40
  jnewbery:
    ACK bc74a40

Tree-SHA512: 29a203905538e8311e3249b78565abe69ce36dc4ec239bec85c726c30e1a7b55b0aaf5c6659b676935008e068cfa53d716f7a598469064108daf130f94329a5d
  • Loading branch information
laanwj committed Jul 15, 2020
2 parents 31bdd86 + bc74a40 commit 3864219
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/netaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,12 +726,10 @@ bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const
*/
std::vector<unsigned char> CService::GetKey() const
{
std::vector<unsigned char> vKey;
vKey.resize(18);
memcpy(vKey.data(), ip, 16);
vKey[16] = port / 0x100; // most significant byte of our port
vKey[17] = port & 0x0FF; // least significant byte of our port
return vKey;
auto key = GetAddrBytes();
key.push_back(port / 0x100); // most significant byte of our port
key.push_back(port & 0x0FF); // least significant byte of our port
return key;
}

std::string CService::ToStringPort() const
Expand Down
6 changes: 5 additions & 1 deletion src/netaddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ class CService : public CNetAddr
CService(const struct in6_addr& ipv6Addr, uint16_t port);
explicit CService(const struct sockaddr_in6& addr);

SERIALIZE_METHODS(CService, obj) { READWRITE(obj.ip, Using<BigEndianFormatter<2>>(obj.port)); }
SERIALIZE_METHODS(CService, obj)
{
READWRITEAS(CNetAddr, obj);
READWRITE(Using<BigEndianFormatter<2>>(obj.port));
}
};

bool SanityCheckASMap(const std::vector<bool>& asmap);
Expand Down

0 comments on commit 3864219

Please sign in to comment.