Better onConnected logic

- First port forward after 5 seconds
- Public IP obtained ASAP
- Logging in main only
- Allow port forward firewall with 1 second timeout local context
This commit is contained in:
Quentin McGaw
2020-04-30 12:54:48 +00:00
parent ac706bd156
commit 94255aaa38
3 changed files with 35 additions and 42 deletions

View File

@@ -13,7 +13,6 @@ import (
)
func (c *configurator) GetPortForward() (port uint16, err error) {
c.logger.Info("Obtaining port to be forwarded")
b, err := c.random.GenerateRandomBytes(32)
if err != nil {
return 0, err
@@ -35,12 +34,10 @@ func (c *configurator) GetPortForward() (port uint16, err error) {
if err := json.Unmarshal(content, &body); err != nil {
return 0, fmt.Errorf("port forwarding response: %w", err)
}
c.logger.Info("Port forwarded is %d", body.Port)
return body.Port, nil
}
func (c *configurator) WritePortForward(filepath models.Filepath, port uint16, uid, gid int) (err error) {
c.logger.Info("Writing forwarded port to %s", filepath)
return c.fileManager.WriteLinesToFile(
string(filepath),
[]string{fmt.Sprintf("%d", port)},
@@ -49,11 +46,5 @@ func (c *configurator) WritePortForward(filepath models.Filepath, port uint16, u
}
func (c *configurator) AllowPortForwardFirewall(ctx context.Context, device models.VPNDevice, port uint16) (err error) {
c.logger.Info("Allowing forwarded port %d through firewall", port)
return c.firewall.AllowInputTrafficOnPort(ctx, device, port)
}
func (c *configurator) ClearPortForward(filepath models.Filepath, uid, gid int) (err error) {
c.logger.Info("Clearing forwarded port status file %s", filepath)
return c.fileManager.Remove(string(filepath))
}