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;
default:
throw new RuntimeException("Command 'version' or 'verack' expected, but was '"
throw new NodeException("Command 'version' or 'verack' expected, but was '"
+ msg.getPayload().getCommand() + "'");
}
}
@ -173,6 +173,9 @@ public class Connection implements Runnable {
} catch (IOException | NodeException e) {
LOG.debug("disconnection from node " + node + ": " + e.getMessage(), e);
disconnect();
} catch (RuntimeException e) {
disconnect();
throw e;
}
}
@ -215,6 +218,8 @@ public class Connection implements Runnable {
listener.receive(objectMessage);
ctx.getInventory().storeObject(objectMessage);
// 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());
} catch (InsufficientProofOfWorkException e) {
LOG.warn(e.getMessage());

View File

@ -45,6 +45,7 @@ public class JdbcNodeRegistry extends JdbcHelper implements NodeRegistry {
if (result.isEmpty()) {
try (InputStream in = getClass().getClassLoader().getResourceAsStream("nodes.txt")) {
Scanner scanner = new Scanner(in);
long stream = 1;
while (scanner.hasNext()) {
try {
String line = scanner.nextLine().trim();
@ -52,10 +53,14 @@ public class JdbcNodeRegistry extends JdbcHelper implements NodeRegistry {
// Ignore
continue;
}
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).build());
if (line.startsWith("[stream")) {
stream = Long.parseLong(line.substring(8, line.lastIndexOf(']')));
} else {
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) {
LOG.warn(e.getMessage(), e);
}

View File

@ -1,3 +1,5 @@
[stream 1]
[2604:2000:1380:9f:82e:148b:2746:d0c7]:8080
5.45.99.75:8444
75.167.159.54:8444
@ -7,4 +9,7 @@
178.62.12.187:8448
24.188.198.204:8111
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
public void testInitNodes() throws Exception {
config.reset();
List<NetworkAddress> knownAddresses = registry.getKnownAddresses(1, 1);
assertEquals(10, knownAddresses.size());
List<NetworkAddress> knownAddresses = registry.getKnownAddresses(2, 1);
assertEquals(2, knownAddresses.size());
}
@Test