mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-18 21:32:35 +01:00
Services: add anyOf()
helper to check for at least one of the given node services
This commit is contained in:
parent
f174e2350e
commit
5e1c556a15
@ -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);
|
||||
|
@ -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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user