@Override public void send(int partyId, byte[] data) { if (partyId == conf.getMyId()) { this.selfQueue.add(data); } else { inRange(partyId); if (!senders.get(partyId).isRunning()) { throw new RuntimeException( "P" + conf.getMyId() + ": Unable to send to P" + partyId + ". Sender not running"); } this.senders.get(partyId).queueMessage(data); } }
/** * Listens for connections from the opposing parties with lower id's. * * @throws IOException thrown if an {@link IOException} occurs while listening. */ private Map<Integer, Socket> connectServer(final NetworkConfiguration conf) throws IOException { Map<Integer, Socket> socketMap = new HashMap<>(conf.getMyId() - 1); if (conf.getMyId() > 1) { try (ServerSocket server = serverFactory.createServerSocket(conf.getMe().getPort())) { logger.info("P{}: bound at port {}", conf.getMyId(), conf.getMe().getPort()); for (int i = 1; i < conf.getMyId(); i++) { Socket sock = server.accept(); int id = 0; for (int j = 0; j < PARTY_ID_BYTES; j++) { id ^= sock.getInputStream().read() << j * Byte.SIZE; } socketMap.put(id, sock); logger.info("P{}: accepted connection from P{}", conf.getMyId(), id); socketMap.put(id, sock); } } } return socketMap; }
/** * Closes the network down and releases held resources. */ @Override public void close() { if (alive) { alive = false; if (conf.noOfParties() < 2) { logger.info("P{}: Network closed", conf.getMyId()); return; } ExceptionConverter.safe(() -> { closeCommunication(); logger.info("P{}: Network closed", conf.getMyId()); return null; }, "Unable to properly close the network."); } else { logger.info("P{}: Network already closed", conf.getMyId()); } }
@Override public byte[] receive(final int partyId) { if (partyId == conf.getMyId()) { return ExceptionConverter.safe(selfQueue::take, "Receiving from self failed"); } inRange(partyId); byte[] data; data = receivers.get(partyId).pollMessage(RECEIVE_TIMEOUT); while (data == null) { if (!receivers.get(partyId).isRunning()) { throw new RuntimeException("P" + conf.getMyId() + ": Unable to recieve from P" + partyId + ". Receiver not running"); } data = receivers.get(partyId).pollMessage(RECEIVE_TIMEOUT); } return data; }
Map<Integer, Socket> socketMap = new HashMap<>(conf.noOfParties() - conf.getMyId()); for (int i = conf.getMyId() + 1; i <= conf.noOfParties(); i++) { Party p = conf.getParty(i); boolean connectionMade = false; Socket sock = socketFactory.createSocket(p.getHostname(), p.getPort()); for (int j = 0; j < PARTY_ID_BYTES; j++) { byte b = (byte) (conf.getMyId() >>> j * Byte.SIZE); sock.getOutputStream().write(b); logger.info("P{}: connected to {}", conf.getMyId(), p); } catch (ConnectException e) {
Objects.requireNonNull(socketMap); for (int i = 1; i < conf.noOfParties() + 1; i++) { if (i == conf.getMyId()) { continue;
NetworkConfiguration networkConfiguration = cmdUtil.getNetworkConfiguration(); if (networkConfiguration.getMyId() == 1 || networkConfiguration.getMyId() == 2) { if (!cmd.hasOption("x") || !cmd.hasOption("y")) { cmdUtil.displayHelp(); DistanceDemo distDemo = new DistanceDemo(networkConfiguration.getMyId(), x, y); SecureComputationEngine<ResourcePoolT, ProtocolBuilderNumeric> sce = cmdUtil.getSce(); ResourcePoolT resourcePool = cmdUtil.getResourcePool();
if (networkConfiguration.getMyId() == 1 || networkConfiguration.getMyId() == 2) { if (!cmd.hasOption("in")) { throw new IllegalArgumentException("Player 1 and 2 must submit inputs"); PrivateSetDemo privateSetDemo = new PrivateSetDemo(networkConfiguration.getMyId(), key, inputs); ProtocolSuite<T, ProtocolBuilderBinary> psConf = util.getProtocolSuite(); SecureComputationEngine<T, ProtocolBuilderBinary> sce =
@Test public void testMyIdIsCorrect() { assertEquals(1, confs.get(1).getMyId()); }
protected Map<Integer, CloseableNetwork> createNetworks(List<NetworkConfiguration> confs) { int numParties = confs.get(0).noOfParties(); ExecutorService es = Executors.newFixedThreadPool(numParties); Map<Integer, CloseableNetwork> netMap = new HashMap<>(numParties); Map<Integer, Future<CloseableNetwork>> futureMap = new HashMap<>(numParties); try { for (NetworkConfiguration conf : confs) { Future<CloseableNetwork> f = es.submit(() -> newCloseableNetwork(conf)); futureMap.put(conf.getMyId(), f); } for (Entry<Integer, Future<CloseableNetwork>> entry : futureMap.entrySet()) { netMap.put(entry.getKey(), entry.getValue().get()); } } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); fail("Failed to setup networks."); } finally { es.shutdownNow(); } return netMap; }
Future<CloseableNetwork> f = es.submit(() -> fact.newCloseableNetwork(conf, Duration.ofSeconds(1))); futureMap.put(conf.getMyId(), f);
cmd.getOptionProperties("D"), this.networkConfiguration.getMyId(), networkConfiguration.noOfParties(), network );
@Test public void testGetMyId() { assertEquals(me.getPartyId(), netConf.getMyId()); }
Future<CloseableNetwork> f = es.submit(() -> fact.newCloseableNetwork(conf, Connector.DEFAULT_CONNECTION_TIMEOUT)); futureMap.put(conf.getMyId(), f);
kms = getKeyStoreManager(conf.getMyId()); } catch (UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException e) { tms = getTrustStoreManager(conf.getMyId()); } catch (UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException e) {