// 初期接続アドレス String contactHostAndPort = null; int contactPort = -1; String contactString = null; if (cmd.getArgs().length >= 1) { contactHostAndPort = cmd.getArgs()[0]; join = true; if (args.length >= 2) contactPort = Integer.parseInt(args[1]); } // initialize a DHT DHTConfiguration config = DHTFactory.getDefaultConfiguration(); if (transport != null) config.setMessagingTransport(transport); if (algorithm != null) config.setRoutingAlgorithm(algorithm); if (routingStyle != null) config.setRoutingStyle(routingStyle); if (fWorkDir != null) config.setWorkingDirectory(fWorkDir.getPath()); if (selfAddressAndPort != null) { MessagingUtility.HostAndPort hostAndPort = MessagingUtility.parseHostnameAndPort(selfAddressAndPort, config.getSelfPort()); config.setSelfAddress(hostAndPort.getHostName()); config.setSelfPort(hostAndPort.getPort()); } if (noUPnP) config.setDoUPnPNATTraversal(false); DHT<Serializable> dht = DHTFactory.getDHT((short)0, (short)0, config, selfID); // throws Exception StringBuilder sb = new StringBuilder(); sb.append("DHT configuration:\n"); sb.append(" hostname:port: ").append(dht.getSelfIDAddressPair().getAddress()).append('\n'); sb.append(" transport type: ").append(config.getMessagingTransport()).append('\n'); sb.append(" routing algorithm: ").append(config.getRoutingAlgorithm()).append('\n'); sb.append(" routing style: ").append(config.getRoutingStyle()).append('\n'); sb.append(" directory type: ").append(config.getDirectoryType()).append('\n'); sb.append(" working directory: ").append(config.getWorkingDirectory()).append('\n'); System.out.print(sb); try { if (statCollectorAddressAndPort != null) { MessagingUtility.HostAndPort hostAndPort = MessagingUtility.parseHostnameAndPort(statCollectorAddressAndPort, config.getSelfPort()); dht.setStatCollectorAddress(hostAndPort.getHostName(), hostAndPort.getPort()); } if (join) { if (contactPort >= 0) { dht.joinOverlay(contactHostAndPort, contactPort); contactString = contactHostAndPort + " : " + contactPort; } else { try { dht.joinOverlay(contactHostAndPort); contactString = contactHostAndPort; } catch (IllegalArgumentException e) { // port is not specified contactPort = config.getContactPort(); dht.joinOverlay(contactHostAndPort, contactPort); contactString = contactHostAndPort + ":" + contactPort; } } } } catch (UnknownHostException e) { System.err.println("A hostname could not be resolved: " + contactHostAndPort); e.printStackTrace(); System.exit(1); } if (join) { System.out.println(" initial contact: " + contactString); } System.out.println("A DHT started."); System.out.flush(); return dht; } }
だぁ、文字数制限があるとめんどくせぇ!
どっか別のブログに移動しようかしらん。
来週は put データ、送信メッセージを決めることにしよう。では。