-
Notifications
You must be signed in to change notification settings - Fork 155
Resolve DNS to IP & IPv6 address support #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
driver/src/main/java/org/neo4j/driver/internal/cluster/DnsResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed 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.neo4j.driver.internal.cluster; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.neo4j.driver.internal.net.BoltServerAddress; | ||
import org.neo4j.driver.v1.Logger; | ||
|
||
public class DnsResolver implements HostNameResolver | ||
{ | ||
private final Logger logger; | ||
|
||
public DnsResolver( Logger logger ) | ||
{ | ||
this.logger = logger; | ||
} | ||
|
||
@Override | ||
public Set<BoltServerAddress> resolve( BoltServerAddress initialRouter ) | ||
{ | ||
Set<BoltServerAddress> addresses = new HashSet<>(); | ||
try | ||
{ | ||
InetAddress[] ipAddresses = InetAddress.getAllByName( initialRouter.host() ); | ||
|
||
for ( InetAddress ipAddress : ipAddresses ) | ||
{ | ||
addresses.add( new BoltServerAddress( ipAddress.getHostAddress(), initialRouter.port() ) ); | ||
} | ||
|
||
return addresses; | ||
} | ||
catch ( UnknownHostException e ) | ||
{ | ||
logger.error( "Failed to resolve URI `" + initialRouter + "` to IPs due to error: " + e.getMessage(), e ); | ||
|
||
addresses.add( initialRouter ); | ||
return addresses; | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
driver/src/main/java/org/neo4j/driver/internal/cluster/HostNameResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed 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.neo4j.driver.internal.cluster; | ||
|
||
import java.util.Set; | ||
|
||
import org.neo4j.driver.internal.net.BoltServerAddress; | ||
|
||
public interface HostNameResolver | ||
{ | ||
Set<BoltServerAddress> resolve( BoltServerAddress initialRouter ); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
driver/src/test/java/org/neo4j/driver/internal/cluster/DnsResolverTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed 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.neo4j.driver.internal.cluster; | ||
|
||
import org.junit.Test; | ||
|
||
import java.net.UnknownHostException; | ||
import java.util.Set; | ||
|
||
import org.neo4j.driver.internal.net.BoltServerAddress; | ||
import org.neo4j.driver.v1.Logger; | ||
|
||
import static org.hamcrest.Matchers.greaterThanOrEqualTo; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
|
||
public class DnsResolverTest | ||
{ | ||
private DnsResolver resolver = new DnsResolver( mock( Logger.class ) ); | ||
|
||
@Test | ||
public void shouldResolveDNSToIPs() | ||
{ | ||
Set<BoltServerAddress> resolve = resolver.resolve( new BoltServerAddress( "google.com", 80 ) ); | ||
assertThat( resolve.size(), greaterThanOrEqualTo( 1 ) ); | ||
} | ||
|
||
@Test | ||
public void shouldResolveLocalhostIPDNSToIPs() | ||
{ | ||
Set<BoltServerAddress> resolve = resolver.resolve( new BoltServerAddress( "127.0.0.1", 80 ) ); | ||
assertThat( resolve.size(), greaterThanOrEqualTo( 1 ) ); | ||
} | ||
|
||
@Test | ||
public void shouldResolveLocalhostDNSToIPs() | ||
{ | ||
Set<BoltServerAddress> resolve = resolver.resolve( new BoltServerAddress( "localhost", 80 ) ); | ||
assertThat( resolve.size(), greaterThanOrEqualTo( 1 ) ); | ||
} | ||
|
||
@Test | ||
public void shouldResolveIPv6LocalhostDNSToIPs() | ||
{ | ||
Set<BoltServerAddress> resolve = resolver.resolve( new BoltServerAddress( "[::1]", 80 ) ); | ||
assertThat( resolve.size(), greaterThanOrEqualTo( 1 ) ); | ||
} | ||
|
||
@Test | ||
public void shouldExceptionAndGiveDefaultValue() | ||
{ | ||
Logger logger = mock( Logger.class ); | ||
DnsResolver resolver = new DnsResolver( logger ); | ||
Set<BoltServerAddress> resolve = resolver.resolve( new BoltServerAddress( "[/]", 80 ) ); | ||
verify( logger ).error( any( String.class ), any( UnknownHostException.class ) ); | ||
assertThat( resolve.size(), greaterThanOrEqualTo( 1 ) ); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
#forget()
method is also called on connection errors. Do we really want to drop routers here? I'd vote for not changing this and keeping#removeRouter()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point to keep in routing table? they were there to protect from running out of routers. Now we no longer have the problem with dns