Code cleanup
This commit is contained in:
parent
4dd639e651
commit
9f1e0057c9
@ -25,6 +25,7 @@ import ch.dissem.bitmessage.entity.payload.Pubkey.Feature;
|
|||||||
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.exception.DecryptionFailedException;
|
import ch.dissem.bitmessage.exception.DecryptionFailedException;
|
||||||
import ch.dissem.bitmessage.factory.Factory;
|
import ch.dissem.bitmessage.factory.Factory;
|
||||||
import ch.dissem.bitmessage.ports.*;
|
import ch.dissem.bitmessage.ports.*;
|
||||||
@ -119,7 +120,7 @@ public class BitmessageContext {
|
|||||||
|
|
||||||
public void addDistributedMailingList(String address, String alias) {
|
public void addDistributedMailingList(String address, String alias) {
|
||||||
// TODO
|
// TODO
|
||||||
throw new RuntimeException("not implemented");
|
throw new ApplicationException("not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcast(final BitmessageAddress from, final String subject, final String message) {
|
public void broadcast(final BitmessageAddress from, final String subject, final String message) {
|
||||||
@ -187,7 +188,7 @@ public class BitmessageContext {
|
|||||||
case BROADCAST:
|
case BROADCAST:
|
||||||
return Factory.getBroadcast(msg);
|
return Factory.getBroadcast(msg);
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unknown message type " + msg.getType());
|
throw new ApplicationException("Unknown message type " + msg.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ class DefaultMessageListener implements NetworkHandler.MessageListener {
|
|||||||
address.setPubkey(pubkey);
|
address.setPubkey(pubkey);
|
||||||
LOG.info("Got pubkey for contact " + address);
|
LOG.info("Got pubkey for contact " + address);
|
||||||
ctx.getAddressRepository().save(address);
|
ctx.getAddressRepository().save(address);
|
||||||
List<Plaintext> messages = ctx.getMessageRepository().findMessages(Plaintext.Status.PUBKEY_REQUESTED, address);
|
List<Plaintext> messages = ctx.getMessageRepository().findMessages(PUBKEY_REQUESTED, address);
|
||||||
LOG.info("Sending " + messages.size() + " messages for contact " + address);
|
LOG.info("Sending " + messages.size() + " messages for contact " + address);
|
||||||
for (Plaintext msg : messages) {
|
for (Plaintext msg : messages) {
|
||||||
msg.setStatus(DOING_PROOF_OF_WORK);
|
msg.setStatus(DOING_PROOF_OF_WORK);
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package ch.dissem.bitmessage.entity;
|
package ch.dissem.bitmessage.entity;
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.utils.AccessCounter;
|
import ch.dissem.bitmessage.utils.AccessCounter;
|
||||||
import ch.dissem.bitmessage.utils.Encode;
|
import ch.dissem.bitmessage.utils.Encode;
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ public class CustomMessage implements MessagePayload {
|
|||||||
write(out);
|
write(out);
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,7 +78,7 @@ public class CustomMessage implements MessagePayload {
|
|||||||
Encode.varString(command, out);
|
Encode.varString(command, out);
|
||||||
out.write(data);
|
out.write(data);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Tried to write custom message without data. " +
|
throw new ApplicationException("Tried to write custom message without data. " +
|
||||||
"Programmer: did you forget to override #write()?");
|
"Programmer: did you forget to override #write()?");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,7 +91,7 @@ public class CustomMessage implements MessagePayload {
|
|||||||
try {
|
try {
|
||||||
return new CustomMessage(COMMAND_ERROR, message.getBytes("UTF-8"));
|
return new CustomMessage(COMMAND_ERROR, message.getBytes("UTF-8"));
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package ch.dissem.bitmessage.entity;
|
|||||||
|
|
||||||
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.factory.Factory;
|
import ch.dissem.bitmessage.factory.Factory;
|
||||||
import ch.dissem.bitmessage.utils.Decode;
|
import ch.dissem.bitmessage.utils.Decode;
|
||||||
import ch.dissem.bitmessage.utils.Encode;
|
import ch.dissem.bitmessage.utils.Encode;
|
||||||
@ -111,9 +112,9 @@ public class Plaintext implements Streamable {
|
|||||||
|
|
||||||
public void setTo(BitmessageAddress to) {
|
public void setTo(BitmessageAddress to) {
|
||||||
if (this.to.getVersion() != 0)
|
if (this.to.getVersion() != 0)
|
||||||
throw new RuntimeException("Correct address already set");
|
throw new IllegalStateException("Correct address already set");
|
||||||
if (!Arrays.equals(this.to.getRipe(), to.getRipe())) {
|
if (!Arrays.equals(this.to.getRipe(), to.getRipe())) {
|
||||||
throw new RuntimeException("RIPEs don't match");
|
throw new IllegalArgumentException("RIPEs don't match");
|
||||||
}
|
}
|
||||||
this.to = to;
|
this.to = to;
|
||||||
}
|
}
|
||||||
@ -223,7 +224,7 @@ public class Plaintext implements Streamable {
|
|||||||
}
|
}
|
||||||
return text;
|
return text;
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -402,7 +403,7 @@ public class Plaintext implements Streamable {
|
|||||||
this.encoding = Encoding.SIMPLE.getCode();
|
this.encoding = Encoding.SIMPLE.getCode();
|
||||||
this.message = ("Subject:" + subject + '\n' + "Body:" + message).getBytes("UTF-8");
|
this.message = ("Subject:" + subject + '\n' + "Body:" + message).getBytes("UTF-8");
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package ch.dissem.bitmessage.entity.valueobject;
|
|||||||
|
|
||||||
import ch.dissem.bitmessage.entity.Streamable;
|
import ch.dissem.bitmessage.entity.Streamable;
|
||||||
import ch.dissem.bitmessage.entity.payload.Pubkey;
|
import ch.dissem.bitmessage.entity.payload.Pubkey;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.factory.Factory;
|
import ch.dissem.bitmessage.factory.Factory;
|
||||||
import ch.dissem.bitmessage.utils.Bytes;
|
import ch.dissem.bitmessage.utils.Bytes;
|
||||||
import ch.dissem.bitmessage.utils.Decode;
|
import ch.dissem.bitmessage.utils.Decode;
|
||||||
@ -71,7 +72,7 @@ public class PrivateKey implements Streamable {
|
|||||||
this.pubkey = security().createPubkey(version, stream, privateSigningKey, privateEncryptionKey,
|
this.pubkey = security().createPubkey(version, stream, privateSigningKey, privateEncryptionKey,
|
||||||
nonceTrialsPerByte, extraBytes, features);
|
nonceTrialsPerByte, extraBytes, features);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,4 +23,8 @@ public class ApplicationException extends RuntimeException {
|
|||||||
public ApplicationException(Throwable cause) {
|
public ApplicationException(Throwable cause) {
|
||||||
super(cause);
|
super(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ApplicationException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package ch.dissem.bitmessage.ports;
|
package ch.dissem.bitmessage.ports;
|
||||||
|
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.utils.Bytes;
|
import ch.dissem.bitmessage.utils.Bytes;
|
||||||
|
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@ -37,7 +38,7 @@ public class SimplePOWEngine implements ProofOfWorkEngine {
|
|||||||
try {
|
try {
|
||||||
mda = MessageDigest.getInstance("SHA-512");
|
mda = MessageDigest.getInstance("SHA-512");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
inc(nonce);
|
inc(nonce);
|
||||||
|
@ -20,12 +20,10 @@ import ch.dissem.bitmessage.cryptography.bc.BouncyCryptography;
|
|||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||||
import ch.dissem.bitmessage.entity.ObjectMessage;
|
import ch.dissem.bitmessage.entity.ObjectMessage;
|
||||||
import ch.dissem.bitmessage.entity.Plaintext;
|
import ch.dissem.bitmessage.entity.Plaintext;
|
||||||
import ch.dissem.bitmessage.entity.payload.GetPubkey;
|
|
||||||
import ch.dissem.bitmessage.entity.payload.Msg;
|
import ch.dissem.bitmessage.entity.payload.Msg;
|
||||||
import ch.dissem.bitmessage.ports.*;
|
import ch.dissem.bitmessage.ports.*;
|
||||||
import ch.dissem.bitmessage.utils.Singleton;
|
import ch.dissem.bitmessage.utils.Singleton;
|
||||||
import ch.dissem.bitmessage.utils.TestUtils;
|
import ch.dissem.bitmessage.utils.TestUtils;
|
||||||
import org.hamcrest.CoreMatchers;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
@ -39,6 +37,7 @@ import static org.junit.Assert.assertThat;
|
|||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Matchers.isNull;
|
import static org.mockito.Matchers.isNull;
|
||||||
|
import static org.mockito.Mockito.anyLong;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,6 +21,7 @@ import ch.dissem.bitmessage.entity.CustomMessage;
|
|||||||
import ch.dissem.bitmessage.entity.Streamable;
|
import ch.dissem.bitmessage.entity.Streamable;
|
||||||
import ch.dissem.bitmessage.entity.payload.CryptoBox;
|
import ch.dissem.bitmessage.entity.payload.CryptoBox;
|
||||||
import ch.dissem.bitmessage.entity.payload.Pubkey;
|
import ch.dissem.bitmessage.entity.payload.Pubkey;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.exception.DecryptionFailedException;
|
import ch.dissem.bitmessage.exception.DecryptionFailedException;
|
||||||
import ch.dissem.bitmessage.factory.Factory;
|
import ch.dissem.bitmessage.factory.Factory;
|
||||||
import ch.dissem.bitmessage.utils.Encode;
|
import ch.dissem.bitmessage.utils.Encode;
|
||||||
@ -134,9 +135,9 @@ public class CryptoCustomMessage<T extends Streamable> extends CustomMessage {
|
|||||||
return read;
|
return read;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkSignature(Pubkey pubkey) throws IOException, RuntimeException {
|
public void checkSignature(Pubkey pubkey) throws IOException, IllegalStateException {
|
||||||
if (!security().isSignatureValid(out.toByteArray(), varBytes(wrapped), pubkey)) {
|
if (!security().isSignatureValid(out.toByteArray(), varBytes(wrapped), pubkey)) {
|
||||||
throw new RuntimeException("Signature check failed");
|
throw new IllegalStateException("Signature check failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -252,6 +252,7 @@ class Connection {
|
|||||||
case CUSTOM:
|
case CUSTOM:
|
||||||
case VERACK:
|
case VERACK:
|
||||||
case VERSION:
|
case VERSION:
|
||||||
|
default:
|
||||||
throw new RuntimeException("Unexpectedly received '" + messagePayload.getCommand() + "' command");
|
throw new RuntimeException("Unexpectedly received '" + messagePayload.getCommand() + "' command");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import ch.dissem.bitmessage.entity.BitmessageAddress;
|
|||||||
import ch.dissem.bitmessage.entity.Plaintext;
|
import ch.dissem.bitmessage.entity.Plaintext;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.ports.MessageRepository;
|
import ch.dissem.bitmessage.ports.MessageRepository;
|
||||||
import ch.dissem.bitmessage.utils.Strings;
|
import ch.dissem.bitmessage.utils.Strings;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -53,7 +54,7 @@ public class JdbcMessageRepository extends JdbcHelper implements MessageReposito
|
|||||||
result.add(getLabel(rs));
|
result.add(getLabel(rs));
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -118,7 +119,7 @@ public class JdbcMessageRepository extends JdbcHelper implements MessageReposito
|
|||||||
case 1:
|
case 1:
|
||||||
return plaintexts.get(0);
|
return plaintexts.get(0);
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("This shouldn't happen, found " + plaintexts.size() +
|
throw new ApplicationException("This shouldn't happen, found " + plaintexts.size() +
|
||||||
" messages, one or none was expected");
|
" messages, one or none was expected");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,10 +226,10 @@ public class JdbcMessageRepository extends JdbcHelper implements MessageReposito
|
|||||||
} catch (SQLException e1) {
|
} catch (SQLException e1) {
|
||||||
LOG.debug(e1.getMessage(), e);
|
LOG.debug(e1.getMessage(), e);
|
||||||
}
|
}
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ package ch.dissem.bitmessage.wif;
|
|||||||
|
|
||||||
import ch.dissem.bitmessage.BitmessageContext;
|
import ch.dissem.bitmessage.BitmessageContext;
|
||||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.utils.Base58;
|
import ch.dissem.bitmessage.utils.Base58;
|
||||||
import org.ini4j.Ini;
|
import org.ini4j.Ini;
|
||||||
import org.ini4j.Profile;
|
import org.ini4j.Profile;
|
||||||
@ -95,7 +96,7 @@ public class WifExporter {
|
|||||||
try {
|
try {
|
||||||
ini.store(writer);
|
ini.store(writer);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
return writer.toString();
|
return writer.toString();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user