import cleanup

This commit is contained in:
Dave
2015-07-03 23:43:06 +02:00
parent 9dac03891c
commit 1c1a6012bf
12 changed files with 60 additions and 56 deletions

View File

@@ -36,6 +36,8 @@ public interface NoAdapter {
public Collection<NoByteSet> pollNoByteSets(PublicKey address) throws NoAdapterException; public Collection<NoByteSet> pollNoByteSets(PublicKey address) throws NoAdapterException;
public void addNoByteSets(Collection<NoByteSet> noByteSets, PublicKey address) public void addNoByteSet(NoByteSet byteSet, PublicKey address) throws NoAdapterException;
public void addNoByteSets(Collection<NoByteSet> byteSets, PublicKey address)
throws NoAdapterException; throws NoAdapterException;
} }

View File

@@ -195,6 +195,14 @@ public class NoDefaultAdapter implements NoAdapter {
return new ArrayList<NoByteSet>(); return new ArrayList<NoByteSet>();
} }
} }
@Override
public void addNoByteSet(NoByteSet byteSet, PublicKey address) {
if (!byteSets.containsKey(address)) {
byteSets.put(address, new ArrayList<NoByteSet>());
}
byteSets.get(address).add(byteSet);
}
@Override @Override
public void addNoByteSets(Collection<NoByteSet> addedByteSets, PublicKey address) { public void addNoByteSets(Collection<NoByteSet> addedByteSets, PublicKey address) {

View File

@@ -28,7 +28,6 @@ import java.security.spec.KeySpec;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException; import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory; import javax.crypto.SecretKeyFactory;

View File

@@ -13,11 +13,8 @@ import javax.crypto.IllegalBlockSizeException;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import nodash.core.NoAdapter; import nodash.core.NoAdapter;
import nodash.core.NoCore;
import nodash.core.NoUtil; import nodash.core.NoUtil;
import nodash.exceptions.NoByteSetBadDecryptionException; import nodash.exceptions.NoByteSetBadDecryptionException;
import nodash.exceptions.NoDashFatalException;
import nodash.exceptions.NoDashSessionBadUuidException;
import nodash.exceptions.NoSessionConfirmedException; import nodash.exceptions.NoSessionConfirmedException;
import nodash.exceptions.NoSessionExpiredException; import nodash.exceptions.NoSessionExpiredException;
import nodash.exceptions.NoSessionNotAwaitingConfirmationException; import nodash.exceptions.NoSessionNotAwaitingConfirmationException;
@@ -191,26 +188,6 @@ public final class NoSession implements Serializable {
} }
} }
private static String decryptUuid(String data) throws NoDashSessionBadUuidException {
return decryptUuid(Base64.decodeBase64(data));
}
private static String decryptUuid(byte[] data) throws NoDashSessionBadUuidException {
if (data == null) {
throw new NoDashSessionBadUuidException();
}
try {
return Base64.encodeBase64String(NoUtil.decrypt(data));
} catch (IllegalArgumentException e) {
throw new NoDashSessionBadUuidException();
} catch (IllegalBlockSizeException e) {
throw new NoDashSessionBadUuidException();
} catch (BadPaddingException e) {
throw new NoDashSessionBadUuidException();
}
}
public void setIncoming(Collection<NoByteSet> incoming) { public void setIncoming(Collection<NoByteSet> incoming) {
this.incoming = incoming; this.incoming = incoming;
} }

View File

@@ -23,8 +23,10 @@ package nodash.models.noactiontypes;
import java.security.PublicKey; import java.security.PublicKey;
import nodash.core.NoCore; import nodash.core.NoAdapter;
import nodash.exceptions.NoAdapterException;
import nodash.exceptions.NoCannotGetInfluenceException; import nodash.exceptions.NoCannotGetInfluenceException;
import nodash.exceptions.NoDashFatalException;
import nodash.models.NoByteSet; import nodash.models.NoByteSet;
import nodash.models.NoInfluence; import nodash.models.NoInfluence;
@@ -36,20 +38,27 @@ public abstract class NoErrorableAction extends NoTargetedAction {
super(source); super(source);
} }
public void execute() { @Override
public void execute(NoAdapter adapter) {
this.process(); this.process();
try { try {
NoInfluence influence = this.generateTargetInfluence(); NoInfluence influence = this.generateTargetInfluence();
if (influence != null) { if (influence != null) {
NoByteSet byteSet = influence.getByteSet(this.target); NoByteSet byteSet = influence.getByteSet(this.target);
NoCore.addByteSet(byteSet, this.target); adapter.addNoByteSet(byteSet, this.target);
} }
} catch (NoCannotGetInfluenceException e) { } catch (NoCannotGetInfluenceException e) {
NoInfluence errorInfluence = e.getResponseInfluence(); NoInfluence errorInfluence = e.getResponseInfluence();
if (errorInfluence != null) { if (errorInfluence != null) {
NoByteSet byteSet = errorInfluence.getByteSet(this.target); NoByteSet byteSet = errorInfluence.getByteSet(this.target);
NoCore.addByteSet(byteSet, this.target); try {
adapter.addNoByteSet(byteSet, this.target);
} catch (NoAdapterException e1) {
throw new NoDashFatalException("Could not add the error byte set to the pool.");
}
} }
} catch (NoAdapterException e) {
throw new NoDashFatalException("Could not add the byte set to the pool.");
} }
} }
} }

View File

@@ -23,8 +23,10 @@ package nodash.models.noactiontypes;
import java.security.PublicKey; import java.security.PublicKey;
import nodash.core.NoCore; import nodash.core.NoAdapter;
import nodash.exceptions.NoAdapterException;
import nodash.exceptions.NoCannotGetInfluenceException; import nodash.exceptions.NoCannotGetInfluenceException;
import nodash.exceptions.NoDashFatalException;
import nodash.models.NoByteSet; import nodash.models.NoByteSet;
import nodash.models.NoInfluence; import nodash.models.NoInfluence;
@@ -37,30 +39,33 @@ public abstract class NoHandshakeAction extends NoSourcedAction {
super(target, source); super(target, source);
} }
public void execute() { @Override
public void execute(NoAdapter adapter) {
this.process(); this.process();
try { try {
NoInfluence influence = this.generateTargetInfluence(); NoInfluence influence = this.generateTargetInfluence();
if (influence != null) { if (influence != null) {
NoByteSet byteSet = influence.getByteSet(this.target); NoByteSet byteSet = influence.getByteSet(this.target);
NoCore.addByteSet(byteSet, this.target); adapter.addNoByteSet(byteSet, this.target);
} }
NoInfluence result = this.generateReturnedInfluence(); NoInfluence result = this.generateReturnedInfluence();
if (result != null) { if (result != null) {
NoByteSet byteSet = result.getByteSet(this.source); NoByteSet byteSet = result.getByteSet(this.source);
NoCore.addByteSet(byteSet, this.source); adapter.addNoByteSet(byteSet, this.source);
} }
} catch (NoCannotGetInfluenceException e) { } catch (NoCannotGetInfluenceException e) {
NoInfluence errorInfluence = e.getResponseInfluence(); NoInfluence errorInfluence = e.getResponseInfluence();
if (errorInfluence != null) { if (errorInfluence != null) {
NoByteSet byteSet = errorInfluence.getByteSet(this.source); NoByteSet byteSet = errorInfluence.getByteSet(this.source);
NoCore.addByteSet(byteSet, this.source); try {
adapter.addNoByteSet(byteSet, this.source);
} catch (NoAdapterException e1) {
throw new NoDashFatalException("Could not add error byte set to the pool.");
}
} }
} catch (NoAdapterException e) {
throw new NoDashFatalException("Could not add byte sets to the pool.", e);
} }
} }
public void purge() {
super.purge();
}
} }

View File

@@ -22,8 +22,10 @@ package nodash.models.noactiontypes;
import java.security.PublicKey; import java.security.PublicKey;
import nodash.core.NoCore; import nodash.core.NoAdapter;
import nodash.exceptions.NoAdapterException;
import nodash.exceptions.NoCannotGetInfluenceException; import nodash.exceptions.NoCannotGetInfluenceException;
import nodash.exceptions.NoDashFatalException;
import nodash.models.NoByteSet; import nodash.models.NoByteSet;
import nodash.models.NoInfluence; import nodash.models.NoInfluence;
@@ -38,23 +40,31 @@ public abstract class NoSourcedAction extends NoTargetedAction {
this.source = source; this.source = source;
} }
public void execute() { @Override
public void execute(NoAdapter adapter) {
this.process(); this.process();
try { try {
NoInfluence influence = this.generateTargetInfluence(); NoInfluence influence = this.generateTargetInfluence();
if (influence != null) { if (influence != null) {
NoByteSet byteSet = influence.getByteSet(this.target); NoByteSet byteSet = influence.getByteSet(this.target);
NoCore.addByteSet(byteSet, this.target); adapter.addNoByteSet(byteSet, this.target);
} }
} catch (NoCannotGetInfluenceException e) { } catch (NoCannotGetInfluenceException e) {
NoInfluence errorInfluence = e.getResponseInfluence(); NoInfluence errorInfluence = e.getResponseInfluence();
if (errorInfluence != null) { if (errorInfluence != null) {
NoByteSet byteSet = errorInfluence.getByteSet(this.source); NoByteSet byteSet = errorInfluence.getByteSet(this.source);
NoCore.addByteSet(byteSet, this.source); try {
adapter.addNoByteSet(byteSet, this.source);
} catch (NoAdapterException e1) {
throw new NoDashFatalException("Could not add error byte set to the pool.", e);
}
} }
} catch (NoAdapterException e) {
throw new NoDashFatalException("Could not add byte set to the pool.", e);
} }
} }
@Override
public void purge() { public void purge() {
super.purge(); super.purge();
this.source = null; this.source = null;

View File

@@ -19,7 +19,8 @@ package nodash.models.noactiontypes;
import java.security.PublicKey; import java.security.PublicKey;
import nodash.core.NoCore; import nodash.core.NoAdapter;
import nodash.exceptions.NoAdapterException;
import nodash.exceptions.NoCannotGetInfluenceException; import nodash.exceptions.NoCannotGetInfluenceException;
import nodash.exceptions.NoDashFatalException; import nodash.exceptions.NoDashFatalException;
import nodash.models.NoAction; import nodash.models.NoAction;
@@ -36,22 +37,26 @@ public abstract class NoTargetedAction extends NoAction {
this.target = target; this.target = target;
} }
public void execute() { @Override
public void execute(NoAdapter adapter) {
this.process(); this.process();
try { try {
NoInfluence influence = this.generateTargetInfluence(); NoInfluence influence = this.generateTargetInfluence();
if (influence != null) { if (influence != null) {
NoByteSet byteSet = influence.getByteSet(this.target); NoByteSet byteSet = influence.getByteSet(this.target);
NoCore.addByteSet(byteSet, this.target); adapter.addNoByteSet(byteSet, this.target);
} }
} catch (NoCannotGetInfluenceException e) { } catch (NoCannotGetInfluenceException e) {
if (e.getResponseInfluence() != null) { if (e.getResponseInfluence() != null) {
throw new NoDashFatalException( throw new NoDashFatalException(
"Unsourced action has generated an error with an undeliverable influence.", e); "Unsourced action has generated an error with an undeliverable influence.", e);
} }
} catch (NoAdapterException e) {
throw new NoDashFatalException("Could not add byte set to the pool.", e);
} }
} }
@Override
public void purge() { public void purge() {
this.target = null; this.target = null;
} }

View File

@@ -17,7 +17,6 @@ import nodash.exceptions.NoSessionNotAwaitingConfirmationException;
import nodash.exceptions.NoSessionNotChangedException; import nodash.exceptions.NoSessionNotChangedException;
import nodash.exceptions.NoUserAlreadyOnlineException; import nodash.exceptions.NoUserAlreadyOnlineException;
import nodash.exceptions.NoUserNotValidException; import nodash.exceptions.NoUserNotValidException;
import nodash.models.NoSession;
import nodash.models.NoUser; import nodash.models.NoUser;
import org.junit.Test; import org.junit.Test;
@@ -123,19 +122,16 @@ public class NoCoreTest {
@Test @Test
public void testGetUser() { public void testGetUser() {
NoCore core = new NoCore(new NoDefaultAdapter());
fail("Not yet implemented"); fail("Not yet implemented");
} }
@Test @Test
public void testGetSessionState() { public void testGetSessionState() {
NoCore core = new NoCore(new NoDefaultAdapter());
fail("Not yet implemented"); fail("Not yet implemented");
} }
@Test @Test
public void testShred() { public void testShred() {
NoCore core = new NoCore(new NoDefaultAdapter());
fail("Not yet implemented"); fail("Not yet implemented");
} }

View File

@@ -1,12 +1,10 @@
package nodash.test; package nodash.test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import nodash.core.NoCore;
import nodash.exceptions.NoSessionConfirmedException; import nodash.exceptions.NoSessionConfirmedException;
import nodash.exceptions.NoSessionExpiredException; import nodash.exceptions.NoSessionExpiredException;
import nodash.models.NoSession; import nodash.models.NoSession;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class NoSessionTest { public class NoSessionTest {

View File

@@ -8,11 +8,9 @@ import java.util.Arrays;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import nodash.core.NoCore;
import nodash.models.NoUser; import nodash.models.NoUser;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class NoUserTest { public class NoUserTest {

View File

@@ -13,12 +13,9 @@ import java.util.Arrays;
import javax.crypto.BadPaddingException; import javax.crypto.BadPaddingException;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import nodash.core.NoCore;
import nodash.core.NoUtil; import nodash.core.NoUtil;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class NoUtilTest { public class NoUtilTest {