int port = Integer.valueOf(line.substring(portIndex + 1)); for (InetAddress inetAddress : inetAddresses) { streamSet.add(new NetworkAddress.Builder().ip(inetAddress).port(port).stream(stream).build());
@Override public Void call() throws Exception { try (SocketChannel channel = SocketChannel.open(new InetSocketAddress(server, port))) { channel.configureBlocking(false); ConnectionInfo connection = new ConnectionInfo(ctx, SYNC, new NetworkAddress.Builder().ip(server).port(port).stream(1).build(), new HashMap<InventoryVector, Long>(), timeoutInSeconds); while (channel.isConnected() && !connection.isSyncFinished()) { write(channel, connection); read(channel, connection); Thread.sleep(10); } LOG.info("Synchronization finished"); } return null; } });
public static Connection sync(InternalContext ctx, InetAddress address, int port, MessageListener listener, long timeoutInSeconds) throws IOException { return new Connection(ctx, SYNC, new Socket(address, port), new HashMap<InventoryVector, Long>(), new NetworkAddress.Builder().ip(address).port(port).stream(1).build(), timeoutInSeconds); }
while (rs.next()) { result.add( new NetworkAddress.Builder() .stream(rs.getLong("stream")) .ipv6(rs.getBytes("address"))
private NetworkAddress loadExisting(NetworkAddress node) { String query = "SELECT stream, address, port, services, time" + " FROM Node" + " WHERE stream = " + node.getStream() + " AND address = X'" + Strings.hex(node.getIPv6()) + "'" + " AND port = " + node.getPort(); try ( Connection connection = config.getConnection(); Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery(query) ) { if (rs.next()) { return new NetworkAddress.Builder() .stream(rs.getLong("stream")) .ipv6(rs.getBytes("address")) .port(rs.getInt("port")) .services(rs.getLong("services")) .time(rs.getLong("time")) .build(); } else { return null; } } catch (Exception e) { LOG.error(e.getMessage(), e); throw new ApplicationException(e); } }
private static NetworkAddress parseAddress(InputStream stream, boolean light) throws IOException { long time; long streamNumber; if (!light) { time = Decode.int64(stream); streamNumber = Decode.uint32(stream); // This isn't consistent, not sure if this is correct } else { time = 0; streamNumber = 0; } long services = Decode.int64(stream); byte[] ipv6 = Decode.bytes(stream, 16); int port = Decode.uint16(stream); return new NetworkAddress.Builder() .time(time) .stream(streamNumber) .services(services) .ipv6(ipv6) .port(port) .build(); }
private static NetworkAddress parseAddress(InputStream stream, boolean light) throws IOException { long time; long streamNumber; if (!light) { time = Decode.int64(stream); streamNumber = Decode.uint32(stream); // This isn't consistent, not sure if this is correct } else { time = 0; streamNumber = 0; } long services = Decode.int64(stream); byte[] ipv6 = Decode.bytes(stream, 16); int port = Decode.uint16(stream); return new NetworkAddress.Builder().time(time).stream(streamNumber).services(services).ipv6(ipv6).port(port).build(); }
public Connection(InternalContext context, Mode mode, Socket socket, Map<InventoryVector, Long> requestedObjectsMap) throws IOException { this(context, mode, socket, requestedObjectsMap, new NetworkAddress.Builder().ip(socket.getInetAddress()).port(socket.getPort()).stream(1).build(), 0); }