本文整理汇总了Java中net.tomp2p.utils.Utils.IPV4_BYTES属性的典型用法代码示例。如果您正苦于以下问题:Java Utils.IPV4_BYTES属性的具体用法?Java Utils.IPV4_BYTES怎么用?Java Utils.IPV4_BYTES使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类net.tomp2p.utils.Utils
的用法示例。
在下文中一共展示了Utils.IPV4_BYTES属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toByteArray
/**
* Serializes a peer socket address to a byte array. First the ports are serialized: TCP and UDP, then the address.
*
* @param me
* The byte array to store the serialization
* @param offset
* The offset where to start
* @return How many data have been written
*/
public int toByteArray(final byte[] me, final int offset) {
int offset2 = offset;
me[offset2++] = (byte) (tcpPort >>> Utils.BYTE_BITS);
me[offset2++] = (byte) tcpPort;
me[offset2++] = (byte) (udpPort >>> Utils.BYTE_BITS);
me[offset2++] = (byte) udpPort;
if (inetAddress instanceof Inet4Address) {
System.arraycopy(inetAddress.getAddress(), 0, me, offset2, Utils.IPV4_BYTES);
offset2 += Utils.IPV4_BYTES;
} else {
System.arraycopy(inetAddress.getAddress(), 0, me, offset2, Utils.IPV6_BYTES);
offset2 += Utils.IPV6_BYTES;
}
return offset2;
}
示例2: 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);
}
示例3: PeerAddress
/**
* Creates a PeerAddress if all the values are known.
*
* @param id
* The id of the peer
* @param peerSocketAddress
* The peer socket address including both ports UDP and TCP
* @param firewalledUDP
* Indicates if peer is not reachable via UDP
* @param firewalledTCP
* Indicates if peer is not reachable via TCP
* @param isRelay
* Indicates if peer used as a relay
* @param peerSocketAddresses
* the relay peers
*/
public PeerAddress(final Number160 id, final PeerSocketAddress peerSocketAddress,
final boolean firewalledTCP, final boolean firewalledUDP, final boolean isRelay,
final PeerSocketAddress[] peerSocketAddresses) {
this.peerId = id;
int size = Number160.BYTE_ARRAY_SIZE;
this.peerSocketAddress = peerSocketAddress;
this.hashCode = id.hashCode();
this.net6 = peerSocketAddress.getInetAddress() instanceof Inet6Address;
this.firewalledUDP = firewalledUDP;
this.firewalledTCP = firewalledTCP;
this.isRelay = false;
// header + TCP port + UDP port
size += HEADER_SIZE + PORTS_SIZE + (net6 ? Utils.IPV6_BYTES : Utils.IPV4_BYTES);
if (peerSocketAddresses == null) {
this.peerSocketAddresses = EMPTY_PEER_SOCKET_ADDRESSES;
this.relayType = EMPTY_RELAY_TYPE;
relaySize = 0;
} else {
relaySize = peerSocketAddresses.length;
if (relaySize > TYPE_BIT_SIZE) {
throw new IllegalArgumentException("Can only store up to 5 relay peers");
}
this.peerSocketAddresses = peerSocketAddresses;
this.relayType = new BitSet(relaySize);
}
for (int i = 0; i < relaySize; i++) {
boolean isIPV6 = peerSocketAddresses[i].getInetAddress() instanceof Inet6Address;
this.relayType.set(i, isIPV6);
}
this.size = size;
// unused here
this.offset = -1;
}