本文整理汇总了Java中net.tomp2p.utils.Utils.MASK_FF属性的典型用法代码示例。如果您正苦于以下问题:Java Utils.MASK_FF属性的具体用法?Java Utils.MASK_FF怎么用?Java Utils.MASK_FF使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类net.tomp2p.utils.Utils
的用法示例。
在下文中一共展示了Utils.MASK_FF属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
/**
* Converts an byte array into a peer socket address.
*
* @param me
* The byte array
* @param isIPv4
* Indicates if its IPv4 or IPv6
* @param offsetOriginal
* The offset where to start reading in the array
* @return the PeerSocketAddress and the new offset
*/
public static PeerSocketAddress create(final byte[] me, final boolean isIPv4, final int offsetOriginal) {
int offset = offsetOriginal;
final int portTCP = ((me[offset++] & Utils.MASK_FF) << Utils.BYTE_BITS) + (me[offset++] & Utils.MASK_FF);
final int portUDP = ((me[offset++] & Utils.MASK_FF) << Utils.BYTE_BITS) + (me[offset++] & Utils.MASK_FF);
//
final InetAddress address;
if (isIPv4) {
address = Utils.inet4FromBytes(me, offset);
// IPv4 is 32 bit
offset += Utils.IPV4_BYTES;
} else {
address = Utils.inet6FromBytes(me, offset);
// IPv6 is 128 bit
offset += Utils.IPV6_BYTES;
}
return new PeerSocketAddress(address, portTCP, portUDP, offset);
}
示例2: PeerAddress
/**
* Creates a PeerAddress from a continuous byte array. This is useful if you don't know the size beforehand. The new
* offset can be accessed with offset().
*
* @param me
* The serialized array
* @param initialOffset
* the offset, where to start
*/
public PeerAddress(final byte[] me, final int initialOffset) {
// get the peer ID, this is independent of the type
int offset = initialOffset;
// get the type
final int options = me[offset++] & Utils.MASK_FF;
this.net6 = (options & NET6) > 0;
this.firewalledUDP = (options & FIREWALL_UDP) > 0;
this.firewalledTCP = (options & FIREWALL_TCP) > 0;
this.isRelay = (options & IS_RELAY) > 0;
final int relays = me[offset++] & Utils.MASK_FF;
// first: three bits are the size 1,2,4
// 000 means no relays
// 001 means 1 relay
// 010 means 2 relays
// 011 means 3 relays
// 100 means 4 relays
// 101 means 5 relays
// 110 is not used
// 111 is not used
// second: five bits indicate if IPv6 or IPv4 -> in total we can save 5 addresses
this.relaySize = (relays >>> TYPE_BIT_SIZE) & MASK_7;
final byte b = (byte) (relays & MASK_1F);
this.relayType = Utils.createBitSet(b);
// now comes the ID
final byte[] tmp = new byte[Number160.BYTE_ARRAY_SIZE];
System.arraycopy(me, offset, tmp, 0, Number160.BYTE_ARRAY_SIZE);
this.peerId = new Number160(tmp);
offset += Number160.BYTE_ARRAY_SIZE;
this.peerSocketAddress = PeerSocketAddress.create(me, isIPv4(), offset);
offset = this.peerSocketAddress.getOffset();
if (relaySize > 0) {
this.peerSocketAddresses = new PeerSocketAddress[relaySize];
for (int i = 0; i < relaySize; i++) {
peerSocketAddresses[i] = PeerSocketAddress.create(me, relayType.get(i), offset);
offset = peerSocketAddresses[i].getOffset();
}
} else {
this.peerSocketAddresses = EMPTY_PEER_SOCKET_ADDRESSES;
}
this.size = offset - initialOffset;
this.offset = offset;
this.hashCode = peerId.hashCode();
}
示例3: isNet6
/**
* Checks if option has IPv6 set.
*
* @param options
* The option field, lowest 8 bit
* @return True if its IPv6
*/
private static boolean isNet6(final int options) {
return ((options & Utils.MASK_FF) & NET6) > 0;
}
示例4: isFirewalledTCP
/**
* Checks if option has firewall TCP set.
*
* @param options
* The option field, lowest 8 bit
* @return True if it firewalled via TCP
*/
private static boolean isFirewalledTCP(final int options) {
return ((options & Utils.MASK_FF) & FIREWALL_TCP) > 0;
}
示例5: isFirewalledUDP
/**
* Checks if option has firewall UDP set.
*
* @param options
* The option field, lowest 8 bit
* @return True if it firewalled via UDP
*/
private static boolean isFirewalledUDP(final int options) {
return ((options & Utils.MASK_FF) & FIREWALL_UDP) > 0;
}
示例6: isRelay
/**
* Checks if option has relay flag set.
*
* @param options
* The option field, lowest 8 bit
* @return True if it is used as a relay
*/
private static boolean isRelay(final int options) {
return ((options & Utils.MASK_FF) & IS_RELAY) > 0;
}
示例7: size
/**
* Calculates the size based on the two header bytes.
*
* @param header
* The header is in the lower 16 bits
* @return the expected size of the peer address
*/
public static int size(final int header) {
int options = (header >>> Utils.BYTE_BITS) & Utils.MASK_FF;
int relays = header & Utils.MASK_FF;
return size(options, relays);
}