Skip to content

Commit

Permalink
Fix IPv6 support in client connector addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfurmanski committed Jul 5, 2017
1 parent 272753e commit 64aee78
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Expand Up @@ -39,6 +39,9 @@ public class SocketAddress

public SocketAddress( String hostname, int port )
{
assert !hostname.contains( "[" );
assert !hostname.contains( "]" );

this.hostname = hostname;
this.port = port;
}
Expand Down
Expand Up @@ -29,6 +29,7 @@
import java.util.stream.Stream;

import org.neo4j.helpers.AdvertisedSocketAddress;
import org.neo4j.helpers.SocketAddressParser;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.server.configuration.ClientConnectorSettings.HttpConnector.Encryption;

Expand Down Expand Up @@ -155,8 +156,8 @@ public String toString()
private static ConnectorUri fromString( String string )
{
URI uri = URI.create( string );
return new ConnectorUri( Scheme.valueOf( uri.getScheme() ),
new AdvertisedSocketAddress( uri.getHost(), uri.getPort() ) );
AdvertisedSocketAddress advertisedSocketAddress = SocketAddressParser.socketAddress( uri.getAuthority(), AdvertisedSocketAddress::new );
return new ConnectorUri( Scheme.valueOf( uri.getScheme() ), advertisedSocketAddress );
}

@Override
Expand Down
Expand Up @@ -25,9 +25,7 @@
import org.neo4j.helpers.AdvertisedSocketAddress;

import static java.util.Arrays.asList;

import static org.junit.Assert.assertEquals;

import static org.neo4j.causalclustering.discovery.ClientConnectorAddresses.Scheme.bolt;
import static org.neo4j.causalclustering.discovery.ClientConnectorAddresses.Scheme.http;
import static org.neo4j.causalclustering.discovery.ClientConnectorAddresses.Scheme.https;
Expand All @@ -41,11 +39,22 @@ public void shouldSerializeToString() throws Exception
ClientConnectorAddresses connectorAddresses = new ClientConnectorAddresses( asList(
new ConnectorUri( bolt, new AdvertisedSocketAddress( "host", 1 ) ),
new ConnectorUri( http, new AdvertisedSocketAddress( "host", 2 ) ),
new ConnectorUri( https, new AdvertisedSocketAddress( "host", 3 ) ) )
new ConnectorUri( https, new AdvertisedSocketAddress( "host", 3 ) ),
new ConnectorUri( bolt, new AdvertisedSocketAddress( "::1", 4 ) ),
new ConnectorUri( http, new AdvertisedSocketAddress( "::", 5 ) ),
new ConnectorUri( https, new AdvertisedSocketAddress( "fe80:1:2::3", 6 ) ) )
);

String expectedString = "bolt://host:1,http://host:2,https://host:3,bolt://[::1]:4,http://[::]:5,https://[fe80:1:2::3]:6";

// when
ClientConnectorAddresses out = ClientConnectorAddresses.fromString( connectorAddresses.toString() );
String connectorAddressesString = connectorAddresses.toString();

// then
assertEquals( expectedString, connectorAddressesString );

// when
ClientConnectorAddresses out = ClientConnectorAddresses.fromString( connectorAddressesString );

// then
assertEquals( connectorAddresses, out );
Expand Down

0 comments on commit 64aee78

Please sign in to comment.