diff --git a/commons/src/main/java/org/archive/net/PublicSuffixes.java b/commons/src/main/java/org/archive/net/PublicSuffixes.java index 8294b323..5f74e189 100644 --- a/commons/src/main/java/org/archive/net/PublicSuffixes.java +++ b/commons/src/main/java/org/archive/net/PublicSuffixes.java @@ -1,26 +1,20 @@ -/* PublicSuffixes.java +/* + * This file is part of the Heritrix web crawler (crawler.archive.org). * - * $Id: BloomFilter32bitSplit.java 5197 2007-06-06 01:31:46Z gojomo $ + * Licensed to the Internet Archive (IA) by one or more individual + * contributors. * - * Created on Jun 13, 2007 + * The IA licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * Copyright (C) 2007 Internet Archive + * http://www.apache.org/licenses/LICENSE-2.0 * - * This file is part of the Heritrix web crawler (crawler.archive.org). - * - * Heritrix is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * any later version. - * - * Heritrix is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser Public License for more details. - * - * You should have received a copy of the GNU Lesser Public License - * along with Heritrix; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.archive.net; @@ -62,6 +56,10 @@ import org.archive.util.TextUtils; * suffix may be useful for applying the same rules to all, such as assigning * them to the same queue or crawler in a multi- machine setup. * + * As of Heritrix3, we prefer the term 'Assignment Level Domain' (ALD) + * for such domains, by analogy to 'Top Level Domain' (TLD) or '2nd Level + * Domain' (2LD), etc. + * * @author Gojomo */ public class PublicSuffixes { @@ -290,7 +288,7 @@ public class PublicSuffixes { * @param surt SURT to truncate * @return truncated-to-topmost-assigned SURT prefix */ - public static String reduceSurtToTopmostAssigned(String surt) { + public static String reduceSurtToAssignmentLevel(String surt) { Matcher matcher = TextUtils.getMatcher( getTopmostAssignedSurtPrefixRegex(), surt); if (matcher.find()) { diff --git a/commons/src/test/java/org/archive/net/PublicSuffixesTest.java b/commons/src/test/java/org/archive/net/PublicSuffixesTest.java index 4be57141..63ce5648 100644 --- a/commons/src/test/java/org/archive/net/PublicSuffixesTest.java +++ b/commons/src/test/java/org/archive/net/PublicSuffixesTest.java @@ -1,26 +1,20 @@ -/* PublicSuffixesTest.java +/* + * This file is part of the Heritrix web crawler (crawler.archive.org). * - * $Id: BloomFilter32bitSplit.java 5197 2007-06-06 01:31:46Z gojomo $ + * Licensed to the Internet Archive (IA) by one or more individual + * contributors. * - * Created on Jun 13, 2007 + * The IA licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * Copyright (C) 2007 Internet Archive + * http://www.apache.org/licenses/LICENSE-2.0 * - * This file is part of the Heritrix web crawler (crawler.archive.org). - * - * Heritrix is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * any later version. - * - * Heritrix is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser Public License for more details. - * - * You should have received a copy of the GNU Lesser Public License - * along with Heritrix; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package org.archive.net; @@ -68,13 +62,13 @@ public class PublicSuffixesTest extends TestCase { public void testIPV4() { assertEquals("unexpected reduction", "1.2.3.4", - PublicSuffixes.reduceSurtToTopmostAssigned("1.2.3.4")); + PublicSuffixes.reduceSurtToAssignmentLevel("1.2.3.4")); } public void testIPV6() { assertEquals("unexpected reduction", "[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]", - PublicSuffixes.reduceSurtToTopmostAssigned( + PublicSuffixes.reduceSurtToAssignmentLevel( "[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]")); } diff --git a/engine/src/main/java/org/archive/crawler/frontier/AssignmentLevelSurtQueueAssignmentPolicy.java b/engine/src/main/java/org/archive/crawler/frontier/AssignmentLevelSurtQueueAssignmentPolicy.java new file mode 100644 index 00000000..37ccb1e7 --- /dev/null +++ b/engine/src/main/java/org/archive/crawler/frontier/AssignmentLevelSurtQueueAssignmentPolicy.java @@ -0,0 +1,41 @@ +/* + * This file is part of the Heritrix web crawler (crawler.archive.org). + * + * Licensed to the Internet Archive (IA) by one or more individual + * contributors. + * + * The IA licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.archive.crawler.frontier; + +import org.archive.crawler.datamodel.CrawlURI; +import org.archive.net.PublicSuffixes; + +/** + * Create a queueKey based on the SURT authority, reduced to the + * public-suffix-plus-one domain (topmost assignable domain). + * + * @author gojomo + */ +public class AssignmentLevelSurtQueueAssignmentPolicy extends + SurtAuthorityQueueAssignmentPolicy { + private static final long serialVersionUID = -1533545293624791702L; + + @Override + public String getClassKey(CrawlURI cauri) { + String candidate = super.getClassKey(cauri); + candidate = PublicSuffixes.reduceSurtToAssignmentLevel(candidate); + return candidate; + } + +} diff --git a/engine/src/main/java/org/archive/crawler/frontier/TopmostAssignedSurtQueueAssignmentPolicy.java b/engine/src/main/java/org/archive/crawler/frontier/TopmostAssignedSurtQueueAssignmentPolicy.java deleted file mode 100644 index da30f77d..00000000 --- a/engine/src/main/java/org/archive/crawler/frontier/TopmostAssignedSurtQueueAssignmentPolicy.java +++ /dev/null @@ -1,47 +0,0 @@ -/* AbstractFrontier - * - * $Id: AbstractFrontier.java 5053 2007-04-10 02:34:20Z gojomo $ - * - * Created on June 18, 2007 - * - * Copyright (C) 2007 Internet Archive. - * - * This file is part of the Heritrix web crawler (crawler.archive.org). - * - * Heritrix is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or - * any later version. - * - * Heritrix is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser Public License for more details. - * - * You should have received a copy of the GNU Lesser Public License - * along with Heritrix; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -package org.archive.crawler.frontier; - -import org.archive.crawler.datamodel.CrawlURI; -import org.archive.net.PublicSuffixes; - -/** - * Create a queueKey based on the SURT authority, reduced to the - * public-suffix-plus-one domain (topmost assignable domain). - * - * @author gojomo - */ -public class TopmostAssignedSurtQueueAssignmentPolicy extends - SurtAuthorityQueueAssignmentPolicy { - private static final long serialVersionUID = -1533545293624791702L; - - @Override - public String getClassKey(CrawlURI cauri) { - String candidate = super.getClassKey(cauri); - candidate = PublicSuffixes.reduceSurtToTopmostAssigned(candidate); - return candidate; - } - -} diff --git a/modules/src/main/java/org/archive/modules/deciderules/HopCrossesAssignmentLevelDomainDecideRule.java b/modules/src/main/java/org/archive/modules/deciderules/HopCrossesAssignmentLevelDomainDecideRule.java new file mode 100644 index 00000000..e9fb4680 --- /dev/null +++ b/modules/src/main/java/org/archive/modules/deciderules/HopCrossesAssignmentLevelDomainDecideRule.java @@ -0,0 +1,73 @@ +/* + * This file is part of the Heritrix web crawler (crawler.archive.org). + * + * Licensed to the Internet Archive (IA) by one or more individual + * contributors. + * + * The IA licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.archive.modules.deciderules; + +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.archive.modules.ProcessorURI; +import org.archive.net.PublicSuffixes; +import org.archive.net.UURI; + +/** + * Applies its decision if the current URI differs in that portion of + * its hostname/domain that is assigned/sold by registrars, its + * 'assignment-level-domain' (ALD) (AKA 'public suffix' or in previous + * Heritrix versions, 'topmost assigned SURT') + * + * @author Olaf Freyer + */ +public class HopCrossesAssignmentLevelDomainDecideRule extends PredicatedDecideRule { + private static final long serialVersionUID = 1L; + + private static final Logger LOGGER = Logger + .getLogger(HopCrossesAssignmentLevelDomainDecideRule.class.getName()); + + public HopCrossesAssignmentLevelDomainDecideRule() { + } + + protected boolean evaluate(ProcessorURI uri) { + UURI via = uri.getVia(); + if (via == null) { + return false; + } + try { + // determine if this hop crosses assignment-level-domain borders + String ald = getAssignmentLevelSurt(uri.getUURI()); + String viaAld = getAssignmentLevelSurt(via); + if (ald != null && !ald.equals(viaAld)) { + if(LOGGER.isLoggable(Level.FINE)) { + LOGGER.fine("rule matched for \"" + ald+"\" vs. \""+viaAld+"\""); + } + return true; + } + } catch (Exception e) { + LOGGER.log(Level.WARNING,"uri="+uri+" via="+via, e); + // Return false since we could not get hostname or something else + // went wrong + } + return false; + } + + private String getAssignmentLevelSurt(UURI uuri){ + String surt = uuri.getSurtForm().replaceFirst(".*://\\((.*?)\\).*", "$1"); + return PublicSuffixes.reduceSurtToAssignmentLevel(surt); + + } +}