Skip to content
Snippets Groups Projects
Commit d7f07fcc authored by cyberta's avatar cyberta
Browse files

remove code duplication when starting to listen on openvpn UDP connections

parent 8747c993
Branches
Tags
1 merge request!61Reconnect on error
Pipeline #235196 passed
......@@ -186,14 +186,9 @@ func (c *Client) Start() (bool, error) {
c.updateState(running)
proxyAddr, err := net.ResolveUDPAddr("udp", c.ProxyAddr)
if err != nil {
return false, fmt.Errorf("cannot resolve UDP addr: %w", err)
}
c.openvpnConn, err = net.ListenUDP("udp", proxyAddr)
c.openvpnConn, err = c.createOpenvpnConnection()
if err != nil {
return false, fmt.Errorf("error accepting udp connection: %w", err)
return false, err
}
if c.hopEnabled {
......@@ -466,7 +461,12 @@ func (c *Client) createOpenvpnConnection() (*net.UDPConn, error) {
return nil, err
}
return net.ListenUDP("udp", proxyAddr)
udpConn, err := net.ListenUDP("udp", proxyAddr)
if err != nil {
c.error("error accepting udp connection: %v", err)
return nil, fmt.Errorf("error accepting udp connection: %w", err)
}
return udpConn, nil
}
func (c *Client) Stop() (bool, error) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment