Synchronisation API and related refactorings / improvements

-> lets you synchronize with the Bitmessage network without staying connected
This commit is contained in:
2015-10-07 21:50:41 +02:00
parent c3fdee79ca
commit f9ff22bebe
13 changed files with 154 additions and 49 deletions

View File

@ -24,7 +24,6 @@ import ch.dissem.bitmessage.ports.Inventory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.sql.*;
import java.util.LinkedList;
import java.util.List;
@ -139,6 +138,23 @@ public class JdbcInventory extends JdbcHelper implements Inventory {
}
}
@Override
public boolean contains(ObjectMessage object) {
try (Connection connection = config.getConnection()) {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT count(1) FROM Inventory WHERE hash = X'"
+ object.getInventoryVector() + "'");
if (rs.next()) {
return rs.getInt(1) > 0;
} else {
throw new RuntimeException("Couldn't query if inventory contains " + object.getInventoryVector());
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
@Override
public void cleanup() {
try (Connection connection = config.getConnection()) {