Skip to content

Commit

Permalink
Allow a second call to initQUICSockets. (scionproto#79)
Browse files Browse the repository at this point in the history
* Allow a second call to initQUICSockets.

Force the port to zero before the second call.

* use a parameter to ignore the port

* fix comment
  • Loading branch information
juagargi authored Jan 5, 2021
1 parent 707a5e6 commit 5a623a2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions go/lib/infra/infraenv/infraenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (nc *NetworkConfig) QUICStack() (*QUICStack, error) {
if nc.QUIC.Address == "" {
nc.QUIC.Address = net.JoinHostPort(nc.Public.IP.String(), "0")
}
client, server, err := nc.initQUICSockets()
client, server, err := nc.initQUICSockets(false)
if err != nil {
return nil, err
}
Expand All @@ -121,7 +121,9 @@ func (nc *NetworkConfig) QUICStack() (*QUICStack, error) {
}

//TLS/QUIC part
tlsClient, tlsServer, err := nc.initQUICSockets()
// Calling initQUICSockets again will fail if nc.QUIC.Address has a port other than 0.
// As a workaround, forcefully set the port to 0 via a parameter.
tlsClient, tlsServer, err := nc.initQUICSockets(true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -283,7 +285,7 @@ func (nc *NetworkConfig) initSvcRedirect(quicAddress string, tlsQUICAdress strin
return cancel, nil
}

func (nc *NetworkConfig) initQUICSockets() (net.PacketConn, net.PacketConn, error) {
func (nc *NetworkConfig) initQUICSockets(ignorePort bool) (net.PacketConn, net.PacketConn, error) {
dispatcherService := reliable.NewDispatcher("")
if nc.ReconnectToDispatcher {
dispatcherService = reconnect.NewDispatcherService(dispatcherService)
Expand All @@ -303,6 +305,9 @@ func (nc *NetworkConfig) initQUICSockets() (net.PacketConn, net.PacketConn, erro
if err != nil {
return nil, nil, serrors.WrapStr("parsing server QUIC address", err)
}
if ignorePort {
serverAddr.Port = 0
}
server, err := serverNet.Listen(context.Background(), "udp", serverAddr, addr.SvcNone)
if err != nil {
return nil, nil, serrors.WrapStr("creating server connection", err)
Expand Down

0 comments on commit 5a623a2

Please sign in to comment.