Skip to content
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

[Dubbo-2064] Ipv6 support #2079

Merged
merged 9 commits into from
Aug 2, 2018
Merged

Conversation

ralf0131
Copy link
Contributor

What is the purpose of the change

Add ipv6 support for Dubbo #2064

Brief changelog

  • Support parsing ipv6 address in url
  • Support ipv6 multicast network
  • ipv6 support is available if java.net.preferIPv6Addresses is set to true

Verifying this change

How to test ipv6 support:

dubbo-demo-provider.xml

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

    <!-- provider's application name, used for tracing dependency relationship -->
    <dubbo:application name="demo-provider"/>

    <!-- use multicast registry center to export service -->
    <dubbo:registry address="multicast://FF02:0:0:0:0:0:0:FC:1234"/>

    <!-- use dubbo protocol to export service on port 20880 -->
    <dubbo:protocol name="dubbo" port="20880"/>

    <!-- service implementation, as same as regular local bean -->
    <bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl"/>

    <!-- declare the service interface to be exported -->
    <dubbo:service interface="org.apache.dubbo.demo.DemoService" ref="demoService"/>

</beans>

dubbo-demo-consumer.xml

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
       http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">

    <!-- consumer's application name, used for tracing dependency relationship (not a matching criterion),
    don't set it same as provider -->
    <dubbo:application name="demo-consumer"/>

    <!-- use multicast registry center to discover service -->
    <dubbo:registry address="multicast://FF02:0:0:0:0:0:0:FC:1234"/>

    <!-- generate proxy for the remote service, then demoService can be used in the same way as the
    local regular interface -->
    <dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.demo.DemoService"/>

</beans>

Add -Djava.net.preferIPv6Addresses=true before starting Provider/Consumer.

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a GITHUB_issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a GITHUB issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [Dubbo-XXX] Fix UnknownException when host config not exist #XXX. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn clean install -DskipTests & mvn clean test-compile failsafe:integration-test to make sure unit-test and integration-test pass.
  • If this contribution is large, please follow the Software Donation Guide.

@luyuanwan
Copy link
Contributor

Why not create a IPV6Utils class? @ralf0131 :)

@codecov-io
Copy link

codecov-io commented Jul 15, 2018

Codecov Report

Merging #2079 into master will increase coverage by 1.47%.
The diff coverage is 33.84%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2079      +/-   ##
============================================
+ Coverage     53.12%   54.59%   +1.47%     
- Complexity     4959     5127     +168     
============================================
  Files           559      559              
  Lines         24894    25195     +301     
  Branches       4432     4569     +137     
============================================
+ Hits          13225    13756     +531     
+ Misses         9650     9396     -254     
- Partials       2019     2043      +24
Impacted Files Coverage Δ Complexity Δ
.../dubbo/registry/integration/RegistryDirectory.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...n/java/org/apache/dubbo/common/utils/NetUtils.java 53.59% <0%> (-8.53%) 44 <0> (ø)
...mon/src/main/java/org/apache/dubbo/common/URL.java 26.75% <100%> (+0.1%) 81 <0> (+1) ⬆️
...he/dubbo/registry/multicast/MulticastRegistry.java 57.32% <72%> (-0.42%) 38 <4> (-3)
...ubbo/common/compiler/support/AdaptiveCompiler.java 77.77% <0%> (-11.12%) 3% <0%> (-1%)
...apache/dubbo/rpc/protocol/rest/BaseRestServer.java 88.88% <0%> (-11.12%) 7% <0%> (-1%)
...he/dubbo/remoting/transport/netty/NettyClient.java 72.88% <0%> (-10.17%) 12% <0%> (-1%)
...apache/dubbo/rpc/protocol/dubbo/FutureAdapter.java 58.06% <0%> (-6.46%) 3% <0%> (ø)
...ubbo/rpc/protocol/dubbo/ChannelWrappedInvoker.java 45.83% <0%> (-4.17%) 3% <0%> (ø)
...rpc/protocol/dubbo/telnet/InvokeTelnetHandler.java 51.89% <0%> (-3.8%) 11% <0%> (-2%)
... and 34 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd68437...fef30cc. Read the comment docs.

@ralf0131
Copy link
Contributor Author

@luyuanwan Good suggestion!

For me, I think the current refactoring is not large enough to make that change. You can always improve it as you wish, and send the pull request.

} catch (Throwable e) {
logger.warn(e);
}
while (interfaces.hasMoreElements()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    public static Enumeration<NetworkInterface> getNetworkInterfaces()
        throws SocketException {
        final NetworkInterface[] netifs = getAll();

        // specified to return null if no network interfaces
        if (netifs == null)
            return null;

Should check the interfaces property null value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I am using Java 10, the implementation is different with Java 8. In Java 10 the implementation guarantees no null value is returned. I will add the null check.

}
} catch (Throwable e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename e to ignored will be better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this is just coding style. I prefer to use

catch (Throwable e) {
   // ignore
}

instead of

catch(Throwable ignored) {

}

I found several codes in Dubbo's code that is written in the former way, but did not find my codes that is written in the way you suggested.

So I guess I am going to leave it unchanged.

}
} catch (Throwable e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename e to ignored will be better


@Test
public void testIsValidV6Address() {
System.setProperty("java.net.preferIPv6Addresses", "true");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String saved = System.setProperty("java.net.preferIPv6Addresses");
System.setProperty("java.net.preferIPv6Addresses", "true");
...
System.setProperty("java.net.preferIPv6Addresses", saved);

This way is more elegant and will not break subsequent tests.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String saved = System.getProperty("java.net.preferIPv6Addresses");
System.setProperty("java.net.preferIPv6Addresses", "true");
...
System.setProperty("java.net.preferIPv6Addresses", saved);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, it is better.

@ralf0131
Copy link
Contributor Author

ralf0131 commented Aug 2, 2018

@zonghaishang I've improved the code based on your review comments, could you take a look?

@zonghaishang zonghaishang merged commit 413a2a0 into apache:master Aug 2, 2018
@zonghaishang
Copy link
Member

It looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants