schollz / peerdiscovery

Pure-Go library for cross-platform local peer discovery using UDP multicast :woman: :repeat: :woman:
MIT License
638 stars 55 forks source link

IPv6 support #6

Closed oxzi closed 5 years ago

oxzi commented 5 years ago

This pull request adds IPv6 multicast scans by introducing the IPVersion field to the Settings struct, defaulting to IPv4 to not break the compatibility. However, settings IPVersion: IPv6 will execute the same peer discovery service, just for IPv6 instead.

The code is a bit ugly at some points, because both ipv4.PacketConn and ipv6.PacketConn does not implement net.PacketConn. Therefore I treated them as an empty interface.

Please tell me what you think and thanks a lot for this library!


Random note regarding testing: I wrote a small Dockerfile which launches - after enabling IPv6 - some containers for testing.

$ cat Dockerfile
FROM golang:1.11

WORKDIR /peerdiscovery
COPY . .
RUN go build ./examples/main.go

CMD ["/peerdiscovery/main"]

$ docker build -t peertest .
. . .

# run the following command in multiple terminals
$ docker run -t --rm peertest
oxzi commented 5 years ago

Seems like Travis CI does not like IPv6:

IPv6 network: IPv6 is not available

schollz commented 5 years ago

@geistesk This is awesome! Thanks so much for this PR, its really incredible.

If you don't mind, could you also add the Dockerfile and update the README with your testing? I think your test is really clever and want to make sure everyone knows about it. If you are busy, I can also merge this now and add it myself later :)

oxzi commented 5 years ago

@schollz Thanks for your fast and nice response :)

I've just updated the PR. Does this look good for you?

Edit: Amended last commit to comment on enabling IPv6 for Docker.

schollz commented 5 years ago

This is great, thanks so much!