-
Notifications
You must be signed in to change notification settings - Fork 801
Adopt ip4s #4242
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
Adopt ip4s #4242
Conversation
Not being as cute as we were with folds in #4207. This will supersede it. |
1c2123f
to
c634171
Compare
7599dbd
to
2bcf4cb
Compare
} | ||
|
||
final case class Ipv4Address(a: Byte, b: Byte, c: Byte, d: Byte) | ||
final case class Ipv4Address(address: ip4s.Ipv4Address) |
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.
Forwarded
has wrappers just called Ipv4
. We could alternatively reclaim that name here and not need this prefix. We should be consistent with Forwarded
either way.
|
||
implicit val http4sTestingCogenForIpv4Address: Cogen[Uri.Ipv4Address] = | ||
Cogen[(Byte, Byte, Byte, Byte)].contramap(ipv4 => (ipv4.a, ipv4.b, ipv4.c, ipv4.d)) | ||
Cogen[Array[Byte]].contramap(_.address.toBytes) |
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.
@mpilquist Do you want Cogen
instances?
// TODO After release, replace with https://github.com/Comcast/ip4s/blob/4c799aa81d24f0d097daec8cd6f8fc029ed4ad3e/jvm/src/main/scala/com/comcast/ip4s/IpAddressPlatform.scala#L58 | ||
fromByteArray(address.getAddress).valueOr(throw _) | ||
|
||
def fromShorts(a: Short, b: Short, c: Short, d: Short, e: Short, f: Short, g: Short, h: Short) |
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.
I think this should be in ip4s, but maybe we're the only ones who ever modeled it as shorts?
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.
I'm surprised to not hit connection info problems in the Ember backend.
local = SocketAddress( | ||
IpAddress.fromBytes(local.getAddress.getAddress).get, | ||
Port(local.getPort).get), | ||
remote = SocketAddress( | ||
IpAddress.fromBytes(remote.getAddress.getAddress).get, | ||
Port(remote.getPort).get), |
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 is inartful. And maybe wasteful if unreferenced!
def remoteHost: Option[String] = remote.map(_.getHostName) | ||
def remoteHost(implicit F: Sync[F]): F[Option[Hostname]] = { | ||
val inetAddress = remote.map(_.ip.toInetAddress) | ||
F.delay(inetAddress.map(_.getHostName)).map(_.flatMap(Hostname(_))) |
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.
I think this should have been getHostAddress all along, and then it wouldn't need the F
? Why are we doing reverse lookups here?
local = SocketAddress(IpAddress(req.getLocalAddr).get, Port(req.getLocalPort).get), | ||
remote = SocketAddress(IpAddress(req.getRemoteAddr).get, Port(req.getRemotePort).get), |
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 is also inartful.
class ErrorActionSuite extends Http4sSuite { | ||
val remote = "192.168.0.1" | ||
val remote = IpAddress("192.168.0.1").get |
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.
We're running up against a problem here where our ipv4
and ipv6
interpolators conflict with ip4s', and ip4s' are imported at the root level, so they're almost always going to win. I think we should retire ours. Most of what @hamnis just did for ours could continue on: just remove the conflicting ones.
An ip4s 1.4.2 release, with its |
fs2-3.x is taking on an ip4s dependency, so it will be on our classpath anyway in 1.0. It has a richer model of addresses and is a lot harder to accidentally trigger network lookups, so it's good for us to use.
In the spirit of making 0.22 look as much like 1.0 as possible without cats-effect, we begin the adoption here.