Skip to content

Commit

Permalink
Add variable naming rules to checkstyle (iotaledger#753)
Browse files Browse the repository at this point in the history
  • Loading branch information
GalRogozinski authored Sep 16, 2018
1 parent a454d8c commit b6c338e
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 62 deletions.
9 changes: 9 additions & 0 deletions checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@ IOTA checkstyle draft
<property name="fileExtensions" value="java, properties, xml"/>
<module name="TreeWalker">
<module name="NeedBraces"/>
<!-- Checks for Naming Conventions. -->

<!-- See http://checkstyle.sf.net/config_naming.html -->
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="TypeName"/>
</module>
</module>
4 changes: 2 additions & 2 deletions src/main/java/com/iota/iri/Iota.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void init() throws Exception {
tangle.init();

if (configuration.isRescanDb()){
rescan_db();
rescanDb();
}

if (configuration.isRevalidate()) {
Expand All @@ -85,7 +85,7 @@ public void init() throws Exception {
node.init();
}

private void rescan_db() throws Exception {
private void rescanDb() throws Exception {
//delete all transaction indexes
tangle.clearColumn(com.iota.iri.model.Address.class);
tangle.clearColumn(com.iota.iri.model.Bundle.class);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/iota/iri/MilestoneTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public MilestoneTracker(Tangle tangle,
}

private boolean shuttingDown;
private static int RESCAN_INTERVAL = 5000;
private static final int RESCAN_INTERVAL = 5000;

public void init (SpongeFactory.Mode mode, LedgerValidator ledgerValidator) {
this.ledgerValidator = ledgerValidator;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/iota/iri/TransactionValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class TransactionValidator {
private int MIN_WEIGHT_MAGNITUDE = 81;
private static long snapshotTimestamp;
private static long snapshotTimestampMs;
private static long MAX_TIMESTAMP_FUTURE = 2 * 60 * 60;
private static long MAX_TIMESTAMP_FUTURE_MS = MAX_TIMESTAMP_FUTURE * 1000;
private static final long MAX_TIMESTAMP_FUTURE = 2 * 60 * 60;
private static final long MAX_TIMESTAMP_FUTURE_MS = MAX_TIMESTAMP_FUTURE * 1000;

private Thread newSolidThread;

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/iota/iri/hash/Curl.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@ public void squeeze(final byte[] trits, int offset, int length) {
private void transform() {

int scratchpadIndex = 0;
int prev_scratchpadIndex = 0;
int prevScratchpadIndex = 0;
for (int round = 0; round < numberOfRounds; round++) {
System.arraycopy(state, 0, scratchpad, 0, STATE_LENGTH);
for (int stateIndex = 0; stateIndex < STATE_LENGTH; stateIndex++) {
prev_scratchpadIndex = scratchpadIndex;
prevScratchpadIndex = scratchpadIndex;
if (scratchpadIndex < 365) {
scratchpadIndex += 364;
} else {
scratchpadIndex += -365;
}
state[stateIndex] = TRUTH_TABLE[scratchpad[prev_scratchpadIndex] + (scratchpad[scratchpadIndex] << 2) + 5];
state[stateIndex] = TRUTH_TABLE[scratchpad[prevScratchpadIndex] + (scratchpad[scratchpadIndex] << 2) + 5];
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/iota/iri/network/TransactionRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public TransactionRequester(Tangle tangle, MessageQ messageQ) {
this.messageQ = messageQ;
}

public void init(double p_REMOVE_REQUEST) {
public void init(double pRemoveRequest) {
if(!initialized) {
initialized = true;
P_REMOVE_REQUEST = p_REMOVE_REQUEST;
P_REMOVE_REQUEST = pRemoveRequest;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ public void run() {
try {
CRC32 crc32 = new CRC32();
crc32.update(message.array());
String crc32_string = Long.toHexString(crc32.getValue());
while (crc32_string.length() < CRC32_BYTES) {
crc32_string = "0"+crc32_string;
String crc32String = Long.toHexString(crc32.getValue());
while (crc32String.length() < CRC32_BYTES) {
crc32String = "0"+crc32String;
}
out.write(message.array());
out.write(crc32_string.getBytes());
out.write(crc32String.getBytes());
out.flush();
neighbor.incSentTransactions();
} catch (IOException e2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@ public void run() {
boolean finallyClose = true;

try {

SocketAddress address = connection.getRemoteSocketAddress();
InetSocketAddress inet_socket_address = (InetSocketAddress) address;
InetSocketAddress inetSocketAddress = (InetSocketAddress) address;

existingNeighbor = false;
List<Neighbor> neighbors = node.getNeighbors();
neighbors.stream().filter(n -> n instanceof TCPNeighbor)
.map(n -> ((TCPNeighbor) n))
.forEach(n -> {
String hisAddress = inet_socket_address.getAddress().getHostAddress();
String hisAddress = inetSocketAddress.getAddress().getHostAddress();
if (n.getHostAddress().equals(hisAddress)) {
existingNeighbor = true;
neighbor = n;
Expand All @@ -76,11 +75,11 @@ public void run() {
if (!existingNeighbor) {
int maxPeersAllowed = maxPeers;
if (!testnet || Neighbor.getNumPeers() >= maxPeersAllowed) {
String hostAndPort = inet_socket_address.getHostName() + ":" + String.valueOf(inet_socket_address.getPort());
if (Node.rejectedAddresses.add(inet_socket_address.getHostName())) {
String hostAndPort = inetSocketAddress.getHostName() + ":" + String.valueOf(inetSocketAddress.getPort());
if (Node.rejectedAddresses.add(inetSocketAddress.getHostName())) {
String sb = "***** NETWORK ALERT ***** Got connected from unknown neighbor tcp://"
+ hostAndPort
+ " (" + inet_socket_address.getAddress().getHostAddress() + ") - closing connection";
+ " (" + inetSocketAddress.getAddress().getHostAddress() + ") - closing connection";
if (testnet && Neighbor.getNumPeers() >= maxPeersAllowed) {
sb = sb + (" (max-peers allowed is "+String.valueOf(maxPeersAllowed)+")");
}
Expand All @@ -92,15 +91,15 @@ public void run() {
connection.close();
return;
} else {
final TCPNeighbor fresh_neighbor = new TCPNeighbor(inet_socket_address, false);
node.getNeighbors().add(fresh_neighbor);
neighbor = fresh_neighbor;
final TCPNeighbor freshNeighbor = new TCPNeighbor(inetSocketAddress, false);
node.getNeighbors().add(freshNeighbor);
neighbor = freshNeighbor;
Neighbor.incNumPeers();
}
}

if ( neighbor.getSource() != null ) {
log.info("Source {} already connected", inet_socket_address.getAddress().getHostAddress());
log.info("Source {} already connected", inetSocketAddress.getAddress().getHostAddress());
finallyClose = false;
return;
}
Expand Down Expand Up @@ -128,7 +127,7 @@ public void run() {
}

if (connection.isConnected()) {
log.info("----- NETWORK INFO ----- Source {} is connected", inet_socket_address.getAddress().getHostAddress());
log.info("----- NETWORK INFO ----- Source {} is connected", inetSocketAddress.getAddress().getHostAddress());
}

connection.setSoTimeout(0); // infinite timeout - blocking read
Expand All @@ -152,15 +151,15 @@ public void run() {
for (int i=0; i<packetSize; i++) {
crc32.update(data[i]);
}
String crc32_string = Long.toHexString(crc32.getValue());
while (crc32_string.length() < ReplicatorSinkProcessor.CRC32_BYTES) {
crc32_string = "0"+crc32_string;
String crc32String = Long.toHexString(crc32.getValue());
while (crc32String.length() < ReplicatorSinkProcessor.CRC32_BYTES) {
crc32String = "0"+crc32String;
}
byte [] crc32_bytes = crc32_string.getBytes();
byte [] crc32Bytes = crc32String.getBytes();

boolean crcError = false;
for (int i=0; i<ReplicatorSinkProcessor.CRC32_BYTES; i++) {
if (crc32_bytes[i] != data[packetSize + i]) {
if (crc32Bytes[i] != data[packetSize + i]) {
crcError = true;
break;
}
Expand All @@ -170,7 +169,7 @@ public void run() {
}
}
catch (IllegalStateException e) {
log.error("Queue is full for neighbor IP {}",inet_socket_address.getAddress().getHostAddress());
log.error("Queue is full for neighbor IP {}",inetSocketAddress.getAddress().getHostAddress());
} catch (final RuntimeException e) {
log.error("Transaction processing runtime exception ",e);
neighbor.incInvalidTransactions();
Expand Down
42 changes: 21 additions & 21 deletions src/main/java/com/iota/iri/service/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ private AbstractResponse process(final String requestString, InetSocketAddress s
* Check if a list of addresses was ever spent from, in the current epoch, or in previous epochs.
*
* @param addresses List of addresses to check if they were ever spent from.
* @return {@link com.iota.iri.service.dto.wereAddressesSpentFrom}
* @return {@link com.iota.iri.service.dto.WereAddressesSpentFrom}
**/
private AbstractResponse wereAddressesSpentFromStatement(List<String> addresses) throws Exception {
final List<Hash> addressesHash = addresses.stream().map(Hash::new).collect(Collectors.toList());
Expand All @@ -377,7 +377,7 @@ private AbstractResponse wereAddressesSpentFromStatement(List<String> addresses)
for (Hash address : addressesHash) {
states[index++] = wasAddressSpentFrom(address);
}
return wereAddressesSpentFrom.create(states);
return WereAddressesSpentFrom.create(states);
}

private boolean wasAddressSpentFrom(Hash address) throws Exception {
Expand Down Expand Up @@ -602,19 +602,19 @@ private synchronized AbstractResponse getTrytesStatement(List<String> hashes) th
return GetTrytesResponse.create(elements);
}

private static int counter_getTxToApprove = 0;
public static int getCounter_getTxToApprove() {
return counter_getTxToApprove;
private static int counterGetTxToApprove = 0;
public static int getCounterGetTxToApprove() {
return counterGetTxToApprove;
}
public static void incCounter_getTxToApprove() {
counter_getTxToApprove++;
public static void incCounteGetTxToApprove() {
counterGetTxToApprove++;
}

private static long ellapsedTime_getTxToApprove = 0L;
public static long getEllapsedTime_getTxToApprove() {
public static long getEllapsedTimeGetTxToApprove() {
return ellapsedTime_getTxToApprove;
}
public static void incEllapsedTime_getTxToApprove(long ellapsedTime) {
public static void incEllapsedTimeGetTxToApprove(long ellapsedTime) {
ellapsedTime_getTxToApprove += ellapsedTime;
}

Expand Down Expand Up @@ -646,11 +646,11 @@ public synchronized List<Hash> getTransactionsToApproveStatement(int depth, Opti
}

private void gatherStatisticsOnTipSelection() {
API.incCounter_getTxToApprove();
if ((getCounter_getTxToApprove() % 100) == 0) {
String sb = "Last 100 getTxToApprove consumed " + API.getEllapsedTime_getTxToApprove() / 1000000000L + " seconds processing time.";
API.incCounteGetTxToApprove();
if ((getCounterGetTxToApprove() % 100) == 0) {
String sb = "Last 100 getTxToApprove consumed " + API.getEllapsedTimeGetTxToApprove() / 1000000000L + " seconds processing time.";
log.debug(sb);
counter_getTxToApprove = 0;
counterGetTxToApprove = 0;
ellapsedTime_getTxToApprove = 0L;
}
}
Expand Down Expand Up @@ -1033,18 +1033,18 @@ private AbstractResponse getBalancesStatement(final List<String> addresses, fina
}

private static int counter_PoW = 0;
public static int getCounter_PoW() {
public static int getCounterPoW() {
return counter_PoW;
}
public static void incCounter_PoW() {
public static void incCounterPoW() {
API.counter_PoW++;
}

private static long ellapsedTime_PoW = 0L;
public static long getEllapsedTime_PoW() {
public static long getEllapsedTimePoW() {
return ellapsedTime_PoW;
}
public static void incEllapsedTime_PoW(long ellapsedTime) {
public static void incEllapsedTimePoW(long ellapsedTime) {
ellapsedTime_PoW += ellapsedTime;
}

Expand Down Expand Up @@ -1109,11 +1109,11 @@ public synchronized List<String> attachToTangleStatement(final Hash trunkTransac
transactionViewModels.add(transactionViewModel);
prevTransaction = transactionViewModel.getHash();
} finally {
API.incEllapsedTime_PoW(System.nanoTime() - startTime);
API.incCounter_PoW();
if ( ( API.getCounter_PoW() % 100) == 0 ) {
API.incEllapsedTimePoW(System.nanoTime() - startTime);
API.incCounterPoW();
if ( ( API.getCounterPoW() % 100) == 0 ) {
String sb = "Last 100 PoW consumed " +
API.getEllapsedTime_PoW() / 1000000000L +
API.getEllapsedTimePoW() / 1000000000L +
" seconds processing time.";
log.info(sb);
counter_PoW = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.iota.iri.service.dto;

public class wereAddressesSpentFrom extends AbstractResponse {
public class WereAddressesSpentFrom extends AbstractResponse {

private boolean [] states;

public static AbstractResponse create(boolean[] inclusionStates) {
wereAddressesSpentFrom res = new wereAddressesSpentFrom();
WereAddressesSpentFrom res = new WereAddressesSpentFrom();
res.states = inclusionStates;
return res;
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/iota/iri/utils/MapIdentityManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ private boolean verifyCredential(Account account, Credential credential) {
if (credential instanceof PasswordCredential) {
char[] givenPassword = ((PasswordCredential) credential).getPassword();
String trytes = Converter.asciiToTrytes(new String(givenPassword));
byte[] in_trits = Converter.allocateTritsForTrytes(trytes.length());
Converter.trits(trytes, in_trits, 0);
byte[] hash_trits = new byte[Curl.HASH_LENGTH];
byte[] inTrits = Converter.allocateTritsForTrytes(trytes.length());
Converter.trits(trytes, inTrits, 0);
byte[] hashTrits = new byte[Curl.HASH_LENGTH];
Sponge curl;
curl = SpongeFactory.create(SpongeFactory.Mode.CURLP81);
curl.absorb(in_trits, 0, in_trits.length);
curl.squeeze(hash_trits, 0, Curl.HASH_LENGTH);
String out_trytes = Converter.trytes(hash_trits);
char[] char_out_trytes = out_trytes.toCharArray();
curl.absorb(inTrits, 0, inTrits.length);
curl.squeeze(hashTrits, 0, Curl.HASH_LENGTH);
String outTrytes = Converter.trytes(hashTrits);
char[] charOutTrytes = outTrytes.toCharArray();
char[] expectedPassword = users.get(account.getPrincipal().getName());
boolean verified = Arrays.equals(givenPassword, expectedPassword);
// Password can either be clear text or the hash of the password
if (!verified) {
verified = Arrays.equals(char_out_trytes, expectedPassword);
verified = Arrays.equals(charOutTrytes, expectedPassword);
}
return verified;
}
Expand Down

0 comments on commit b6c338e

Please sign in to comment.