private boolean checkSocket(Socket s) { int l = deny.size(); byte address[] = s.getInetAddress().getAddress(); for (int i = 0; i < l; i++) { AddressMatcher match = (AddressMatcher) deny.elementAt(i); if (match.matches(address)) return false; } l = accept.size(); for (int i = 0; i < l; i++) { AddressMatcher match = (AddressMatcher) accept.elementAt(i); if (match.matches(address)) return true; } return false; }
/** * Checks incoming connections to see if they should be allowed. If not in paranoid mode, always * returns true. * * @param s The socket to inspect. * @return Whether the connection should be allowed. */ protected boolean allowConnection(Socket s) { if (!paranoid) { return true; } int l = deny.size(); byte address[] = s.getInetAddress().getAddress(); for (int i = 0; i < l; i++) { AddressMatcher match = (AddressMatcher) deny.elementAt(i); if (match.matches(address)) { return false; } } l = accept.size(); for (int i = 0; i < l; i++) { AddressMatcher match = (AddressMatcher) accept.elementAt(i); if (match.matches(address)) { return true; } } return false; }
/** * Returns logicalName and jobtracker Id when the local host matches the configuration parameter * {@code addressKey}.<logical>.<jobtracker Id> * * @param conf Configuration * @param addressKey configuration key corresponding to the address. * @param logicalName * @param matcher matching criteria for matching the address * @return Array with logical name and jobtracker Id on success. First element in the array is * logical name and second element is jobtracker Id. Null value indicates that the * configuration does not have the the Id. * @throws HadoopIllegalArgumentException on error */ static String[] getSuffixIDs( final Configuration conf, final String addressKey, String logicalName, final AddressMatcher matcher) { String jobTrackerId = null; int found = 0; Collection<String> jtIds = getJtServiceIds(conf, logicalName); for (String jtId : emptyAsSingletonNull(jtIds)) { if (LOG.isTraceEnabled()) { LOG.trace( String.format( "addressKey: %s logicalName: %s jtId: %s", addressKey, logicalName, jtId)); } String key = DFSUtil.addKeySuffixes(addressKey, logicalName, jtId); String addr = conf.get(key); if (addr == null) { continue; } InetSocketAddress s = null; try { s = NetUtils.createSocketAddr(addr); } catch (Exception e) { LOG.warn("Exception in creating socket address " + addr, e); continue; } if (!s.isUnresolved() && matcher.match(s)) { jobTrackerId = jtId; found++; } } // Only one address must match the local address if (found == 0) { String msg = "Configuration has no addresses that match " + "local node's address. Please configure the system with " + MR_HA_JOBTRACKER_ID_KEY; throw new HadoopIllegalArgumentException(msg); } else if (found > 1) { String msg = "Configuration has multiple addresses that match " + "local node's address. Please configure the system with " + MR_HA_JOBTRACKER_ID_KEY; throw new HadoopIllegalArgumentException(msg); } return new String[] {logicalName, jobTrackerId}; }