use of jota.dto.response.GetTransactionsToApproveResponse in project isf-jclient by mikrohash.
the class IotaAPI method sendSpam.
public void sendSpam() throws ArgumentException {
ArrayList<Transfer> transfers = new ArrayList<Transfer>();
String message = UploadDataManager.getNextData();
transfers.add(new Transfer(AddressManager.getSpamAddress(), 0, message, SpamThread.getTag()));
List<Input> inputs = new ArrayList<Input>();
List<String> trytes = prepareTransfers("", SECURITY, transfers, null, inputs, false);
GetTransactionsToApproveResponse txs = TipPool.getTransactionsToApprove();
while (txs == null) txs = NodeManager.getTransactionsToApprove(NodeManager.getRotatedAPI());
final GetAttachToTangleResponse res = attachToTangle(txs.getTrunkTransaction(), txs.getBranchTransaction(), MIN_WEIGHT_MAGNITUDE, trytes.toArray(new String[trytes.size()]));
TxBroadcaster.queueTrytes(res);
}
use of jota.dto.response.GetTransactionsToApproveResponse in project isf-jclient by mikrohash.
the class NodeManager method isNodeSynced.
private static String isNodeSynced(int api) {
GetNodeInfoResponse getNodeInfoResponse = null;
try {
getNodeInfoResponse = getNodeInfo(api, false);
} catch (Throwable e) {
return e.getClass().getName() + ": " + e.getMessage();
}
if (getNodeInfoResponse == null)
return "did not receive getNodeInfoResponse response within " + NODEINFO_DURATION_TOLERANCE + " seconds";
if (Math.abs(getNodeInfoResponse.getLatestSolidSubtangleMilestoneIndex() - getNodeInfoResponse.getLatestMilestoneIndex()) > 3)
return "solid subtangle is not updated: lacking " + (getNodeInfoResponse.getLatestMilestoneIndex() - getNodeInfoResponse.getLatestSolidSubtangleMilestoneIndex()) + " milestones behind";
String milestone = getNodeInfoResponse.getLatestSolidSubtangleMilestone();
long secondsBehind = System.currentTimeMillis() / 1000 - findTractionsByHashes(new String[] { milestone }, api).get(0).getTimestamp();
if (secondsBehind > 600)
return "lacking " + (secondsBehind / 60) + " minutes behind";
GetTransactionsToApproveResponse getTransactionsToApproveResponse = null;
try {
getTransactionsToApproveResponse = apis[api].getTransactionsToApprove(DEPTH);
} catch (Throwable e) {
return e.getClass().getName() + ": " + e.getMessage();
}
if (getTransactionsToApproveResponse == null)
return "getTransactionsToApproveResponse == null";
String[] hashes = { getTransactionsToApproveResponse.getBranchTransaction(), getTransactionsToApproveResponse.getTrunkTransaction() };
List<Transaction> transactions = findTractionsByHashes(hashes, api);
if (transactions.size() == 0)
return "silly node pretends to not know tips it just provided";
long newerTimestamp = Math.max(transactions.get(0).getAttachmentTimestamp(), transactions.get(1).getAttachmentTimestamp());
long tipAge = System.currentTimeMillis() / 1000 - newerTimestamp;
lastSyncCheck[api] = System.currentTimeMillis();
return tipAge > TIP_AGE_TOLERANCE ? "tips are " + tipAge + "s old, tolerance is set to " + TIP_AGE_TOLERANCE + "s" : null;
}
use of jota.dto.response.GetTransactionsToApproveResponse in project isf-jclient by mikrohash.
the class NodeManager method getTransactionsToApprove.
public static GetTransactionsToApproveResponse getTransactionsToApprove(int api) {
GetTransactionsToApproveResponse getTransactionsToApproveResponse = null;
long timeStarted = System.currentTimeMillis();
while (getTransactionsToApproveResponse == null) {
try {
if (!available[api])
return null;
getTransactionsToApproveResponse = apis[api].getTransactionsToApprove(DEPTH);
} catch (IllegalStateException e) {
if (e.getMessage().contains("thread interrupted")) {
} else
api = handleThrowableFromIotaAPI("get transactions to approve", e, api);
} catch (Throwable e) {
api = handleThrowableFromIotaAPI("get transactions to approve", e, api);
}
}
totalTimeGetTxsToApprove += System.currentTimeMillis() - timeStarted;
amountGetTxsToApprove++;
return getTransactionsToApproveResponse;
}
use of jota.dto.response.GetTransactionsToApproveResponse in project isf-jclient by mikrohash.
the class TipPool method init.
public static void init() {
for (int i = 0; i < NodeManager.getAmountOfAPIs(); i++) {
final int api = i;
new Thread() {
@Override
public void run() {
TimeAbortCall tb = new TimeAbortCall("requesting transactions to approve (tips)", 10) {
@Override
public boolean onCall() {
GetTransactionsToApproveResponse gttar = NodeManager.getTransactionsToApprove(api);
if (gttar != null) {
gttars.push(gttar);
REQUIRED_TIPS.o = gttarsLimit - gttars.size();
}
return gttar != null;
}
@Override
public void onNotToleratedFail(String failMsg) {
NodeManager.connectToAnyNode(api, failMsg);
}
};
while (true) {
do {
synchronized (REQUIRED_TIPS) {
try {
REQUIRED_TIPS.wait();
} catch (InterruptedException e) {
}
}
} while (!NodeManager.isAvailable(api));
while ((int) REQUESTED_TIPS.o < (int) REQUIRED_TIPS.o) {
synchronized (REQUIRED_TIPS) {
REQUESTED_TIPS.o = ((int) REQUESTED_TIPS.o) + 1;
}
if (!tb.call(6))
;
synchronized (REQUIRED_TIPS) {
REQUESTED_TIPS.o = ((int) REQUESTED_TIPS.o) - 1;
}
}
}
}
}.start();
}
}
Aggregations