Issue # 5: fixed test and initialisation

This commit is contained in:
Christian Basler 2015-06-17 06:23:00 +02:00
parent 9b0de83706
commit 1dc4582012
4 changed files with 23 additions and 8 deletions

View File

@ -159,7 +159,7 @@ public class Connection implements Runnable {
} }
break; break;
default: default:
throw new RuntimeException("Command 'version' or 'verack' expected, but was '" throw new NodeException("Command 'version' or 'verack' expected, but was '"
+ msg.getPayload().getCommand() + "'"); + msg.getPayload().getCommand() + "'");
} }
} }
@ -173,6 +173,9 @@ public class Connection implements Runnable {
} catch (IOException | NodeException e) { } catch (IOException | NodeException e) {
LOG.debug("disconnection from node " + node + ": " + e.getMessage(), e); LOG.debug("disconnection from node " + node + ": " + e.getMessage(), e);
disconnect(); disconnect();
} catch (RuntimeException e) {
disconnect();
throw e;
} }
} }
@ -215,6 +218,8 @@ public class Connection implements Runnable {
listener.receive(objectMessage); listener.receive(objectMessage);
ctx.getInventory().storeObject(objectMessage); ctx.getInventory().storeObject(objectMessage);
// offer object to some random nodes so it gets distributed throughout the network: // offer object to some random nodes so it gets distributed throughout the network:
// FIXME: don't do this while we catch up after initialising our first connection
// (that might be a bit tricky to do)
ctx.getNetworkHandler().offer(objectMessage.getInventoryVector()); ctx.getNetworkHandler().offer(objectMessage.getInventoryVector());
} catch (InsufficientProofOfWorkException e) { } catch (InsufficientProofOfWorkException e) {
LOG.warn(e.getMessage()); LOG.warn(e.getMessage());

View File

@ -45,6 +45,7 @@ public class JdbcNodeRegistry extends JdbcHelper implements NodeRegistry {
if (result.isEmpty()) { if (result.isEmpty()) {
try (InputStream in = getClass().getClassLoader().getResourceAsStream("nodes.txt")) { try (InputStream in = getClass().getClassLoader().getResourceAsStream("nodes.txt")) {
Scanner scanner = new Scanner(in); Scanner scanner = new Scanner(in);
long stream = 1;
while (scanner.hasNext()) { while (scanner.hasNext()) {
try { try {
String line = scanner.nextLine().trim(); String line = scanner.nextLine().trim();
@ -52,10 +53,14 @@ public class JdbcNodeRegistry extends JdbcHelper implements NodeRegistry {
// Ignore // Ignore
continue; continue;
} }
int portIndex = line.lastIndexOf(':'); if (line.startsWith("[stream")) {
InetAddress inetAddress = InetAddress.getByName(line.substring(0, portIndex)); stream = Long.parseLong(line.substring(8, line.lastIndexOf(']')));
int port = Integer.valueOf(line.substring(portIndex + 1)); } else {
result.add(new NetworkAddress.Builder().ip(inetAddress).port(port).build()); int portIndex = line.lastIndexOf(':');
InetAddress inetAddress = InetAddress.getByName(line.substring(0, portIndex));
int port = Integer.valueOf(line.substring(portIndex + 1));
result.add(new NetworkAddress.Builder().ip(inetAddress).port(port).stream(stream).build());
}
} catch (IOException e) { } catch (IOException e) {
LOG.warn(e.getMessage(), e); LOG.warn(e.getMessage(), e);
} }

View File

@ -1,3 +1,5 @@
[stream 1]
[2604:2000:1380:9f:82e:148b:2746:d0c7]:8080 [2604:2000:1380:9f:82e:148b:2746:d0c7]:8080
5.45.99.75:8444 5.45.99.75:8444
75.167.159.54:8444 75.167.159.54:8444
@ -8,3 +10,6 @@
24.188.198.204:8111 24.188.198.204:8111
109.147.204.113:1195 109.147.204.113:1195
178.11.46.221:8444 178.11.46.221:8444
[stream 2]
# none yet

View File

@ -48,8 +48,8 @@ public class JdbcNodeRegistryTest {
@Test @Test
public void testInitNodes() throws Exception { public void testInitNodes() throws Exception {
config.reset(); config.reset();
List<NetworkAddress> knownAddresses = registry.getKnownAddresses(1, 1); List<NetworkAddress> knownAddresses = registry.getKnownAddresses(2, 1);
assertEquals(10, knownAddresses.size()); assertEquals(2, knownAddresses.size());
} }
@Test @Test