Some fixes for the new Kotlin based version of Jabit.

This commit is contained in:
Christian Basler 2017-07-08 19:48:14 +02:00
parent 1a52af880d
commit e362cb1251
3 changed files with 48 additions and 57 deletions

View File

@ -27,11 +27,9 @@ import ch.dissem.bitmessage.extensions.pow.ProofOfWorkRequest;
import ch.dissem.bitmessage.ports.CustomCommandHandler; import ch.dissem.bitmessage.ports.CustomCommandHandler;
import ch.dissem.bitmessage.ports.ProofOfWorkEngine; import ch.dissem.bitmessage.ports.ProofOfWorkEngine;
import ch.dissem.bitmessage.server.repository.ServerProofOfWorkRepository; import ch.dissem.bitmessage.server.repository.ServerProofOfWorkRepository;
import ch.dissem.bitmessage.utils.UnixTime;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Timer; import java.util.Timer;
@ -81,7 +79,6 @@ public class ProofOfWorkRequestHandler implements CustomCommandHandler, Internal
@Override @Override
public MessagePayload handle(CustomMessage message) { public MessagePayload handle(CustomMessage message) {
try {
CryptoCustomMessage<ProofOfWorkRequest> cryptoMessage = CryptoCustomMessage.read(message, CryptoCustomMessage<ProofOfWorkRequest> cryptoMessage = CryptoCustomMessage.read(message,
ProofOfWorkRequest::read); ProofOfWorkRequest::read);
ProofOfWorkRequest request = decrypt(cryptoMessage); ProofOfWorkRequest request = decrypt(cryptoMessage);
@ -118,9 +115,6 @@ public class ProofOfWorkRequestHandler implements CustomCommandHandler, Internal
} }
} }
return null; return null;
} catch (IOException e) {
return CustomMessage.error(e.getMessage());
}
} }
private BitmessageAddress getIdentity() { private BitmessageAddress getIdentity() {
@ -148,8 +142,6 @@ public class ProofOfWorkRequestHandler implements CustomCommandHandler, Internal
try { try {
return cryptoMessage.decrypt(key); return cryptoMessage.decrypt(key);
} catch (DecryptionFailedException ignore) { } catch (DecryptionFailedException ignore) {
} catch (IOException e) {
throw new RuntimeException(e);
} }
} }
return null; return null;

View File

@ -25,7 +25,10 @@ import com.google.zxing.qrcode.encoder.QRCode;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.*; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.Scanner; import java.util.Scanner;
import java.util.Set; import java.util.Set;
@ -91,17 +94,13 @@ public class Utils {
if (address.getAlias() != null) { if (address.getAlias() != null) {
link.append("?label=").append(address.getAlias()); link.append("?label=").append(address.getAlias());
} }
if (address.getPubkey() != null) {
link.append(address.getAlias() == null ? '?' : '&');
ByteArrayOutputStream pubkey = new ByteArrayOutputStream();
try {
address.getPubkey().writeUnencrypted(pubkey);
} catch (IOException e) {
throw new RuntimeException(e);
}
// This makes the QR code quite big, so it's not active. But sometimes it might be useful: // This makes the QR code quite big, so it's not active. But sometimes it might be useful:
// if (address.getPubkey() != null) {
// link.append(address.getAlias() == null ? '?' : '&');
// ByteArrayOutputStream pubkey = new ByteArrayOutputStream();
// address.getPubkey().writeUnencrypted(pubkey);
// link.append("pubkey=").append(Base64.getUrlEncoder().encodeToString(pubkey.toByteArray())); // link.append("pubkey=").append(Base64.getUrlEncoder().encodeToString(pubkey.toByteArray()));
} // }
QRCode code; QRCode code;
try { try {
code = Encoder.encode(link.toString(), ErrorCorrectionLevel.L, null); code = Encoder.encode(link.toString(), ErrorCorrectionLevel.L, null);

View File

@ -118,7 +118,7 @@ public class ServerProofOfWorkRepository extends JdbcHelper {
try (Connection connection = config.getConnection()) { try (Connection connection = config.getConnection()) {
PreparedStatement ps = connection.prepareStatement( PreparedStatement ps = connection.prepareStatement(
"DELETE FROM ProofOfWorkTask WHERE timestamp < ?"); "DELETE FROM ProofOfWorkTask WHERE timestamp < ?");
ps.setLong(1, UnixTime.now(-ageInSeconds)); ps.setLong(1, UnixTime.now() - ageInSeconds);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);