uber / tchannel-java

A Java implementation of the TChannel protocol.
MIT License
134 stars 65 forks source link

Borrow the getCurrentIp implementation from Go #138

Closed blampe closed 8 years ago

blampe commented 8 years ago

Resolves #137.

Java's iteration order for network interfaces looks reversed from Go. Here's Go's ListenIP with some logging added:

$ go run main.go
2016/07/23 17:15:02 Checking 127.0.0.1/8
2016/07/23 17:15:02 Checking 10.28.174.63/32
2016/07/23 17:15:02 Checking ::1/128
2016/07/23 17:15:02 Checking 10.28.40.63/24
2016/07/23 17:15:02 Checking fe80::2e60:cff:fea2:2f30/64
2016/07/23 17:15:02 Checking 10.28.104.63/24
2016/07/23 17:15:02 Checking fe80::2e60:cff:fea2:2f31/64
2016/07/23 17:15:02 Checking 172.17.0.1/16

And here's Java:

$ java IpTest
Checking 172.17.0.1
Checking fe80:0:0:0:2e60:cff:fea2:2f31%3
Checking 10.28.104.63
Checking fe80:0:0:0:2e60:cff:fea2:2f30%2
Checking 10.28.40.63
Checking 0:0:0:0:0:0:0:1%1
Checking 10.28.174.63
Checking 127.0.0.1

This PR mimics the Go implementation but prefers the last-seen match instead of the first-seen to account for this reverse ordering. The existing Java implementation had some other differences from Go (wasn't checking if the interface was up, for example) and so I feel more comfortable just copying Go since we know that works well.

I've confirmed locally that with this change Java will listen on the same IP as Go.

blampe commented 8 years ago

@junchaowu any pointers for how to release a new version of this?

blampe commented 8 years ago

cc @abhinav @prashantv @nikunjgit

jc-fireball commented 8 years ago

good to go. The release process will take a long process since the release people need to get authorization from the central maven. If you are in hurry, just land the diff. I will release for you.

abhinav commented 8 years ago

lgtm with nits

abhinav commented 8 years ago

:shipit: