Code cleanup
This commit is contained in:
parent
0a00a0a1b4
commit
f6add5b2ea
@ -416,7 +416,8 @@ public class BitmessageContext {
|
|||||||
customCommandHandler = new CustomCommandHandler() {
|
customCommandHandler = new CustomCommandHandler() {
|
||||||
@Override
|
@Override
|
||||||
public MessagePayload handle(CustomMessage request) {
|
public MessagePayload handle(CustomMessage request) {
|
||||||
throw new RuntimeException("Received custom request, but no custom command handler configured.");
|
throw new IllegalStateException(
|
||||||
|
"Received custom request, but no custom command handler configured.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package ch.dissem.bitmessage.entity.payload;
|
package ch.dissem.bitmessage.entity.payload;
|
||||||
|
|
||||||
import ch.dissem.bitmessage.entity.Streamable;
|
import ch.dissem.bitmessage.entity.Streamable;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.exception.DecryptionFailedException;
|
import ch.dissem.bitmessage.exception.DecryptionFailedException;
|
||||||
import ch.dissem.bitmessage.utils.*;
|
import ch.dissem.bitmessage.utils.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -123,7 +124,7 @@ public class CryptoBox implements Streamable {
|
|||||||
writeWithoutMAC(macData);
|
writeWithoutMAC(macData);
|
||||||
return security().mac(key_m, macData.toByteArray());
|
return security().mac(key_m, macData.toByteArray());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
package ch.dissem.bitmessage.utils;
|
package ch.dissem.bitmessage.utils;
|
||||||
|
|
||||||
import ch.dissem.bitmessage.exception.AddressFormatException;
|
import ch.dissem.bitmessage.exception.AddressFormatException;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
|
||||||
@ -83,7 +84,7 @@ public class Base58 {
|
|||||||
try {
|
try {
|
||||||
return new String(output, "US-ASCII");
|
return new String(output, "US-ASCII");
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e); // Cannot happen.
|
throw new ApplicationException(e); // Cannot happen.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,8 @@ public class BitmessageContextTest {
|
|||||||
.putObject(object(BROADCAST), eq(1000L), eq(1000L));
|
.putObject(object(BROADCAST), eq(1000L), eq(1000L));
|
||||||
verify(ctx.internals().getProofOfWorkEngine())
|
verify(ctx.internals().getProofOfWorkEngine())
|
||||||
.calculateNonce(any(byte[].class), any(byte[].class), any(ProofOfWorkEngine.Callback.class));
|
.calculateNonce(any(byte[].class), any(byte[].class), any(ProofOfWorkEngine.Callback.class));
|
||||||
verify(ctx.messages(), timeout(10000).atLeastOnce()).save(MessageMatchers.plaintext(Plaintext.Type.BROADCAST));
|
verify(ctx.messages(), timeout(10000).atLeastOnce())
|
||||||
|
.save(MessageMatchers.plaintext(Plaintext.Type.BROADCAST));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
@ -55,44 +55,56 @@ public class BitmessageAddressTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateAddress() {
|
public void ensureIdentityCanBeCreated() {
|
||||||
BitmessageAddress address = new BitmessageAddress(new PrivateKey(false, 1, 1000, 1000, DOES_ACK));
|
BitmessageAddress address = new BitmessageAddress(new PrivateKey(false, 1, 1000, 1000, DOES_ACK));
|
||||||
assertNotNull(address.getPubkey());
|
assertNotNull(address.getPubkey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testV2PubkeyImport() throws IOException {
|
public void ensureV2PubkeyCanBeImported() throws IOException {
|
||||||
ObjectMessage object = TestUtils.loadObjectMessage(2, "V2Pubkey.payload");
|
ObjectMessage object = TestUtils.loadObjectMessage(2, "V2Pubkey.payload");
|
||||||
Pubkey pubkey = (Pubkey) object.getPayload();
|
Pubkey pubkey = (Pubkey) object.getPayload();
|
||||||
BitmessageAddress address = new BitmessageAddress("BM-opWQhvk9xtMFvQA2Kvetedpk8LkbraWHT");
|
BitmessageAddress address = new BitmessageAddress("BM-opWQhvk9xtMFvQA2Kvetedpk8LkbraWHT");
|
||||||
address.setPubkey(pubkey);
|
try {
|
||||||
|
address.setPubkey(pubkey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testV3PubkeyImport() throws IOException {
|
public void ensureV3PubkeyCanBeImported() throws IOException {
|
||||||
BitmessageAddress address = new BitmessageAddress("BM-2D9Vc5rFxxR5vTi53T9gkLfemViHRMVLQZ");
|
BitmessageAddress address = new BitmessageAddress("BM-2D9Vc5rFxxR5vTi53T9gkLfemViHRMVLQZ");
|
||||||
assertArrayEquals(Bytes.fromHex("007402be6e76c3cb87caa946d0c003a3d4d8e1d5"), address.getRipe());
|
assertArrayEquals(Bytes.fromHex("007402be6e76c3cb87caa946d0c003a3d4d8e1d5"), address.getRipe());
|
||||||
|
|
||||||
ObjectMessage object = TestUtils.loadObjectMessage(3, "V3Pubkey.payload");
|
ObjectMessage object = TestUtils.loadObjectMessage(3, "V3Pubkey.payload");
|
||||||
Pubkey pubkey = (Pubkey) object.getPayload();
|
Pubkey pubkey = (Pubkey) object.getPayload();
|
||||||
assertTrue(object.isSignatureValid(pubkey));
|
assertTrue(object.isSignatureValid(pubkey));
|
||||||
address.setPubkey(pubkey);
|
try {
|
||||||
|
address.setPubkey(pubkey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
assertArrayEquals(Bytes.fromHex("007402be6e76c3cb87caa946d0c003a3d4d8e1d5"), pubkey.getRipe());
|
assertArrayEquals(Bytes.fromHex("007402be6e76c3cb87caa946d0c003a3d4d8e1d5"), pubkey.getRipe());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testV4PubkeyImport() throws IOException, DecryptionFailedException {
|
public void ensureV4PubkeyCanBeImported() throws IOException, DecryptionFailedException {
|
||||||
BitmessageAddress address = new BitmessageAddress("BM-2cXxfcSetKnbHJX2Y85rSkaVpsdNUZ5q9h");
|
BitmessageAddress address = new BitmessageAddress("BM-2cXxfcSetKnbHJX2Y85rSkaVpsdNUZ5q9h");
|
||||||
ObjectMessage object = TestUtils.loadObjectMessage(4, "V4Pubkey.payload");
|
ObjectMessage object = TestUtils.loadObjectMessage(4, "V4Pubkey.payload");
|
||||||
object.decrypt(address.getPublicDecryptionKey());
|
object.decrypt(address.getPublicDecryptionKey());
|
||||||
V4Pubkey pubkey = (V4Pubkey) object.getPayload();
|
V4Pubkey pubkey = (V4Pubkey) object.getPayload();
|
||||||
assertTrue(object.isSignatureValid(pubkey));
|
assertTrue(object.isSignatureValid(pubkey));
|
||||||
address.setPubkey(pubkey);
|
try {
|
||||||
|
address.setPubkey(pubkey);
|
||||||
|
} catch (Exception e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testV3AddressImport() throws IOException {
|
public void ensureV3IdentityCanBeImported() throws IOException {
|
||||||
String address_string = "BM-2DAjcCFrqFrp88FUxExhJ9kPqHdunQmiyn";
|
String address_string = "BM-2DAjcCFrqFrp88FUxExhJ9kPqHdunQmiyn";
|
||||||
assertEquals(3, new BitmessageAddress(address_string).getVersion());
|
assertEquals(3, new BitmessageAddress(address_string).getVersion());
|
||||||
assertEquals(1, new BitmessageAddress(address_string).getStream());
|
assertEquals(1, new BitmessageAddress(address_string).getStream());
|
||||||
@ -108,9 +120,17 @@ public class BitmessageAddressTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetSecret() throws IOException {
|
public void ensureV4IdentityCanBeImported() throws IOException {
|
||||||
assertHexEquals("0C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D",
|
assertEquals(4, new BitmessageAddress("BM-2cV5f9EpzaYARxtoruSpa6pDoucSf9ZNke").getVersion());
|
||||||
getSecret("5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ"));
|
byte[] privsigningkey = getSecret("5KMWqfCyJZGFgW6QrnPJ6L9Gatz25B51y7ErgqNr1nXUVbtZbdU");
|
||||||
|
byte[] privencryptionkey = getSecret("5JXXWEuhHQEPk414SzEZk1PHDRi8kCuZd895J7EnKeQSahJPxGz");
|
||||||
|
BitmessageAddress address = new BitmessageAddress(new PrivateKey(privsigningkey, privencryptionkey,
|
||||||
|
security().createPubkey(4, 1, privsigningkey, privencryptionkey, 320, 14000)));
|
||||||
|
assertEquals("BM-2cV5f9EpzaYARxtoruSpa6pDoucSf9ZNke", address.getAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertHexEquals(String hex, byte[] bytes) {
|
||||||
|
assertEquals(hex.toLowerCase(), Strings.hex(bytes).toString().toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] getSecret(String walletImportFormat) throws IOException {
|
private byte[] getSecret(String walletImportFormat) throws IOException {
|
||||||
@ -126,18 +146,4 @@ public class BitmessageAddressTest {
|
|||||||
}
|
}
|
||||||
return Arrays.copyOfRange(bytes, 1, 33);
|
return Arrays.copyOfRange(bytes, 1, 33);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testV4AddressImport() throws IOException {
|
|
||||||
assertEquals(4, new BitmessageAddress("BM-2cV5f9EpzaYARxtoruSpa6pDoucSf9ZNke").getVersion());
|
|
||||||
byte[] privsigningkey = getSecret("5KMWqfCyJZGFgW6QrnPJ6L9Gatz25B51y7ErgqNr1nXUVbtZbdU");
|
|
||||||
byte[] privencryptionkey = getSecret("5JXXWEuhHQEPk414SzEZk1PHDRi8kCuZd895J7EnKeQSahJPxGz");
|
|
||||||
BitmessageAddress address = new BitmessageAddress(new PrivateKey(privsigningkey, privencryptionkey,
|
|
||||||
security().createPubkey(4, 1, privsigningkey, privencryptionkey, 320, 14000)));
|
|
||||||
assertEquals("BM-2cV5f9EpzaYARxtoruSpa6pDoucSf9ZNke", address.getAddress());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertHexEquals(String hex, byte[] bytes) {
|
|
||||||
assertEquals(hex.toLowerCase(), Strings.hex(bytes).toString().toLowerCase());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package ch.dissem.bitmessage.cryptography.bc;
|
|||||||
|
|
||||||
import ch.dissem.bitmessage.entity.payload.Pubkey;
|
import ch.dissem.bitmessage.entity.payload.Pubkey;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.ports.AbstractCryptography;
|
import ch.dissem.bitmessage.ports.AbstractCryptography;
|
||||||
import org.bouncycastle.asn1.x9.X9ECParameters;
|
import org.bouncycastle.asn1.x9.X9ECParameters;
|
||||||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||||
@ -37,6 +38,7 @@ import org.bouncycastle.jce.spec.ECPublicKeySpec;
|
|||||||
import org.bouncycastle.math.ec.ECPoint;
|
import org.bouncycastle.math.ec.ECPoint;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.KeyFactory;
|
import java.security.KeyFactory;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.security.Signature;
|
import java.security.Signature;
|
||||||
@ -109,8 +111,8 @@ public class BouncyCryptography extends AbstractCryptography {
|
|||||||
sig.initVerify(publicKey);
|
sig.initVerify(publicKey);
|
||||||
sig.update(data);
|
sig.update(data);
|
||||||
return sig.verify(signature);
|
return sig.verify(signature);
|
||||||
} catch (Exception e) {
|
} catch (GeneralSecurityException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,8 +135,8 @@ public class BouncyCryptography extends AbstractCryptography {
|
|||||||
sig.initSign(privKey);
|
sig.initSign(privKey);
|
||||||
sig.update(data);
|
sig.update(data);
|
||||||
return sig.sign();
|
return sig.sign();
|
||||||
} catch (Exception e) {
|
} catch (GeneralSecurityException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ package ch.dissem.bitmessage.cryptography.sc;
|
|||||||
|
|
||||||
import ch.dissem.bitmessage.entity.payload.Pubkey;
|
import ch.dissem.bitmessage.entity.payload.Pubkey;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.ports.AbstractCryptography;
|
import ch.dissem.bitmessage.ports.AbstractCryptography;
|
||||||
import org.spongycastle.asn1.x9.X9ECParameters;
|
import org.spongycastle.asn1.x9.X9ECParameters;
|
||||||
import org.spongycastle.crypto.BufferedBlockCipher;
|
import org.spongycastle.crypto.BufferedBlockCipher;
|
||||||
@ -37,6 +38,7 @@ import org.spongycastle.jce.spec.ECPublicKeySpec;
|
|||||||
import org.spongycastle.math.ec.ECPoint;
|
import org.spongycastle.math.ec.ECPoint;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.KeyFactory;
|
import java.security.KeyFactory;
|
||||||
import java.security.PublicKey;
|
import java.security.PublicKey;
|
||||||
import java.security.Signature;
|
import java.security.Signature;
|
||||||
@ -109,8 +111,8 @@ public class SpongyCryptography extends AbstractCryptography {
|
|||||||
sig.initVerify(publicKey);
|
sig.initVerify(publicKey);
|
||||||
sig.update(data);
|
sig.update(data);
|
||||||
return sig.verify(signature);
|
return sig.verify(signature);
|
||||||
} catch (Exception e) {
|
} catch (GeneralSecurityException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,8 +135,8 @@ public class SpongyCryptography extends AbstractCryptography {
|
|||||||
sig.initSign(privKey);
|
sig.initSign(privKey);
|
||||||
sig.update(data);
|
sig.update(data);
|
||||||
return sig.sign();
|
return sig.sign();
|
||||||
} catch (Exception e) {
|
} catch (GeneralSecurityException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ import static org.junit.Assert.assertThat;
|
|||||||
* @author Christian Basler
|
* @author Christian Basler
|
||||||
*/
|
*/
|
||||||
public class SystemTest {
|
public class SystemTest {
|
||||||
|
private static int port = 6000;
|
||||||
|
|
||||||
private BitmessageContext alice;
|
private BitmessageContext alice;
|
||||||
private TestListener aliceListener = new TestListener();
|
private TestListener aliceListener = new TestListener();
|
||||||
private BitmessageAddress aliceIdentity;
|
private BitmessageAddress aliceIdentity;
|
||||||
@ -29,6 +31,8 @@ public class SystemTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
int alicePort = port++;
|
||||||
|
int bobPort = port++;
|
||||||
TTL.msg(5 * MINUTE);
|
TTL.msg(5 * MINUTE);
|
||||||
TTL.getpubkey(5 * MINUTE);
|
TTL.getpubkey(5 * MINUTE);
|
||||||
TTL.pubkey(5 * MINUTE);
|
TTL.pubkey(5 * MINUTE);
|
||||||
@ -38,8 +42,8 @@ public class SystemTest {
|
|||||||
.inventory(new JdbcInventory(aliceDB))
|
.inventory(new JdbcInventory(aliceDB))
|
||||||
.messageRepo(new JdbcMessageRepository(aliceDB))
|
.messageRepo(new JdbcMessageRepository(aliceDB))
|
||||||
.powRepo(new JdbcProofOfWorkRepository(aliceDB))
|
.powRepo(new JdbcProofOfWorkRepository(aliceDB))
|
||||||
.port(6001)
|
.port(alicePort)
|
||||||
.nodeRegistry(new TestNodeRegistry(6002))
|
.nodeRegistry(new TestNodeRegistry(bobPort))
|
||||||
.networkHandler(new DefaultNetworkHandler())
|
.networkHandler(new DefaultNetworkHandler())
|
||||||
.cryptography(new BouncyCryptography())
|
.cryptography(new BouncyCryptography())
|
||||||
.listener(aliceListener)
|
.listener(aliceListener)
|
||||||
@ -53,8 +57,8 @@ public class SystemTest {
|
|||||||
.inventory(new JdbcInventory(bobDB))
|
.inventory(new JdbcInventory(bobDB))
|
||||||
.messageRepo(new JdbcMessageRepository(bobDB))
|
.messageRepo(new JdbcMessageRepository(bobDB))
|
||||||
.powRepo(new JdbcProofOfWorkRepository(bobDB))
|
.powRepo(new JdbcProofOfWorkRepository(bobDB))
|
||||||
.port(6002)
|
.port(bobPort)
|
||||||
.nodeRegistry(new TestNodeRegistry(6001))
|
.nodeRegistry(new TestNodeRegistry(alicePort))
|
||||||
.networkHandler(new DefaultNetworkHandler())
|
.networkHandler(new DefaultNetworkHandler())
|
||||||
.cryptography(new BouncyCryptography())
|
.cryptography(new BouncyCryptography())
|
||||||
.listener(bobListener)
|
.listener(bobListener)
|
||||||
|
@ -21,6 +21,7 @@ import ch.dissem.bitmessage.InternalContext;
|
|||||||
import ch.dissem.bitmessage.entity.*;
|
import ch.dissem.bitmessage.entity.*;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.NetworkAddress;
|
import ch.dissem.bitmessage.entity.valueobject.NetworkAddress;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.exception.InsufficientProofOfWorkException;
|
import ch.dissem.bitmessage.exception.InsufficientProofOfWorkException;
|
||||||
import ch.dissem.bitmessage.exception.NodeException;
|
import ch.dissem.bitmessage.exception.NodeException;
|
||||||
import ch.dissem.bitmessage.factory.Factory;
|
import ch.dissem.bitmessage.factory.Factory;
|
||||||
@ -253,7 +254,7 @@ class Connection {
|
|||||||
case VERACK:
|
case VERACK:
|
||||||
case VERSION:
|
case VERSION:
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unexpectedly received '" + messagePayload.getCommand() + "' command");
|
throw new IllegalStateException("Unexpectedly received '" + messagePayload.getCommand() + "' command");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,6 +387,8 @@ class Connection {
|
|||||||
case SYNC:
|
case SYNC:
|
||||||
activateConnection();
|
activateConnection();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
// NO OP
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG.info("Received unsupported version " + payload.getVersion() + ", disconnecting.");
|
LOG.info("Received unsupported version " + payload.getVersion() + ", disconnecting.");
|
||||||
@ -399,6 +402,7 @@ class Connection {
|
|||||||
break;
|
break;
|
||||||
case CLIENT:
|
case CLIENT:
|
||||||
case SYNC:
|
case SYNC:
|
||||||
|
default:
|
||||||
// NO OP
|
// NO OP
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ import ch.dissem.bitmessage.entity.GetData;
|
|||||||
import ch.dissem.bitmessage.entity.NetworkMessage;
|
import ch.dissem.bitmessage.entity.NetworkMessage;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
import ch.dissem.bitmessage.entity.valueobject.InventoryVector;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.NetworkAddress;
|
import ch.dissem.bitmessage.entity.valueobject.NetworkAddress;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.exception.NodeException;
|
import ch.dissem.bitmessage.exception.NodeException;
|
||||||
import ch.dissem.bitmessage.factory.Factory;
|
import ch.dissem.bitmessage.factory.Factory;
|
||||||
import ch.dissem.bitmessage.ports.NetworkHandler;
|
import ch.dissem.bitmessage.ports.NetworkHandler;
|
||||||
@ -85,7 +86,7 @@ public class DefaultNetworkHandler implements NetworkHandler, ContextHolder {
|
|||||||
pool.execute(connection.getWriter());
|
pool.execute(connection.getWriter());
|
||||||
return reader;
|
return reader;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +107,7 @@ public class DefaultNetworkHandler implements NetworkHandler, ContextHolder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +210,7 @@ public class DefaultNetworkHandler implements NetworkHandler, ContextHolder {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,12 +21,12 @@ import ch.dissem.bitmessage.entity.payload.Pubkey;
|
|||||||
import ch.dissem.bitmessage.entity.payload.V3Pubkey;
|
import ch.dissem.bitmessage.entity.payload.V3Pubkey;
|
||||||
import ch.dissem.bitmessage.entity.payload.V4Pubkey;
|
import ch.dissem.bitmessage.entity.payload.V4Pubkey;
|
||||||
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.factory.Factory;
|
import ch.dissem.bitmessage.factory.Factory;
|
||||||
import ch.dissem.bitmessage.ports.AddressRepository;
|
import ch.dissem.bitmessage.ports.AddressRepository;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -129,8 +129,9 @@ public class JdbcAddressRepository extends JdbcHelper implements AddressReposito
|
|||||||
try (Connection connection = config.getConnection()) {
|
try (Connection connection = config.getConnection()) {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM Address WHERE address='" + address.getAddress() + "'");
|
ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM Address WHERE address='" + address.getAddress() + "'");
|
||||||
rs.next();
|
if (rs.next()) {
|
||||||
return rs.getInt(1) > 0;
|
return rs.getInt(1) > 0;
|
||||||
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOG.error(e.getMessage(), e);
|
LOG.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package ch.dissem.bitmessage.repository;
|
package ch.dissem.bitmessage.repository;
|
||||||
|
|
||||||
import ch.dissem.bitmessage.entity.ObjectMessage;
|
import ch.dissem.bitmessage.entity.ObjectMessage;
|
||||||
|
import ch.dissem.bitmessage.exception.ApplicationException;
|
||||||
import ch.dissem.bitmessage.factory.Factory;
|
import ch.dissem.bitmessage.factory.Factory;
|
||||||
import ch.dissem.bitmessage.ports.ProofOfWorkRepository;
|
import ch.dissem.bitmessage.ports.ProofOfWorkRepository;
|
||||||
import ch.dissem.bitmessage.utils.Strings;
|
import ch.dissem.bitmessage.utils.Strings;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -37,11 +39,11 @@ public class JdbcProofOfWorkRepository extends JdbcHelper implements ProofOfWork
|
|||||||
rs.getLong("extra_bytes")
|
rs.getLong("extra_bytes")
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Object requested that we don't have. Initial hash: " + Strings.hex(initialHash));
|
throw new IllegalArgumentException("Object requested that we don't have. Initial hash: " + Strings.hex(initialHash));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (SQLException e) {
|
||||||
LOG.error(e.getMessage(), e);
|
LOG.error(e.getMessage(), e);
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ public class JdbcProofOfWorkRepository extends JdbcHelper implements ProofOfWork
|
|||||||
return result;
|
return result;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOG.error(e.getMessage(), e);
|
LOG.error(e.getMessage(), e);
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,12 +73,9 @@ public class JdbcProofOfWorkRepository extends JdbcHelper implements ProofOfWork
|
|||||||
ps.setLong(4, nonceTrialsPerByte);
|
ps.setLong(4, nonceTrialsPerByte);
|
||||||
ps.setLong(5, extraBytes);
|
ps.setLong(5, extraBytes);
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
} catch (SQLException e) {
|
} catch (IOException | SQLException e) {
|
||||||
LOG.debug("Error storing object of type " + object.getPayload().getClass().getSimpleName(), e);
|
LOG.debug("Error storing object of type " + object.getPayload().getClass().getSimpleName(), e);
|
||||||
throw new RuntimeException(e);
|
throw new ApplicationException(e);
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.error(e.getMessage(), e);
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user