Distributable JAR build

- connection manager should now be rock stable
- does try to create new connections as long as there are less than eight active connections, which might result in more than eight outgoing connections, but this shouldn't be a problem
- some minor improvements and bug fixes
This commit is contained in:
Christian Basler 2015-06-18 13:41:11 +02:00
parent 1dc4582012
commit 6be8d51f6d
8 changed files with 41 additions and 27 deletions

View File

@ -1,4 +1,10 @@
apply plugin: 'java'
plugins {
id "us.kirchmeier.capsule" version "1.0-rc1"
}
task fatCapsule(type: FatCapsule) {
applicationClass 'ch.dissem.bitmessage.demo.Main'
}
sourceCompatibility = 1.7
version = '0.0.1'

View File

@ -20,8 +20,11 @@ import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "DEBUG");
System.setProperty("org.slf4j.simpleLogger.logFile", "./jabit.log");
if (System.getProperty("org.slf4j.simpleLogger.defaultLogLevel") == null)
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "ERROR");
if (System.getProperty("org.slf4j.simpleLogger.logFile") == null)
System.setProperty("org.slf4j.simpleLogger.logFile", "./jabit.log");
new Application();
}
}

View File

@ -21,6 +21,7 @@ import ch.dissem.bitmessage.entity.ObjectMessage;
import ch.dissem.bitmessage.entity.Plaintext;
import ch.dissem.bitmessage.entity.payload.*;
import ch.dissem.bitmessage.entity.payload.Pubkey.Feature;
import ch.dissem.bitmessage.entity.valueobject.Label;
import ch.dissem.bitmessage.entity.valueobject.PrivateKey;
import ch.dissem.bitmessage.exception.DecryptionFailedException;
import ch.dissem.bitmessage.factory.Factory;
@ -114,6 +115,7 @@ public class BitmessageContext {
0
);
msg.setStatus(SENT);
msg.addLabels(ctx.getMessageRepository().getLabels(Label.Type.BROADCAST, Label.Type.SENT));
ctx.getMessageRepository().save(msg);
}
@ -148,6 +150,7 @@ public class BitmessageContext {
ctx.getExtraBytes(to)
);
msg.setStatus(SENT);
msg.addLabels(ctx.getMessageRepository().getLabels(Label.Type.SENT));
ctx.getMessageRepository().save(msg);
}
}

View File

@ -145,7 +145,7 @@ class DefaultMessageListener implements NetworkHandler.MessageListener {
LOG.warn("Broadcast with IV " + object.getInventoryVector() + " was successfully decrypted, but signature check failed. Ignoring.");
} else {
broadcast.getPlaintext().setStatus(RECEIVED);
broadcast.getPlaintext().addLabels(ctx.getMessageRepository().getLabels(Label.Type.INBOX, Label.Type.UNREAD));
broadcast.getPlaintext().addLabels(ctx.getMessageRepository().getLabels(Label.Type.INBOX, Label.Type.BROADCAST, Label.Type.UNREAD));
broadcast.getPlaintext().setInventoryVector(object.getInventoryVector());
ctx.getMessageRepository().save(broadcast.getPlaintext());
listener.receive(broadcast.getPlaintext());

View File

@ -73,7 +73,8 @@ public class Label {
public enum Type {
INBOX,
DRAFTS,
BROADCAST,
DRAFT,
SENT,
UNREAD,
TRASH

View File

@ -9,7 +9,6 @@ repositories {
dependencies {
compile project(':domain')
compile 'com.google.guava:guava-concurrent:r03'
testCompile 'org.slf4j:slf4j-simple:1.7.12'
testCompile 'junit:junit:4.11'
}

View File

@ -82,32 +82,34 @@ public class NetworkNode implements NetworkHandler, ContextHolder {
@Override
public void run() {
while (!Thread.interrupted()) {
int active = 0;
synchronized (connections) {
for (Iterator<Connection> iterator = connections.iterator(); iterator.hasNext(); ) {
Connection c = iterator.next();
if (c.getState() == DISCONNECTED) {
// Remove the current element from the iterator and the list.
iterator.remove();
}
if (c.getState() == ACTIVE) {
active++;
}
}
}
if (active < 8) {
List<NetworkAddress> addresses = ctx.getNodeRegistry().getKnownAddresses(8 - active, ctx.getStreams());
for (NetworkAddress address : addresses) {
startConnection(new Connection(ctx, CLIENT, address, listener));
}
}
try {
int active = 0;
synchronized (connections) {
for (Iterator<Connection> iterator = connections.iterator(); iterator.hasNext(); ) {
Connection c = iterator.next();
if (c.getState() == DISCONNECTED) {
// Remove the current element from the iterator and the list.
iterator.remove();
}
if (c.getState() == ACTIVE) {
active++;
}
}
}
if (active < 8) {
List<NetworkAddress> addresses = ctx.getNodeRegistry().getKnownAddresses(8 - active, ctx.getStreams());
for (NetworkAddress address : addresses) {
startConnection(new Connection(ctx, CLIENT, address, listener));
}
}
Thread.sleep(30000);
} catch (InterruptedException e) {
LOG.debug(e.getMessage(), e);
Thread.currentThread().interrupt();
} catch (Exception e) {
LOG.error("Error in connection manager. Ignored.", e);
}
}
LOG.debug("Connection manager shutting down.");
}
}, "connection-manager");
connectionManager.start();

View File

@ -67,7 +67,7 @@ public class JdbcMessageRepositoryTest {
addressRepo.save(identity);
inbox = repo.getLabels(Label.Type.INBOX).get(0);
drafts = repo.getLabels(Label.Type.DRAFTS).get(0);
drafts = repo.getLabels(Label.Type.DRAFT).get(0);
addMessage(contactA, identity, Plaintext.Status.RECEIVED, inbox);
addMessage(identity, contactA, Plaintext.Status.DRAFT, drafts);