Services: add anyOf() helper to check for at least one of the given node services

This commit is contained in:
Andreas Schildbach 2023-04-03 16:16:47 +02:00
parent f174e2350e
commit 5e1c556a15
2 changed files with 12 additions and 2 deletions

View File

@ -523,7 +523,7 @@ public class Peer extends PeerSocketHandler {
// implementations claim to have a block chain in their services field but then report a height of zero, filter
// them out here.
Services services = peerVersionMessage.services();
if (!(services.has(Services.NODE_NETWORK) || services.has(Services.NODE_NETWORK_LIMITED)) ||
if (!services.anyOf(Services.NODE_NETWORK | Services.NODE_NETWORK_LIMITED) ||
(!params.allowEmptyPeerChain() && peerVersionMessage.bestHeight == 0)) {
// Shut down the channel gracefully.
log.info("{}: Peer does not have at least a recent part of the block chain.", this);

View File

@ -107,12 +107,22 @@ public class Services {
* Checks if given specific node services are signaled by this bitfield.
*
* @param bitmask bitmask representing the services to be checked for
* @return true if the given services are allsignaled, false otherwise
* @return true if the given services are all signaled, false otherwise
*/
public boolean has(long bitmask) {
return (bits & bitmask) == bitmask;
}
/**
* Checks if at least one of the given node services is signaled by this bitfield.
*
* @param bitmask bitmask representing the services to be checked for
* @return true if at least one of the given services is signaled, false otherwise
*/
public boolean anyOf(long bitmask) {
return (bits & bitmask) != 0;
}
/**
* Write the node service bits into the given buffer.
*