Fixed NullPointerException
This commit is contained in:
parent
956ed61b14
commit
239c6ec7f4
@ -96,7 +96,7 @@ public class ObjectMessage implements MessagePayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public InventoryVector getInventoryVector() {
|
public InventoryVector getInventoryVector() {
|
||||||
return new InventoryVector(
|
return InventoryVector.fromHash(
|
||||||
Bytes.truncate(cryptography().doubleSha512(nonce, getPayloadBytesWithoutNonce()), 32)
|
Bytes.truncate(cryptography().doubleSha512(nonce, getPayloadBytesWithoutNonce()), 32)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -52,10 +52,19 @@ public class InventoryVector implements Streamable, Serializable {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryVector(byte[] hash) {
|
private InventoryVector(byte[] hash) {
|
||||||
|
if (hash == null) throw new IllegalArgumentException("hash must not be null");
|
||||||
this.hash = hash;
|
this.hash = hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static InventoryVector fromHash(byte[] hash) {
|
||||||
|
if (hash == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return new InventoryVector(hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(OutputStream out) throws IOException {
|
public void write(OutputStream out) throws IOException {
|
||||||
out.write(hash);
|
out.write(hash);
|
||||||
|
@ -184,7 +184,7 @@ public class Message implements ExtendedEncoding.ExtendedType {
|
|||||||
MPArray<MPBinary> parents = (MPArray<MPBinary>) map.get(mp("parents"));
|
MPArray<MPBinary> parents = (MPArray<MPBinary>) map.get(mp("parents"));
|
||||||
if (parents != null) {
|
if (parents != null) {
|
||||||
for (MPBinary parent : parents) {
|
for (MPBinary parent : parents) {
|
||||||
builder.addParent(new InventoryVector(parent.getValue()));
|
builder.addParent(InventoryVector.fromHash(parent.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -105,7 +105,7 @@ public class Vote implements ExtendedEncoding.ExtendedType {
|
|||||||
Vote.Builder builder = new Vote.Builder();
|
Vote.Builder builder = new Vote.Builder();
|
||||||
MPType<?> msgId = map.get(mp("msgId"));
|
MPType<?> msgId = map.get(mp("msgId"));
|
||||||
if (msgId instanceof MPBinary) {
|
if (msgId instanceof MPBinary) {
|
||||||
builder.msgId(new InventoryVector(((MPBinary) msgId).getValue()));
|
builder.msgId(InventoryVector.fromHash(((MPBinary) msgId).getValue()));
|
||||||
}
|
}
|
||||||
builder.vote(str(map.get(mp("vote"))));
|
builder.vote(str(map.get(mp("vote"))));
|
||||||
return new Vote(builder);
|
return new Vote(builder);
|
||||||
|
@ -103,8 +103,10 @@ class V3MessageFactory {
|
|||||||
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
|
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
|
||||||
payload = Factory.getObjectPayload(objectType, version, stream, dataStream, data.length);
|
payload = Factory.getObjectPayload(objectType, version, stream, dataStream, data.length);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (LOG.isTraceEnabled()) {
|
||||||
LOG.trace("Could not parse object payload - using generic payload instead", e);
|
LOG.trace("Could not parse object payload - using generic payload instead", e);
|
||||||
LOG.info(Strings.hex(data).toString());
|
LOG.trace(Strings.hex(data).toString());
|
||||||
|
}
|
||||||
payload = new GenericPayload(version, stream, data);
|
payload = new GenericPayload(version, stream, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +167,7 @@ class V3MessageFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static InventoryVector parseInventoryVector(InputStream stream) throws IOException {
|
private static InventoryVector parseInventoryVector(InputStream stream) throws IOException {
|
||||||
return new InventoryVector(Decode.bytes(stream, 32));
|
return InventoryVector.fromHash(Decode.bytes(stream, 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static NetworkAddress parseAddress(InputStream stream, boolean light) throws IOException {
|
private static NetworkAddress parseAddress(InputStream stream, boolean light) throws IOException {
|
||||||
|
@ -72,7 +72,7 @@ public class BitmessageContextTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item getItem(byte[] initialHash) {
|
public Item getItem(byte[] initialHash) {
|
||||||
return items.get(new InventoryVector(initialHash));
|
return items.get(InventoryVector.fromHash(initialHash));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -86,12 +86,12 @@ public class BitmessageContextTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putObject(Item item) {
|
public void putObject(Item item) {
|
||||||
items.put(new InventoryVector(cryptography().getInitialHash(item.object)), item);
|
items.put(InventoryVector.fromHash(cryptography().getInitialHash(item.object)), item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void putObject(ObjectMessage object, long nonceTrialsPerByte, long extraBytes) {
|
public void putObject(ObjectMessage object, long nonceTrialsPerByte, long extraBytes) {
|
||||||
items.put(new InventoryVector(cryptography().getInitialHash(object)), new Item(object, nonceTrialsPerByte, extraBytes));
|
items.put(InventoryVector.fromHash(cryptography().getInitialHash(object)), new Item(object, nonceTrialsPerByte, extraBytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,7 +66,7 @@ public class TestUtils {
|
|||||||
public static InventoryVector randomInventoryVector() {
|
public static InventoryVector randomInventoryVector() {
|
||||||
byte[] bytes = new byte[32];
|
byte[] bytes = new byte[32];
|
||||||
RANDOM.nextBytes(bytes);
|
RANDOM.nextBytes(bytes);
|
||||||
return new InventoryVector(bytes);
|
return InventoryVector.fromHash(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InputStream getResource(String resourceName) {
|
public static InputStream getResource(String resourceName) {
|
||||||
|
@ -69,7 +69,7 @@ public class JdbcInventory extends JdbcHelper implements Inventory {
|
|||||||
"WHERE expires > " + now(-5 * MINUTE) + " AND stream = " + stream)
|
"WHERE expires > " + now(-5 * MINUTE) + " AND stream = " + stream)
|
||||||
) {
|
) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
result.put(new InventoryVector(rs.getBytes("hash")), rs.getLong("expires"));
|
result.put(InventoryVector.fromHash(rs.getBytes("hash")), rs.getLong("expires"));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOG.error(e.getMessage(), e);
|
LOG.error(e.getMessage(), e);
|
||||||
|
@ -110,7 +110,7 @@ public class JdbcMessageRepository extends AbstractMessageRepository implements
|
|||||||
Plaintext.Builder builder = Plaintext.readWithoutSignature(type, data);
|
Plaintext.Builder builder = Plaintext.readWithoutSignature(type, data);
|
||||||
long id = rs.getLong("id");
|
long id = rs.getLong("id");
|
||||||
builder.id(id);
|
builder.id(id);
|
||||||
builder.IV(new InventoryVector(iv));
|
builder.IV(InventoryVector.fromHash(iv));
|
||||||
builder.from(ctx.getAddressRepository().getAddress(rs.getString("sender")));
|
builder.from(ctx.getAddressRepository().getAddress(rs.getString("sender")));
|
||||||
builder.to(ctx.getAddressRepository().getAddress(rs.getString("recipient")));
|
builder.to(ctx.getAddressRepository().getAddress(rs.getString("recipient")));
|
||||||
builder.ackData(rs.getBytes("ack_data"));
|
builder.ackData(rs.getBytes("ack_data"));
|
||||||
|
Loading…
Reference in New Issue
Block a user