Skip to content

Commit

Permalink
Added another point of Transaction I/O to DDoS protection. Fixes the …
Browse files Browse the repository at this point in the history
…last source of forwarding unreasonably sized messages.

Head to reduce the number of unconfirmed transactions triggering closer scrutiny.
  • Loading branch information
muhatzg committed Jul 23, 2017
1 parent 22454c0 commit 803c8de
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/java/nxt/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public final class Constants {
public static final int PRIORITY_MESSAGE_FEE = 50;
//Prevents a single address from spaming too many transaction messages onto the network
public static final int MAX_SENDER_MESSEGAE_BYTES = 10 * 1024;
public static final int NUM_UNCONFIRMED_TRANSACTIONS_INVESTIGATE = 1000;
public static final int NUM_UNCONFIRMED_TRANSACTIONS_INVESTIGATE = 200;
public static final int BLOCK_MAX_MESSAGE_PAYLOAD = 20 * 1024;
public static final int BLOCK_MAX_SENDER_MESSAGE_PAYLOAD = 10 * 1024;
public static final int BLOCK_MAX_MESSAGES = 20;
Expand Down
10 changes: 5 additions & 5 deletions src/java/nxt/DDosProtection.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
* @author rainman
*/
public class DDosProtection {
public static List<TransactionImpl> sanitizeTransactionList(Collection<TransactionImpl> transactionList)
public static List<? extends Transaction> sanitizeTransactionList(Collection<? extends Transaction> transactionList)
{
return sanitizeTransactionList(transactionList, "Unknown");
}

public static List<TransactionImpl> sanitizeTransactionList(Collection<TransactionImpl> transactionList, String actor)
public static List<? extends Transaction> sanitizeTransactionList(Collection<? extends Transaction> transactionList, String actor)
{
int numTransactions = transactionList.size();
List<TransactionImpl> discardedTransactions = new ArrayList<>();
List<Transaction> discardedTransactions = new ArrayList<>();

if(numTransactions > Constants.NUM_UNCONFIRMED_TRANSACTIONS_INVESTIGATE) //Something fishy seems to be happening. Investigate
{
Expand All @@ -37,9 +37,9 @@ public static List<TransactionImpl> sanitizeTransactionList(Collection<Transacti
boolean discardGlobalMessageWarning = false;
boolean discardIndividualMessageWarning = false;

for(Iterator<TransactionImpl> transactionIterator = transactionList.iterator(); transactionIterator.hasNext();)
for(Iterator<? extends Transaction> transactionIterator = transactionList.iterator(); transactionIterator.hasNext();)
{
TransactionImpl transaction = transactionIterator.next();
Transaction transaction = transactionIterator.next();
long senderId = transaction.getSenderId();
if(transaction.getMessage() != null && transaction.getAmountNQT() == 0 && limitMap.containsKey(senderId))
{
Expand Down
2 changes: 1 addition & 1 deletion src/java/nxt/Nxt.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public final class Nxt {

public static final String VERSION = "1.2.8m";
public static final String VERSION = "1.2.8mu";
public static final String APPLICATION = "NRS";

private static volatile Time time = new Time.EpochTime();
Expand Down
5 changes: 3 additions & 2 deletions src/java/nxt/TransactionProcessorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ public void run() {

if(numTransactions > Constants.NUM_UNCONFIRMED_TRANSACTIONS_INVESTIGATE) //Something fishy seems to be happening. Investigate
{
List<TransactionImpl> discardedTransactions = DDosProtection.sanitizeTransactionList(unconfirmedTransactions, "removeUnconfirmedTransactionsThread");
//TODO: Cleanup transaction interface/ transactionimpl usage
List<TransactionImpl> discardedTransactions = (List<TransactionImpl>)DDosProtection.sanitizeTransactionList(unconfirmedTransactions, "removeUnconfirmedTransactionsThread");

if(discardedTransactions.size() > 0)
{
Expand Down Expand Up @@ -214,7 +215,7 @@ public void run() {
transactionList.add(transaction);
}
}

DDosProtection.sanitizeTransactionList(transactionList, "Transaction rebroadcaster");
if (transactionList.size() > 0) {
Peers.rebroadcastTransactions(transactionList);
}
Expand Down
17 changes: 10 additions & 7 deletions src/java/nxt/peer/PeerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,6 @@ public JSONObject send(final JSONStreamAware request) {
String log = null;
boolean showLog = false;
HttpURLConnection connection = null;

String txt = request.toString();
if(txt.length() > 250000)
{
Logger.logDebugMessage("About to upload a message that is " + txt.length() + " characters long");
Logger.logDebugMessage(txt);
}

try {

Expand Down Expand Up @@ -339,8 +332,18 @@ public JSONObject send(final JSONStreamAware request) {
try (Writer writer = new BufferedWriter(new OutputStreamWriter(cos, "UTF-8"))) {
request.writeJSONString(writer);
}
long uploadVolume = cos.getCount();
if(uploadVolume > 250000)
{
Logger.logDebugMessage("About to upload a message that is " + uploadVolume + " characters long");
}



updateUploadedVolume(cos.getCount());



if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
CountingInputStream cis = new CountingInputStream(connection.getInputStream());
InputStream responseStream = cis;
Expand Down

0 comments on commit 803c8de

Please sign in to comment.