Fixed NPE
This commit is contained in:
parent
5cf6d308f2
commit
a880a8c10b
@ -69,9 +69,9 @@ public class Plaintext implements Streamable {
|
|||||||
ackData = builder.ackData;
|
ackData = builder.ackData;
|
||||||
if (builder.ackMessage != null && builder.ackMessage.length > 0) {
|
if (builder.ackMessage != null && builder.ackMessage.length > 0) {
|
||||||
ackMessage = Factory.getObjectMessage(
|
ackMessage = Factory.getObjectMessage(
|
||||||
3,
|
3,
|
||||||
new ByteArrayInputStream(builder.ackMessage),
|
new ByteArrayInputStream(builder.ackMessage),
|
||||||
builder.ackMessage.length);
|
builder.ackMessage.length);
|
||||||
}
|
}
|
||||||
signature = builder.signature;
|
signature = builder.signature;
|
||||||
status = builder.status;
|
status = builder.status;
|
||||||
@ -85,25 +85,25 @@ public class Plaintext implements Streamable {
|
|||||||
|
|
||||||
public static Plaintext read(Type type, InputStream in) throws IOException {
|
public static Plaintext read(Type type, InputStream in) throws IOException {
|
||||||
return readWithoutSignature(type, in)
|
return readWithoutSignature(type, in)
|
||||||
.signature(Decode.varBytes(in))
|
.signature(Decode.varBytes(in))
|
||||||
.received(UnixTime.now())
|
.received(UnixTime.now())
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Plaintext.Builder readWithoutSignature(Type type, InputStream in) throws IOException {
|
public static Plaintext.Builder readWithoutSignature(Type type, InputStream in) throws IOException {
|
||||||
long version = Decode.varInt(in);
|
long version = Decode.varInt(in);
|
||||||
return new Builder(type)
|
return new Builder(type)
|
||||||
.addressVersion(version)
|
.addressVersion(version)
|
||||||
.stream(Decode.varInt(in))
|
.stream(Decode.varInt(in))
|
||||||
.behaviorBitfield(Decode.int32(in))
|
.behaviorBitfield(Decode.int32(in))
|
||||||
.publicSigningKey(Decode.bytes(in, 64))
|
.publicSigningKey(Decode.bytes(in, 64))
|
||||||
.publicEncryptionKey(Decode.bytes(in, 64))
|
.publicEncryptionKey(Decode.bytes(in, 64))
|
||||||
.nonceTrialsPerByte(version >= 3 ? Decode.varInt(in) : 0)
|
.nonceTrialsPerByte(version >= 3 ? Decode.varInt(in) : 0)
|
||||||
.extraBytes(version >= 3 ? Decode.varInt(in) : 0)
|
.extraBytes(version >= 3 ? Decode.varInt(in) : 0)
|
||||||
.destinationRipe(type == Type.MSG ? Decode.bytes(in, 20) : null)
|
.destinationRipe(type == Type.MSG ? Decode.bytes(in, 20) : null)
|
||||||
.encoding(Decode.varInt(in))
|
.encoding(Decode.varInt(in))
|
||||||
.message(Decode.varBytes(in))
|
.message(Decode.varBytes(in))
|
||||||
.ackMessage(type == Type.MSG ? Decode.varBytes(in) : null);
|
.ackMessage(type == Type.MSG ? Decode.varBytes(in) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InventoryVector getInventoryVector() {
|
public InventoryVector getInventoryVector() {
|
||||||
@ -198,6 +198,7 @@ public class Plaintext implements Streamable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(ByteBuffer buffer, boolean includeSignature) {
|
public void write(ByteBuffer buffer, boolean includeSignature) {
|
||||||
Encode.varInt(from.getVersion(), buffer);
|
Encode.varInt(from.getVersion(), buffer);
|
||||||
Encode.varInt(from.getStream(), buffer);
|
Encode.varInt(from.getStream(), buffer);
|
||||||
@ -279,14 +280,16 @@ public class Plaintext implements Streamable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateNextTry() {
|
public void updateNextTry() {
|
||||||
if (nextTry == null) {
|
if (to != null) {
|
||||||
if (sent != null && to.has(Feature.DOES_ACK)) {
|
if (nextTry == null) {
|
||||||
nextTry = UnixTime.now(+ttl);
|
if (sent != null && to.has(Feature.DOES_ACK)) {
|
||||||
|
nextTry = UnixTime.now(+ttl);
|
||||||
|
retries++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
nextTry = nextTry + (1 << retries) * ttl;
|
||||||
retries++;
|
retries++;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
nextTry = nextTry + (1 << retries) * ttl;
|
|
||||||
retries++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,15 +323,15 @@ public class Plaintext implements Streamable {
|
|||||||
if (o == null || getClass() != o.getClass()) return false;
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
Plaintext plaintext = (Plaintext) o;
|
Plaintext plaintext = (Plaintext) o;
|
||||||
return Objects.equals(encoding, plaintext.encoding) &&
|
return Objects.equals(encoding, plaintext.encoding) &&
|
||||||
Objects.equals(from, plaintext.from) &&
|
Objects.equals(from, plaintext.from) &&
|
||||||
Arrays.equals(message, plaintext.message) &&
|
Arrays.equals(message, plaintext.message) &&
|
||||||
Objects.equals(getAckMessage(), plaintext.getAckMessage()) &&
|
Objects.equals(getAckMessage(), plaintext.getAckMessage()) &&
|
||||||
Arrays.equals(to.getRipe(), plaintext.to.getRipe()) &&
|
Arrays.equals(to == null ? null : to.getRipe(), plaintext.to == null ? null : plaintext.to.getRipe()) &&
|
||||||
Arrays.equals(signature, plaintext.signature) &&
|
Arrays.equals(signature, plaintext.signature) &&
|
||||||
Objects.equals(status, plaintext.status) &&
|
Objects.equals(status, plaintext.status) &&
|
||||||
Objects.equals(sent, plaintext.sent) &&
|
Objects.equals(sent, plaintext.sent) &&
|
||||||
Objects.equals(received, plaintext.received) &&
|
Objects.equals(received, plaintext.received) &&
|
||||||
Objects.equals(labels, plaintext.labels);
|
Objects.equals(labels, plaintext.labels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -582,13 +585,13 @@ public class Plaintext implements Streamable {
|
|||||||
public Plaintext build() {
|
public Plaintext build() {
|
||||||
if (from == null) {
|
if (from == null) {
|
||||||
from = new BitmessageAddress(Factory.createPubkey(
|
from = new BitmessageAddress(Factory.createPubkey(
|
||||||
addressVersion,
|
addressVersion,
|
||||||
stream,
|
stream,
|
||||||
publicSigningKey,
|
publicSigningKey,
|
||||||
publicEncryptionKey,
|
publicEncryptionKey,
|
||||||
nonceTrialsPerByte,
|
nonceTrialsPerByte,
|
||||||
extraBytes,
|
extraBytes,
|
||||||
behaviorBitfield
|
behaviorBitfield
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if (to == null && type != Type.BROADCAST && destinationRipe != null) {
|
if (to == null && type != Type.BROADCAST && destinationRipe != null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user