public void setStatus(Status status) { if (status != Status.RECEIVED && sent == null && status != Status.DRAFT) { sent = UnixTime.now(); } this.status = status; }
/** * Increases the counter by length, if not null. */ public static void inc(AccessCounter counter, int length) { if (counter != null) counter.inc(length); }
/** * @return true if a < b, where the first [size] bytes are used as the numbers to check. */ public static boolean lt(byte[] a, byte[] b, int size) { for (int i = 0; i < size; i++) { if (a[i] != b[i]) { return lt(a[i], b[i]); } } return false; }
private static boolean testChecksum(byte[] checksum, byte[] payload) { byte[] payloadChecksum = Security.sha512(payload); for (int i = 0; i < checksum.length; i++) { if (checksum[i] != payloadChecksum[i]) { return false; } } return true; }
private CryptoBox(Builder builder) { initializationVector = builder.initializationVector; curveType = builder.curveType; R = Security.createPoint(builder.xComponent, builder.yComponent); encrypted = builder.encrypted; mac = builder.mac; }
/** * A helper method to calculate SHA-512 hashes. Please note that a new {@link MessageDigest} object is created at * each call (to ensure thread safety), so you shouldn't use this if you need to do many hash calculations in * success on the same thread. * * @param data to get hashed * @return SHA-512 hash of data */ public static byte[] sha512(byte[]... data) { return hash("SHA-512", data); }
public Builder defaults(long clientNonce) { version = BitmessageContext.CURRENT_VERSION; services = 1; timestamp = UnixTime.now(); userAgent = "/Jabit:0.0.1/"; streamNumbers = new long[]{1}; nonce = clientNonce; return this; }
/** * Increases the counter by one, if not null. */ public static void inc(AccessCounter counter) { if (counter != null) counter.inc(); }
/** * @return true if a < b, where the first [size] bytes are used as the numbers to check. */ public static boolean lt(byte[] a, byte[] b, int size) { for (int i = 0; i < size; i++) { if (a[i] != b[i]) { return lt(a[i], b[i]); } } return false; }
/** * First 4 bytes of sha512(payload) */ private byte[] getChecksum(byte[] bytes) throws NoSuchProviderException, NoSuchAlgorithmException { byte[] d = sha512(bytes); return new byte[]{d[0], d[1], d[2], d[3]}; }
private Connection(InternalContext context, Mode mode, Socket socket, Map<InventoryVector, Long> commonRequestedObjects, NetworkAddress node, long syncTimeout) { super(context, mode, node, commonRequestedObjects, syncTimeout); this.startTime = UnixTime.now(); this.socket = socket; }
/** * Increases the counter by one, if not null. */ public static void inc(AccessCounter counter) { if (counter != null) counter.inc(); }
/** * Increases the counter by length, if not null. */ public static void inc(AccessCounter counter, int length) { if (counter != null) counter.inc(length); }