feat: close connection if no tunneling request is specified
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 7m18s
All checks were successful
Docker Build and Push / build-and-push (push) Successful in 7m18s
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
package port
|
||||
package SSH_PORT
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -45,10 +45,10 @@ func (pm *PortManager) AddPortRange(startPort, endPort uint16) error {
|
||||
if startPort > endPort {
|
||||
return fmt.Errorf("start port cannot be greater than end port")
|
||||
}
|
||||
for port := startPort; port <= endPort; port++ {
|
||||
if _, exists := pm.ports[port]; !exists {
|
||||
pm.ports[port] = false
|
||||
pm.sortedPorts = append(pm.sortedPorts, port)
|
||||
for SSH_PORT := startPort; SSH_PORT <= endPort; SSH_PORT++ {
|
||||
if _, exists := pm.ports[SSH_PORT]; !exists {
|
||||
pm.ports[SSH_PORT] = false
|
||||
pm.sortedPorts = append(pm.sortedPorts, SSH_PORT)
|
||||
}
|
||||
}
|
||||
sort.Slice(pm.sortedPorts, func(i, j int) bool {
|
||||
@ -61,30 +61,30 @@ func (pm *PortManager) GetUnassignedPort() (uint16, bool) {
|
||||
pm.mu.Lock()
|
||||
defer pm.mu.Unlock()
|
||||
|
||||
for _, port := range pm.sortedPorts {
|
||||
if !pm.ports[port] {
|
||||
pm.ports[port] = true
|
||||
return port, true
|
||||
for _, SSH_PORT := range pm.sortedPorts {
|
||||
if !pm.ports[SSH_PORT] {
|
||||
pm.ports[SSH_PORT] = true
|
||||
return SSH_PORT, true
|
||||
}
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func (pm *PortManager) SetPortStatus(port uint16, assigned bool) error {
|
||||
func (pm *PortManager) SetPortStatus(SSH_PORT uint16, assigned bool) error {
|
||||
pm.mu.Lock()
|
||||
defer pm.mu.Unlock()
|
||||
|
||||
if _, exists := pm.ports[port]; !exists {
|
||||
return fmt.Errorf("port %d is not in the allowed range", port)
|
||||
if _, exists := pm.ports[SSH_PORT]; !exists {
|
||||
return fmt.Errorf("port %d is not in the allowed range", SSH_PORT)
|
||||
}
|
||||
pm.ports[port] = assigned
|
||||
pm.ports[SSH_PORT] = assigned
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pm *PortManager) GetPortStatus(port uint16) (bool, bool) {
|
||||
func (pm *PortManager) GetPortStatus(SSH_PORT uint16) (bool, bool) {
|
||||
pm.mu.RLock()
|
||||
defer pm.mu.RUnlock()
|
||||
|
||||
status, exists := pm.ports[port]
|
||||
status, exists := pm.ports[SSH_PORT]
|
||||
return status, exists
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user