Skip to content

Commit

Permalink
Dash support: Ignore non-bitcoin messages when allowMoreInventoryType…
Browse files Browse the repository at this point in the history
…s() and allowMoreMessages() is on.
  • Loading branch information
oscarguindzberg committed Dec 20, 2018
1 parent f31daee commit 5b35c84
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions core/src/main/java/org/bitcoinj/core/BitcoinSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ private Message makeMessage(String command, int length, byte[] payloadBytes, byt
return new UTXOsMessage(params, payloadBytes);
} else if (command.equals("getutxos")) {
return new GetUTXOsMessage(params, payloadBytes);
} else if(params.allowMoreMessages()) {
return new IgnoreThisMessage(params);
} else {
log.warn("No support for deserializing message with name {}", command);
return new UnknownMessage(params, command, payloadBytes);
Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/org/bitcoinj/core/IgnoreThisMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.bitcoinj.core;

/**
* Created by Hash Engineering on 6/26/2017.
*
* This is a wrapper to allow a message to be ignored that bitcoinj
* will not process. This will prevent the peer from being rejected.
*/
public class IgnoreThisMessage extends EmptyMessage {

public IgnoreThisMessage(NetworkParameters params) {
super(params);
length = 0;
}
}
12 changes: 11 additions & 1 deletion core/src/main/java/org/bitcoinj/core/ListMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.bitcoinj.core;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
Expand All @@ -30,6 +33,7 @@
*/
public abstract class ListMessage extends Message {

private static final Logger log = LoggerFactory.getLogger(PeerGroup.class);
private long arrayLen;
// For some reason the compiler complains if this is inside InventoryItem
protected List<InventoryItem> items;
Expand Down Expand Up @@ -99,7 +103,13 @@ protected void parse() throws ProtocolException {
type = InventoryItem.Type.FilteredBlock;
break;
default:
throw new ProtocolException("Unknown CInv type: " + typeCode);
//
// Allow other inventory types for some coins.
//
if (!params.allowMoreInventoryTypes())
throw new ProtocolException("Unknown CInv type: " + typeCode);
//log.info("Unknown CInv type: " + typeCode);
continue;
}
InventoryItem item = new InventoryItem(type, readHash());
items.add(item);
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/bitcoinj/core/NetworkParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -539,4 +539,7 @@ public int getBitcoinProtocolVersion() {
return bitcoinProtocol;
}
}

public boolean allowMoreInventoryTypes() { return false; }
public boolean allowMoreMessages() { return false;}
}

0 comments on commit 5b35c84

Please sign in to comment.