Browse Source

fix broken threshold test on TCP tunnel

main
forest 5 months ago
parent
commit
89aa46ef1c
  1. 2
      child-process-service/child_process_service.go
  2. 10
      config_service.go
  3. 7
      main.go
  4. 4
      picopublish.sh

2
child-process-service/child_process_service.go

@ -351,7 +351,7 @@ func (service *ChildProcessService) hasExited() bool {
return true
}
}
return service.Command != nil && service.Command.ProcessState != nil && (!service.Command.ProcessState.Exited() || service.Command.ProcessState.ExitCode() == -1)
return service.Command != nil && service.Command.ProcessState != nil && (service.Command.ProcessState.Exited() || service.Command.ProcessState.ExitCode() == -1)
}
func (service *ChildProcessService) killOrphanedProcessByPid(pid int) {

10
config_service.go

@ -446,7 +446,7 @@ func (service *ConfigService) ConfigureThreshold(thresholdConfig *ThresholdTunne
return nil
}
func (service *ConfigService) TestThreshold(thresholdConfig *ThresholdTunnelsConfig) error {
func (service *ConfigService) TestThreshold(thresholdConfig *ThresholdTunnelsConfig, defaultDomain string) error {
url := fmt.Sprintf("%s/start_test", service.ThresholdAdminBaseURL)
response, err := service.ThresholdClient.Get(url)
@ -462,9 +462,6 @@ func (service *ConfigService) TestThreshold(thresholdConfig *ThresholdTunnelsCon
return errors.Errorf("calling /start_test on the threshold client returned HTTP %d %s: %s", response.StatusCode, response.Status, responseContent)
}
// TODO get thresholdServerAddress from the threshold admin api
thresholdServerAddress := ""
sentTokens := map[string]string{}
listenerConfigsByToken := map[string]ThresholdTunnel{}
@ -488,6 +485,9 @@ func (service *ConfigService) TestThreshold(thresholdConfig *ThresholdTunnelsCon
hostnames := strings.Split(listenerConfig.ListenHostnameGlob, ",")
for _, hostname := range hostnames {
specificHostname := strings.ReplaceAll(hostname, "*", "a")
if specificHostname == "" {
specificHostname = defaultDomain
}
if listenerConfig.ListenPort != 80 {
remoteAddress := fmt.Sprintf("%s:%d", specificHostname, listenerConfig.ListenPort)
@ -527,7 +527,7 @@ func (service *ConfigService) TestThreshold(thresholdConfig *ThresholdTunnelsCon
}
} else {
tcpAddressString := fmt.Sprintf("%s:%d", thresholdServerAddress, listenerConfig.ListenPort)
tcpAddressString := fmt.Sprintf("%s:%d", defaultDomain, listenerConfig.ListenPort)
tcpAddress, err := net.ResolveTCPAddr("tcp", tcpAddressString)
if err != nil {
return err

7
main.go

@ -842,6 +842,11 @@ func (daemon *DaemonAPI) ServeHTTP(responseWriter http.ResponseWriter, request *
return
}
// bytez1, _ := json.MarshalIndent(thresholdConfig, "", " ")
// log.Printf("thresholdConfig: %s\n\n", string(bytez1))
// bytez2, _ := json.MarshalIndent(caddyConfig, "", " ")
// log.Printf("caddyConfig: %s\n\n", string(bytez2))
daemon.ThresholdService.Enabled = true
daemon.CaddyService.Enabled = true
daemon.Config.TunnelsEnabled = true
@ -1007,7 +1012,7 @@ func (daemon *DaemonAPI) applyConfigAsync(tunnels []GUITunnel, thresholdConfig *
}
daemon.ApplyConfigStatusIndex++
err = daemon.ConfigService.TestThreshold(thresholdConfig)
err = daemon.ConfigService.TestThreshold(thresholdConfig, daemon.TenantInfo.AuthorizedDomains[0])
if err != nil {
daemon.ApplyConfigStatusError = fmt.Sprintf("testing threshold tunnels: %s", err)
log.Printf("testing threshold tunnels failed: %+v\n", err)

4
picopublish.sh

@ -24,7 +24,7 @@ function build() {
gzip --stdout "build/greenhouse-daemon" > "build/$gzip_file_name"
curl -X POST "https://picopublish.sequentialread.com/files/$gzip_file_name" \
-H 'Content-Type: application/x-gzip' -H "Authorization: Basic $(cat .picopublish-auth)" \
-H 'Content-Type: application/x-gzip' -H "Authorization: Basic $(cat ~/.picopublish-auth)" \
--data-binary "@build/$gzip_file_name"
echo "https://picopublish.sequentialread.com/files/$gzip_file_name"
@ -34,5 +34,5 @@ build linux amd64
build linux arm
build linux arm64
build windows amd64
#build darwin arm64
build darwin arm64
build darwin amd64
Loading…
Cancel
Save